public async Task GetLaptopList_ReturnsLaptopList() { // Arrange await using var context = new LaptopShopContext(_options); await context.Laptops.AddRangeAsync(MockDataProvider.GetMockLaptopList()); await context.SaveChangesAsync(); // Act var result = await new LaptopRepository(context).GetLaptopList(); // Assert var returnValue = Assert.IsType <Laptop[]>(result); var laptop = returnValue.FirstOrDefault(); Assert.NotNull(laptop); Assert.Equal("Dell", laptop.Name); }
public async Task AddToBasket_ReturnsLaptopConfigurationList() { // Arrange await using var context = new LaptopShopContext(_options); await context.Basket.AddRangeAsync(MockDataProvider.GetBasketItems()); await context.SaveChangesAsync(); // Act var item = new BasketItem { LaptopId = 2, LaptopConfigurationIdList = new List <int> { 1, 4, 5 } }; var result = await new LaptopRepository(context).AddToBasket(item); // Assert Assert.NotNull(result); Assert.IsType <Basket[]>(result); Assert.Equal(6, result.Length); Assert.Equal(2, result.Select(r => r.LaptopId).Distinct().Count()); }
public LaptopRepository(LaptopShopContext laptopShopContext) { _laptopShopContext = laptopShopContext; }