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 _context; public PerformContextMock() { Storage = new Mock(); Connection = new Mock(); BackgroundJob = new BackgroundJobMock(); CancellationToken = new Mock(); _context = new Lazy( () => new PerformContext(Storage.Object, Connection.Object, BackgroundJob.Object, CancellationToken.Object)); } public Mock Storage { get; set; } public Mock Connection { get; set; } public BackgroundJobMock BackgroundJob { get; set; } public Mock 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 _object; public BackgroundJobMock() { Id = "JobId"; Job = Job.FromExpression(() => SomeMethod()); CreatedAt = DateTime.UtcNow; _object = new Lazy( () => 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() { } } }