Esempio n. 1
0
        public void AddVehicleRange_ShouldReturnCount2_WhenVehicleListContainsTwoVehicles()
        {
            //Given
            var options = new DbContextOptionsBuilder <CarDealerContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var databaseContext         = new CarDealerContext(options);
            var vehicleInventoryService = new VehicleService(databaseContext);

            //When
            databaseContext.VehicleInventory.ToList().Count.Should().Be(0);

            var vehicle = new Vehicle[]
            {
                new Vehicle()
                {
                    Id = 1, Make = "Tesla1", Model = "XXX1", Year = 2021, VinNumber = "abcxyz1231", MarketValue = 23001
                },
                new Vehicle()
                {
                    Id = 2, Make = "Tesla2", Model = "XXX2", Year = 2022, VinNumber = "abcxyz1232", MarketValue = 23002
                }
            };

            vehicleInventoryService.AddRangeOfVehicles(vehicle);
            //Then
            databaseContext.VehicleInventory.ToList().Count.Should().Be(2);
        }
Esempio n. 2
0
        public void AddVehicleRange_ShouldReturnThrowArgumentNullException_WhenVehicleListIsNull()
        {
            //Given
            var options = new DbContextOptionsBuilder <CarDealerContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var databaseContext         = new CarDealerContext(options);
            var vehicleInventoryService = new VehicleService(databaseContext);
            //When

            Action action = () => vehicleInventoryService.AddRangeOfVehicles(null);

            //Then
            action.Should().Throw <ArgumentNullException>()
            .WithMessage("The vehicle you are trying to add is null (Parameter 'vehicles')");
        }
Esempio n. 3
0
        public void AddVehicleRange_ShouldReturnCountZero_WhenVehicleListContainsZeroVehicles()
        {
            //Action action = () => vehicleInventoryService.AddVehicle(null);
            //Given
            var options = new DbContextOptionsBuilder <CarDealerContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var databaseContext         = new CarDealerContext(options);
            var vehicleInventoryService = new VehicleService(databaseContext);

            //When
            databaseContext.VehicleInventory.ToList().Count.Should().Be(0);

            var vehicle = new Vehicle[] { };

            vehicleInventoryService.AddRangeOfVehicles(vehicle);
            //Then
            databaseContext.VehicleInventory.ToList().Count.Should().Be(0);
        }