public void Initialize_Nothing_ShouldMatchSnapshot() { // act var scheduler = new BatchScheduler(); // assert scheduler.MatchSnapshot(); }
public void Schedule_OneAction_HasTasksShouldReturnTrue() { // arrange var scheduler = new BatchScheduler(); Func <ValueTask> dispatch = () => default; // act scheduler.Schedule(dispatch); // assert Assert.True(scheduler.HasTasks); }
private static async Task <(string, JobPreparationTask, CloudTask, PoolInformation)> ProcessTesTaskAndGetBatchJobArgumentsAsync(TesTask tesTask, IConfiguration configuration, Mock <IAzureProxy> azureProxy) { var batchScheduler = new BatchScheduler(new Mock <ILogger>().Object, configuration, azureProxy.Object); await batchScheduler.ProcessTesTaskAsync(tesTask); var createBatchJobAsyncInvocation = azureProxy.Invocations.FirstOrDefault(i => i.Method.Name == nameof(IAzureProxy.CreateBatchJobAsync)); var jobId = createBatchJobAsyncInvocation?.Arguments[0] as string; var jobPreparationTask = createBatchJobAsyncInvocation?.Arguments[1] as JobPreparationTask; var cloudTask = createBatchJobAsyncInvocation?.Arguments[2] as CloudTask; var poolInformation = createBatchJobAsyncInvocation?.Arguments[3] as PoolInformation; return(jobId, jobPreparationTask, cloudTask, poolInformation); }
public void Schedule_OneAction_HasTasksShouldReturnTrue() { // arrange var hasTask = false; var scheduler = new BatchScheduler(); scheduler.TaskEnqueued += (_, _) => hasTask = true; ValueTask Dispatch() => default; // act scheduler.Schedule(Dispatch); // assert Assert.True(hasTask); }
private static async Task <(string JobId, CloudTask CloudTask, PoolInformation PoolInformation)> ProcessTesTaskAndGetBatchJobArgumentsAsync(TesTask tesTask, IConfiguration configuration, Mock <IAzureProxy> azureProxy) { var batchScheduler = new BatchScheduler(new Mock <ILogger>().Object, configuration, new CachingWithRetriesAzureProxy(azureProxy.Object, new CachingService(new MemoryCacheProvider(new MemoryCache(new MemoryCacheOptions()))))); await batchScheduler.ProcessTesTaskAsync(tesTask); var createBatchJobAsyncInvocation = azureProxy.Invocations.FirstOrDefault(i => i.Method.Name == nameof(IAzureProxy.CreateBatchJobAsync)); var jobId = createBatchJobAsyncInvocation?.Arguments[0] as string; var cloudTask = createBatchJobAsyncInvocation?.Arguments[1] as CloudTask; var poolInformation = createBatchJobAsyncInvocation?.Arguments[2] as PoolInformation; return(jobId, cloudTask, poolInformation); }
public void Dispatch_OneAction_ShouldDispatchOneAction() { // arrange var scheduler = new BatchScheduler(); Func <ValueTask> dispatch = () => default; scheduler.Schedule(dispatch); Assert.True(scheduler.HasTasks); // act scheduler.Dispatch(d => { }); // assert Assert.False(scheduler.HasTasks); }
public void Schedule_OneAction_ShouldRaiseTaskEnqueued() { // arrange var hasBeenRaised = false; var scheduler = new BatchScheduler(); ValueTask Dispatch() => default; scheduler.TaskEnqueued += (_, _) => hasBeenRaised = true; // act scheduler.Schedule(Dispatch); // assert Assert.True(hasBeenRaised); }
public void Schedule_OneAction_ShouldRaiseTaskEnqueued() { // arrange var hasBeenRaised = false; var scheduler = new BatchScheduler(); Func <ValueTask> dispatch = () => default; scheduler.TaskEnqueued += (s, e) => { hasBeenRaised = true; }; // act scheduler.Schedule(dispatch); // assert Assert.True(hasBeenRaised); }
public async Task Dispatch_OneAction_ShouldDispatchOneAction() { // arrange var context = new Mock <IExecutionTaskContext>(); context.Setup(t => t.Register(It.IsAny <IExecutionTask>())); var scheduler = new BatchScheduler(); ValueTask Dispatch() => default; scheduler.Schedule(Dispatch); Assert.True(scheduler.HasTasks); // act await scheduler.DispatchAsync(); // assert Assert.False(scheduler.HasTasks); }
public void Dispatch_OneAction_ShouldDispatchOneAction() { // arrange var context = new Mock <IExecutionTaskContext>(); context.Setup(t => t.Register(It.IsAny <IExecutionTask>())); var hasTask = false; var scheduler = new BatchScheduler(); scheduler.TaskEnqueued += (_, _) => hasTask = true; ValueTask Dispatch() => default; scheduler.Schedule(Dispatch); Assert.True(hasTask); hasTask = false; // act scheduler.BeginDispatch(); // assert Assert.False(hasTask); }