Exemplo n.º 1
0
        public async Task TestAddCarAsync_WithTestData_ShouldAddCarToDb()
        {
            // Arrange
            var contextFactory = new ApplicationDbContextFactory();
            var context        = contextFactory.CreateApplicationDbContext();

            var mapperFactory = new AutoMapperFactory();
            var mapper        = mapperFactory.CreateMapper();

            var carServices = new CarServices(context, mapper);

            var car = new Car()
            {
                Brand    = "BMW",
                Model    = "X6",
                Number   = "PB1234K",
                YearFrom = DateTime.Now
            };
            var carServiceModel = mapper.Map <CarServiceModel>(car);

            // Act
            await carServices.AddCarAsync(carServiceModel);

            var expectedCount = 1;
            var actualCount   = context.Cars.Count();

            // Assert
            Assert.Equal(expected: expectedCount, actual: actualCount);
        }
Exemplo n.º 2
0
        public async Task TestAddCarAsync_WithCarServiceModelNull_ShouldNotAddCarToDb()
        {
            // Arrange
            var contextFactory = new ApplicationDbContextFactory();
            var context        = contextFactory.CreateApplicationDbContext();

            var mapperFactory = new AutoMapperFactory();
            var mapper        = mapperFactory.CreateMapper();

            var carServices = new CarServices(context, mapper);


            // Act
            await carServices.AddCarAsync(null);

            var expectedCount = 0;
            var actualCount   = context.Cars.Count();

            // Assert
            Assert.Equal(expected: expectedCount, actual: actualCount);
        }