コード例 #1
0
        public void InvoiceBLLHasItemMethod()
        {
            //Arrange
            var data = new List <Items>
            {
                new Items()
                {
                    Id          = "1", Quantity = 12, OriginalPrice = 1, SalesPrice = 2,
                    ProductName = "Pen", Status = "Factory New"
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Items> >();

            mockSet.As <IQueryable <Items> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Items> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Items> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Items> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var mockContext = new Mock <OfficeStoreContext>();

            mockContext.Setup(c => c.Items).Returns(mockSet.Object);

            InvoiceBLL invoiceBLL = new InvoiceBLL(mockContext.Object);

            // Act
            bool HasNotItem = invoiceBLL.HasNotItem("1");

            //Assert
            Assert.IsFalse(HasNotItem);
        }