feat: initial commit
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using Hangfire;
|
||||
using Hangfire.Common;
|
||||
using Hangfire.Server;
|
||||
using Hangfire.Storage;
|
||||
using Moq;
|
||||
|
||||
// https://github.com/HangfireIO/Hangfire/blob/master/tests/Hangfire.Core.Tests/Mocks/PerformContextMock.cs
|
||||
|
||||
namespace Strata.Analytics.Test.Unit.Biz.TestData
|
||||
{
|
||||
public class PerformContextMock
|
||||
{
|
||||
private readonly Lazy<PerformContext> _context;
|
||||
|
||||
public PerformContextMock()
|
||||
{
|
||||
Storage = new Mock<JobStorage>();
|
||||
Connection = new Mock<IStorageConnection>();
|
||||
BackgroundJob = new BackgroundJobMock();
|
||||
CancellationToken = new Mock<IJobCancellationToken>();
|
||||
|
||||
_context = new Lazy<PerformContext>(
|
||||
() => new PerformContext(Storage.Object, Connection.Object, BackgroundJob.Object, CancellationToken.Object));
|
||||
}
|
||||
|
||||
public Mock<JobStorage> Storage { get; set; }
|
||||
public Mock<IStorageConnection> Connection { get; set; }
|
||||
public BackgroundJobMock BackgroundJob { get; set; }
|
||||
public Mock<IJobCancellationToken> CancellationToken { get; set; }
|
||||
|
||||
public PerformContext Object => _context.Value;
|
||||
|
||||
public PerformingContext GetPerformingContext()
|
||||
{
|
||||
return new PerformingContext(Object);
|
||||
}
|
||||
|
||||
public PerformedContext GetPerformedContext(object result = null, bool canceled = false, Exception exception = null)
|
||||
{
|
||||
return new PerformedContext(Object, result, canceled, exception);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class BackgroundJobMock
|
||||
{
|
||||
private readonly Lazy<BackgroundJob> _object;
|
||||
|
||||
public BackgroundJobMock()
|
||||
{
|
||||
Id = "JobId";
|
||||
Job = Job.FromExpression(() => SomeMethod());
|
||||
CreatedAt = DateTime.UtcNow;
|
||||
|
||||
_object = new Lazy<BackgroundJob>(
|
||||
() => new BackgroundJob(Id, Job, CreatedAt));
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public Job Job { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
public BackgroundJob Object => _object.Value;
|
||||
|
||||
public static void SomeMethod() { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user