public void GetCartTest() { var products = new List <CartProduct> { new CartProduct { ProductId = 1, ProductName = "Product 1", Value = 0.25M, StockId = 1, Qty = 1 }, new CartProduct { ProductId = 2, ProductName = "Product 2", Value = 10.99M, StockId = 2, Qty = 3 } }; var mock = new Mock <ISessionManager>(); mock.Setup(p => p.GetCart(It.IsAny <Func <CartProduct, GetCart.Response> >())) .Returns <Func <CartProduct, GetCart.Response> >(selector => products.Select(selector).ToList()); var cart = new GetCart(mock.Object).Do().ToList(); var ans = new List <GetCart.Response>() { new GetCart.Response { Name = "Product 1", RealValue = 0.25M, Value = "$0.25", Qty = 1, StockId = 1 }, new GetCart.Response { Name = "Product 2", RealValue = 10.99M, Value = "$10.99", Qty = 3, StockId = 2 } }; Assert.Equal(ans.Count(), cart.Count()); for (int i = 0; i < cart.Count(); i++) { var product = ans.FirstOrDefault(x => x.Name == cart[i].Name && x.RealValue == cart[i].RealValue && x.Value == cart[i].Value && x.Qty == cart[i].Qty && x.StockId == cart[i].StockId ); Assert.NotNull(product); ans.Remove(product); } }