public void ByVendor_Should_Throw_ArgumentException_If_VendorId_Is_Empty() { IQueryable <Product> products = new Product[0].AsQueryable(); Guid vendorId = Guid.Empty; var ex = Assert.Throws <ArgumentException>(() => ProductExtensions.ByVendor(products, vendorId)); Assert.Equal(nameof(vendorId), ex.ParamName); }
public void ByVendor_Should_Throw_ArgumentNullException_If_Products_Is_Null() { IQueryable <Product> products = null; Guid vendorId = Guid.NewGuid(); var ex = Assert.Throws <ArgumentNullException>(() => ProductExtensions.ByVendor(products, vendorId)); Assert.Equal(nameof(products), ex.ParamName); }
public void ByVendor_Should_Return_Only_Products_With_The_Specified_Vendor() { var vendor = Brand.Create("brand", "brand"); var p1 = Product.Create("ean", "sku", "name", "url"); var p2 = Product.Create("ean", "sku", "name", "url"); var p3 = Product.Create("ean", "sku", "name", "url"); p1.SetVendor(vendor); p2.SetVendor(vendor); IQueryable <Product> products = new Product[] { p1, p2, p3 }.AsQueryable(); Guid vendorId = vendor.Id; var productsByVendor = ProductExtensions.ByVendor(products, vendorId).ToArray(); Assert.True(productsByVendor.All(p => p.Vendor != null && p.Vendor.Id == vendorId)); }