Example #1
0
        public async void AddDriverHandler_Returns_False_When_CommandValidAndDriverIsAlreadyInStore()
        {
            //Arrange
            var mediatorMock = new Mock <IMediator>();

            var    driverRepoMock = new Mock <IDriverRepository>();
            Driver driver         = new Driver()
            {
                Name = "Kumi"
            };

            driverRepoMock.Setup(mock => mock.AddDriver(It.IsAny <Driver>())).Verifiable();
            driverRepoMock.Setup(mock => mock.GetDriverByName(It.IsAny <string>())).Returns(driver);

            var command = new AddDriverCommand()
            {
                Name = "Kumi"
            };
            var handler = new AddDriverCommandHandler(driverRepoMock.Object, mediatorMock.Object);

            //Act
            var result = await handler.Handle(command, new CancellationToken());

            //Assert that hanlder returns False and DriverAddedEvent is not published.
            Assert.False(result);
            mediatorMock.Verify(mock => mock.Publish(It.IsAny <DriverAddedEvent>(), new CancellationToken()), Times.Never());
        }
Example #2
0
        public async void AddDriverHandler_Returns_False_When_CommandInvalid()
        {
            //Arrange
            var mediatorMock   = new Mock <IMediator>();
            var driverRepoMock = new Mock <IDriverRepository>();
            var command        = new AddDriverCommand()
            {
                Name = ""
            };
            var handler = new AddDriverCommandHandler(driverRepoMock.Object, mediatorMock.Object);

            //Act
            var result = await handler.Handle(command, new CancellationToken());

            //Assert
            Assert.False(result);
        }