Beispiel #1
0
        public void CanListAllProducts()
        {
            StoreContentController CUT = new Open.GI.hypermart.Controllers.StoreContentController(mockEFContext.Object);
            var s = mockSet.Object;
            var t = mockSet.Object;
            var u = mockEFContext.Object.Products;
            var v = mockEFContext.Object.Products;

            var AllProducts = CUT.GetAllProducts();

            Assert.AreEqual(3, AllProducts.Count(), "Expected 3 products");
        }
Beispiel #2
0
        public void DeleteAProduct()
        {
            var     objContext      = mockEFContext.Object;
            var     Products        = objContext.Products.Count();
            Product ProductToRemove = mockEFContext.Object.Products.FirstOrDefault(x => x.ID == 2);


            //var mockContext = new Mock<IHypermartContext>();
            mockEFContext.Setup(m => m.Products).Returns(mockSet.Object);
            mockEFContext.Setup(m => m.Products.Find(ProductToRemove.ID)).Returns(ProductToRemove);

            //Act
            StoreContentController CUT = new Open.GI.hypermart.Controllers.StoreContentController(mockEFContext.Object);

            CUT.DeleteProduct(ProductToRemove.ID);
            mockEFContext.Verify(m => m.Products.Remove(ProductToRemove), Times.Once());
            mockEFContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Beispiel #3
0
        public void CanAddNewProductMoq()
        {
            //Arrange


            var ProductToAdd = new Product()
            {
                ID = 4, Description = "d4", Files = null, Lead = "l4", Screenshots = null, Tagline = "tl4", Title = "title4"
            };

            mockEFContext.Setup(m => m.Products.Add(It.IsAny <Product>())).Returns(ProductToAdd);


            //Act
            StoreContentController CUT = new Open.GI.hypermart.Controllers.StoreContentController(mockEFContext.Object);

            var res = CUT.PostProduct(ProductToAdd);


            mockEFContext.Verify(m => m.Products.Add(ProductToAdd), Times.Once());
            mockEFContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Beispiel #4
0
        /// <summary>
        /// Determines whether this instance can delete a product.
        /// </summary>

        public void CanDeleteProduct()
        {
            //Arrange
            var _MockRepo = new MockRepository(MockBehavior.Strict);

            var productToDelete = new Product
            {
                ID          = 100,
                Description = "Product 100",
                Files       = null,
                Lead        = "Lead Developer",
                Maintainers = new List <string> {
                    "Maintainer 1", "Maintainer2"
                },
                Screenshots = null,
                SourceCode  = "",
                Tagline     = "tagline",
                Title       = "title"
            };


            // Mocking a DB Set
            IEnumerable <Product> productList = new List <Product>();
            var productData = productList.AsQueryable();

            var _productSet = _MockRepo.Create <DbSet <Product> >();

            //_productSet.As<IDbSet<Product>>().Setup(x => x.Local).Returns(productData);
            //_productSet.As<IQueryable<Product>>().Setup(x => x.Provider).Returns(productData.Provider);
            // _productSet.As<IQueryable<Product>>().Setup(x => x.Expression).Returns(productData.Expression);
            //_productSet.As<IQueryable<Product>>().Setup(x => x.ElementType).Returns(productData.ElementType);
            //_productSet.As<IQueryable<Product>>().Setup(x => x.GetEnumerator()).Returns(productData.GetEnumerator());



            //var _MockHypermartContext =  _MockRepo.Create<IHypermartContext>();
            //_MockHypermartContext.Setup(m => m.Products).Returns(_productSet.Object);



            mockEFContext.Setup(x => x.Products.Find(productToDelete.ID)).Returns(productToDelete);
            mockEFContext.Setup(x => x.Products.Remove(productToDelete)).Returns(productToDelete);
            mockEFContext.Setup(x => x.SaveChanges()).Verifiable();
            //_MockHypermartContext.Setup(x => x.Products.Local).Returns(new ObservableCollection<Product>());



            //var _MockHypermartProductDB = _MockRepo.Create<IDbSet<Product>>();
            //_MockHypermartProductDB.As<IDbSet<Business>>().Setup(m => m.Provider).Returns(queryableTestData.Provider);
            //mockSet.As<IDbSet<Business>>().Setup(m => m.Expression).Returns(queryableTestData.Expression);
            //mockSet.As<IDbSet<Business>>().Setup(m => m.ElementType).Returns(queryableTestData.ElementType);
            //mockSet.As<IDbSet<Business>>().Setup(m => m.GetEnumerator()).Returns(() => queryableTestData.GetEnumerator());
            //_MockHypermartProductDB.As<IDbSet<Product>>().Setup(m => m.Local).Returns(null);



            var _MockProductsList = _MockRepo.Create <IList <Product> >();



            var CUT = new Open.GI.hypermart.Controllers.StoreContentController(mockEFContext.Object);


            //Act
            CUT.DeleteProduct(100);
            _MockRepo.VerifyAll();
        }