public void SyncExecutionFinishRightAway() { var fixture = new CommandFixture() { SyncAction = true }; var command = fixture.Command; command.Execute(); Assert.False(command.IsRunning); Assert.Equal(1, fixture.Executed); }
public async Task ShouldThrowException(string instruction) { var extractorMock = CreateCommandExtractorMock(instruction); var command = new CommandFixture(new Dictionary <string, string> { { Consts.SEPARATOR, "|" } }) .Create(svc => { svc.AddSingleton <ICommandExtractor>(extractorMock); }); await Assert.ThrowsAnyAsync <Exception>(command.Calculate); }
public async Task ShouldReturnExpectedResults(string instruction, decimal expected) { var extractorMock = CreateCommandExtractorMock(instruction); var command = new CommandFixture(new Dictionary <string, string> { { Consts.SEPARATOR, "|" } }) .Create(svc => { svc.AddSingleton <ICommandExtractor>(extractorMock); }); Assert.Equal(expected, await command.Calculate()); }
public void CancelCommand() { var fixture = new CommandFixture(); var command = fixture.Command; Assert.False(command.CancelCommand.CanExecute()); command.Execute(); Assert.True(command.CancelCommand.CanExecute()); command.CancelCommand.Execute(); Assert.True(command.IsCancellationRequested); Assert.False(command.IsRunning); Assert.Equal(0, fixture.Executed); }
public void CancelWhile_Cancel() { var fixture = new CommandFixture() { Policy = AsyncCommandSerializationPolicy.Cancel | AsyncCommandSerializationPolicy.Wait }; var command = fixture.Command; command.Execute(); command.Execute(); command.CancelCommand.Execute(); Assert.Throws <TaskCanceledException>(() => command.Task.GetAwaiter().GetResult()); Assert.False(command.IsRunning); Assert.Equal(0, fixture.Executed); }
public async Task SerializationPolicy_Wait() { var fixture = new CommandFixture() { Policy = AsyncCommandSerializationPolicy.Wait }; var command = fixture.Command; command.Execute(); command.Execute(); await command.Task; Assert.False(command.IsRunning); Assert.Equal(2, fixture.Executed); }
public void CancelCommand_ActionDoesNotUseCancelToken() { var fixture = new CommandFixture() { UseCancellationToken = false }; var command = fixture.Command; command.Execute(); command.CancelCommand.Execute(); Assert.True(command.IsCancellationRequested); Assert.False(command.IsRunning); Assert.Throws <TaskCanceledException>(() => command.Task.GetAwaiter().GetResult()); Assert.Equal(0, fixture.Executed); }
public void SerializationPolicy_WaitCancel() { var fixture = new CommandFixture() { Policy = AsyncCommandSerializationPolicy.Wait | AsyncCommandSerializationPolicy.Cancel }; var command = fixture.Command; command.Execute(); var execution1 = command.Task; command.Execute(); Assert.Throws <TaskCanceledException>(() => execution1.GetAwaiter().GetResult()); command.Task.Wait(); Assert.Equal(1, fixture.Executed); }
public void MultipleExecutions_DifferentTasks() { var fixture = new CommandFixture(); var command = fixture.Command; command.Execute(); var t1 = command.Task; command.Execute(); var t2 = command.Task; command.Execute(); var t3 = command.Task; Assert.NotSame(t1, t2); Assert.NotSame(t2, t3); }
public async Task AsyncCommandExecutes() { var fixture = new CommandFixture(); var command = fixture.Command; Assert.False(command.IsRunning); command.Execute(); Assert.True(command.IsRunning); Assert.NotNull(command.Task); Assert.Equal(0, fixture.Executed); await command.Task; Assert.Equal(1, fixture.Executed); Assert.False(command.IsRunning); }
public CommandTest(CommandFixture <FakeCommand> messageFixture) { MessageFixture = messageFixture; }