Beispiel #1
0
        public async Task when_invoke_create_driver_and_driver_not_exist_command_handler_should_not_be_null()
        {
            var driverRepositoryMock = new Mock <IDriverRepository>();
            var nodeManagerMock      = new Mock <INodeManager>();

            driverRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>())).ReturnsAsync(() => null);

            var command = new CreateDriverCommand("123123")
            {
                UserId = Guid.NewGuid()
            };

            var commandHandler = new CreateDriverCommandHandler(nodeManagerMock.Object, driverRepositoryMock.Object);
            var result         = await commandHandler.Handle(command, CancellationToken.None);

            result.Should().NotBeNull();
        }
Beispiel #2
0
        public async Task when_invoke_create_driver_command_handler_and_driver_exist_should_throw_exception()
        {
            var driverRepositoryMock = new Mock <IDriverRepository>();
            var nodeManagerMock      = new Mock <INodeManager>();

            var driver = new Driver(Guid.NewGuid(), "123123123123");

            driverRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>())).ReturnsAsync(() => driver);

            var command = new CreateDriverCommand("123123")
            {
                UserId = Guid.NewGuid()
            };

            var commandHandler =
                new CreateDriverCommandHandler(nodeManagerMock.Object, driverRepositoryMock.Object);

            Func <Task> act = async() => await commandHandler.Handle(command, CancellationToken.None);

            act.Should().Throw <Exception>();
        }
        public async Task Handle_WithData_FetchesCoorinatesAndCreatesDriver()
        {
            // Arrange
            var handler = new CreateDriverCommandHandler(_driverContext, _mapper, _geocoder);
            var command = new CreateDriverCommand(new ModifyDriverDto
            {
                FirstName            = "Fulano",
                LastName             = "da Silva",
                CarBrand             = "Ford",
                CarModel             = "Focus",
                CarRegistrationPlate = "LUJ1234",
                AddressLine1         = "Av Brasil, 9020",
                AddressLine2         = "Olaria",
                AddressMunicipality  = "Rio de Janeiro",
                AddressState         = "RJ",
                AddressZipCode       = "21030-001"
            });

            // Act
            await handler.Handle(command, CancellationToken.None);

            // Assert
            var driver = await _driverContext.Drivers.FirstAsync();

            Assert.Equal("Fulano", driver.FirstName);
            Assert.Equal("da Silva", driver.LastName);
            Assert.Equal("Ford", driver.Car.Brand);
            Assert.Equal("Focus", driver.Car.Model);
            Assert.Equal("LUJ1234", driver.Car.RegistrationPlate);
            Assert.Equal("Av Brasil, 9020", driver.Address.Line1);
            Assert.Equal("Olaria", driver.Address.Line2);
            Assert.Equal("Rio de Janeiro", driver.Address.Municipality);
            Assert.Equal("RJ", driver.Address.State);
            Assert.Equal("21030-001", driver.Address.ZipCode);
            Assert.Equal(10, driver.Address.Coordinates.Latitude);
            Assert.Equal(-10, driver.Address.Coordinates.Longitude);
        }