public async Task GetMobilePhonesForHomeTest_DBEmpty() { var service = BuildInMemoryDBProvider(); using (var dbContext = service.GetService <DatabaseContext>()) { var configuration = new MapperConfiguration(cfg => { cfg.CreateMap <MobilePhone, MobilePhoneForHomeVM>(); }); //Arrange var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = await mobilePhoneService.GetMobilePhonesForHome(); //Assert result.Should().HaveCount(0); } }
public async Task GetMobilePhonesForHomeTest_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, MobilePhoneForHomeVM>(); }); var mapper = new Mapper(configuration); var mobilePhoneRepository = new MobilePhoneRepository(dbContext); var mobilePhoneService = new MobilePhoneService(mobilePhoneRepository, mapper); //Act var result = await mobilePhoneService.GetMobilePhonesForHome(); //Assert result.Should().HaveCount(3); result.Should().BeOfType <List <MobilePhoneForHomeVM> >(); } }