Exemple #1
0
        public async Task Get_Returns_All_CardAdverts()
        {
            // Arrange
            var controller = new CarAdvertsController(GetUnitTestsDbContext("1"));

            // Act
            var result = await controller.GetCarAdverts();

            // Assert
            var adverts = Assert.IsType <List <CarAdvert> >(result.Value);

            Assert.Equal(4, adverts.Count);
        }
Exemple #2
0
        public async Task Get_With_Sorting_By_Mileage_Returns_All_CardAdverts_In_Correct_Order()
        {
            // Arrange
            var controller = new CarAdvertsController(GetUnitTestsDbContext("3"));

            // Act
            var result = await controller.GetCarAdverts("mileage");

            // Assert
            var adverts = Assert.IsType <List <CarAdvert> >(result.Value);

            Assert.Equal(adverts[2].Mileage, 10000);
            Assert.Equal(adverts[3].Mileage, 20000);
        }
Exemple #3
0
        public async Task Delete_CardAdvert_Reduces_Record_Size()
        {
            // Arrange
            var controller = new CarAdvertsController(GetUnitTestsDbContext("4"));

            // Act
            var deleteResult = await controller.DeleteCarAdvert(1);

            var result = await controller.GetCarAdverts();

            // Assert
            var adverts = Assert.IsType <List <CarAdvert> >(result.Value);

            Assert.Equal(3, adverts.Count);
        }
        private CarAdvertsController GetSUT(string databaseName)
        {
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: databaseName)
                          .Options;
            var context = new ApplicationContext(options);
            var service = new CarAdvertService(context);
            var items   = GetTestCarAdverts().ToList();

            items.ForEach(carAdvert => service.Add(carAdvert));

            context.SaveChanges();

            var configuration = new MapperConfiguration(cfg => cfg.AddProfile(new CarAdvertMappingProfile()));
            var mapper        = new Mapper(configuration);

            var controller = new CarAdvertsController(service, mapper);

            return(controller);
        }
Exemple #5
0
        public async Task Update_CardAdvert_Changes_Entity()
        {
            // Arrange
            var controller = new CarAdvertsController(GetUnitTestsDbContext("5"));

            // Act
            var getResult = await controller.GetCarAdvert(1);

            // Assert
            var advert = Assert.IsType <CarAdvert>(getResult.Value);

            Assert.Equal("First test car", advert.Title);

            // Act and update
            advert.Title = "Updated test car";
            await controller.PutCarAdvert(1, advert);

            // Act
            getResult = await controller.GetCarAdvert(1);

            // Assert
            advert = Assert.IsType <CarAdvert>(getResult.Value);
            Assert.Equal("Updated test car", advert.Title);
        }