public async Task GetMobilePhonesForListTest_EmptyDB() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <MobilePhone, MobilePhoneForListVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = await mobilePhoneService.GetMobilePhonesForList(); //Assert result.Should().HaveCount(0); result.Should().BeOfType <List <MobilePhoneForListVM> >(); } }
public async Task GetMobilePhonesForListTest_ShouldGetThreeObjects() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { //Arrange dbContext.Add(new MobilePhone() { Id = 1, Brand = "Apple", Name = "iPhone 12", Price = 3000, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone 12/Main.png", FirstImage = "/Apple/iPhone 12/First.png", SecondImage = "/Apple/iPhone 12/Second.png", BestSeller = true }); dbContext.Add(new MobilePhone() { Id = 4, Brand = "LG", Name = "Wing 5G", Price = 4500, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/LG/Wing/Main.png", FirstImage = "/LG/Wing/First.png", SecondImage = "/LG/Wing/Second.png", BestSeller = true }); dbContext.Add(new MobilePhone() { Id = 24, Brand = "Apple", Name = "iPhone SE", Price = 2100, ShortDescription = "short", Description = "Description", ActiveStatus = true, QuantityInStack = QuantityStatus.Full, MainImage = "/Apple/iPhone SE/Main.png", FirstImage = "/Apple/iPhone SE/First.png", SecondImage = "/Apple/iPhone SE/Second.png", BestSeller = true }); dbContext.SaveChanges(); var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <MobilePhone, MobilePhoneForListVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = await mobilePhoneService.GetMobilePhonesForList(); //Assert result.Should().HaveCount(3); result.Should().BeOfType <List <MobilePhoneForListVM> >(); } }