コード例 #1
0
        public void SyncExecutionFinishRightAway()
        {
            var fixture = new CommandFixture()
            {
                SyncAction = true
            };
            var command = fixture.Command;

            command.Execute();
            Assert.False(command.IsRunning);
            Assert.Equal(1, fixture.Executed);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
 public CommandTest(CommandFixture <FakeCommand> messageFixture)
 {
     MessageFixture = messageFixture;
 }