public void ShouldAssertProjectionWhenCombinedWithWhere() { var simpleDataInstance = new SimpleData(); // ARRANGE - When simpleDataInstance.Products_GET is called, it should return expected collection. Mock.Arrange(() => simpleDataInstance.Products).ReturnsCollection(ReturnExpextedCollectionOfProducts()); // ACT - Applying a LINQ query for simpleDataMock.Products. var actual = (from p in simpleDataInstance.Products where p.UnitsInStock == 50 select new { p.ProductID, p.ProductName }).SingleOrDefault(); // ASSERT Assert.AreEqual(2, actual.ProductID); }
public void ShouldAssertWithJoinClause() { var simpleDataInstance = new SimpleData(); // ARRANGE // Arranging: When simpleDataInstance.Products_GET is called, it should return expected products collection. Mock.Arrange(() => simpleDataInstance.Products).ReturnsCollection(ReturnExpextedCollectionOfProducts()); // Arranging: When simpleDataInstance.Categories_GET is called, it should return expected categories collection. Mock.Arrange(() => simpleDataInstance.Categories).ReturnsCollection(ReturnExpectedCollectionOfCategories()); // ACT - Applying a LINQ query for simpleDataMock.Products. var actual = from product in simpleDataInstance.Products join category in simpleDataInstance.Categories on product.CategoryID equals category.CategoryID select category.CategoryName; // ASSERT Assert.AreEqual(3, actual.Count()); }
public void ShouldAssertWithExpressionAsAnArgument() { int expectedId = 10; // ARRANGE var simpleDataInstance = new SimpleData(); // Arranging: When simpleDataInstance.Products_GET is called, it should return expected products collection. Mock.Arrange(() => simpleDataInstance.Products).ReturnsCollection(ReturnExpextedCollectionOfProducts()); // Directly arranging a chain call with LINQ query in it. If called with the exact parameters, it should return expectedId. var datum = simpleDataInstance.Products.Where(x => x.ProductID == 2).FirstOrDefault(); Mock.Arrange(() => datum.GetId()).Returns(expectedId); // ACT Product actual = simpleDataInstance.GetProduct(2); // ASSERT Assert.AreEqual(expectedId, actual.GetId()); }