public async Task ProcessCommand_CallProcessCommand(
            [Frozen] Mock <ICommandEvents> commandEvents,
            [Frozen] Mock <IAsyncCommandBus> commandBus,
            NotifyEventsAsyncCommandBus sut,
            IAsyncCommand command)
        {
            //arrange
            commandBus.Setup(c => c.ProcessCommand(command)).Returns(Task.FromResult(true));

            //act
            await sut.ProcessCommand(command);

            //assert
            commandBus.Verify(c => c.ProcessCommand(command), Times.Once());
        }
		public async Task ProcessCommand_ShouldCallNotifyComplete(
			[Frozen]Mock<ICommandEvents> commandEvents,
			[Frozen]Mock<IAsyncCommandBus> commandBus,
			NotifyEventsAsyncCommandBus sut,
			Mock<IAsyncCommand> command)
		{
			//arrange
			command.As<IAsyncCommandEvent<string>>();
			commandBus.Setup(c => c.ProcessCommand(command.Object)).Returns(Task.FromResult(true));

			//act
			await sut.ProcessCommand(command.Object);

			//assert
			commandEvents.Verify(c => c.NotifyComplete(command.As<IAsyncCommandEvent<string>>().Object));
		}
        public async Task ProcessCommand_ShouldCallNotifyComplete(
            [Frozen] Mock <ICommandEvents> commandEvents,
            [Frozen] Mock <IAsyncCommandBus> commandBus,
            NotifyEventsAsyncCommandBus sut,
            Mock <IAsyncCommand> command)
        {
            //arrange
            command.As <IAsyncCommandEvent <string> >();
            commandBus.Setup(c => c.ProcessCommand(command.Object)).Returns(Task.FromResult(true));

            //act
            await sut.ProcessCommand(command.Object);

            //assert
            commandEvents.Verify(c => c.NotifyComplete(command.As <IAsyncCommandEvent <string> >().Object));
        }
		public void ProcessCommand_WhenErrorOccurrs_ShouldThrow(
			[Frozen]Mock<ICommandEvents> commandEvents,
			[Frozen]Mock<IAsyncCommandBus> commandBus,
			NotifyEventsAsyncCommandBus sut,
			Mock<IAsyncCommand> command,
			Exception ex)
		{
			//arrange
			command.As<IAsyncCommandEvent<string>>();
			commandBus.Setup(c => c.ProcessCommand(command.Object)).Returns(() => Task.Run(() => { throw ex; }));

			//act
			Func<Task> task = () =>  sut.ProcessCommand(command.Object);

			//assert
			task.ShouldThrow<Exception>()
			    .And.Should().Be(ex, "Exception was not the exception originally thrown");
		}
        public void ProcessCommand_WhenErrorOccurrs_ShouldThrow(
            [Frozen] Mock <ICommandEvents> commandEvents,
            [Frozen] Mock <IAsyncCommandBus> commandBus,
            NotifyEventsAsyncCommandBus sut,
            Mock <IAsyncCommand> command,
            Exception ex)
        {
            //arrange
            command.As <IAsyncCommandEvent <string> >();
            commandBus.Setup(c => c.ProcessCommand(command.Object)).Returns(() => Task.Run(() => { throw ex; }));

            //act
            Func <Task> task = () => sut.ProcessCommand(command.Object);

            //assert
            task.ShouldThrow <Exception>()
            .And.Should().Be(ex, "Exception was not the exception originally thrown");
        }
		public async Task ProcessCommand_WhenErrorOccurrs_ShouldCallNotifyError(
			[Frozen]Mock<ICommandEvents> commandEvents,
			[Frozen]Mock<IAsyncCommandBus> commandBus,
			NotifyEventsAsyncCommandBus sut,
			Mock<IAsyncCommand> command,
			Exception ex)
		{
			//arrange
			command.As<IAsyncCommandEvent<string>>();
			commandBus.Setup(c => c.ProcessCommand(command.Object)).Returns(() => Task.Run(() => { throw ex; }));

			//act
			try
			{
				await sut.ProcessCommand(command.Object);
			}
			catch (Exception)
			{
				//we don't want to know about exception in this test
			}

			//assert
			commandEvents.Verify(c => c.NotifyError(command.As<IAsyncCommandEvent<string>>().Object, ex));
		}
        public async Task ProcessCommand_WhenErrorOccurrs_ShouldCallNotifyError(
            [Frozen] Mock <ICommandEvents> commandEvents,
            [Frozen] Mock <IAsyncCommandBus> commandBus,
            NotifyEventsAsyncCommandBus sut,
            Mock <IAsyncCommand> command,
            Exception ex)
        {
            //arrange
            command.As <IAsyncCommandEvent <string> >();
            commandBus.Setup(c => c.ProcessCommand(command.Object)).Returns(() => Task.Run(() => { throw ex; }));

            //act
            try
            {
                await sut.ProcessCommand(command.Object);
            }
            catch (Exception)
            {
                //we don't want to know about exception in this test
            }

            //assert
            commandEvents.Verify(c => c.NotifyError(command.As <IAsyncCommandEvent <string> >().Object, ex));
        }
		public async Task ProcessCommand_CallProcessCommand(
			[Frozen]Mock<ICommandEvents> commandEvents,
			[Frozen]Mock<IAsyncCommandBus> commandBus,
			NotifyEventsAsyncCommandBus sut,
			IAsyncCommand command)
		{
			//arrange
			commandBus.Setup(c => c.ProcessCommand(command)).Returns(Task.FromResult(true));

			//act
			await sut.ProcessCommand(command);

			//assert
			commandBus.Verify(c => c.ProcessCommand(command), Times.Once());
		}
		public void Sut_IsAsyncCommandBus(NotifyEventsAsyncCommandBus sut)
		{
			sut.Should().BeAssignableTo<IAsyncCommandBus>();
		}
Exemplo n.º 10
0
 public void Sut_IsAsyncCommandBus(NotifyEventsAsyncCommandBus sut)
 {
     sut.Should().BeAssignableTo <IAsyncCommandBus>();
 }