public void Can_add_a_product_via_a_controller() { IHypermartContext x = new FakeHypermartContext(); var controller = new ProductsController { db = x }; var fakeHTTPSession = new FonySession(); fakeHTTPSession.AddFileUpload(new PhonyUploadFile("Screensjot.jpg", GetResourceAsStrream("TestAPI.img100.jpg"), "JPG")); controller.ControllerContext = fakeHTTPSession.BuildControllerContext(controller); controller.Url = new UrlHelper(fakeHTTPSession.BuildRequestContext()); var res = controller.Create(new Product { ID = 1, Description = "NewProd", Files = null, Lead = "Lead USer", Maintainers = new List<String> { "m1", "m2", "m3" }, Screenshots = new List<Screenshot>(), SourceCode = null, Tagline = "TagLine", Title = "Title" }); Assert.AreEqual(1, controller.db.Products.Count()); }
public void Can_Add_A_Product_Via_A_Controller() { var mockEFContext = new Mock <IHypermartContext>(); var Products = new List <Product> { new Product { ID = 1, Title = "FirstProduct", Description = "First Product In Database" } }.AsQueryable(); var mockSet = new Mock <DbSet <Product> >(); mockSet.As <IQueryable <Product> >().Setup(m => m.Provider).Returns(Products.Provider); mockSet.As <IQueryable <Product> >().Setup(m => m.Expression).Returns(Products.Expression); mockSet.As <IQueryable <Product> >().Setup(m => m.ElementType).Returns(Products.ElementType); mockSet.As <IQueryable <Product> >().Setup(m => m.GetEnumerator()).Returns(Products.GetEnumerator()); mockEFContext.Setup(x => x.Products).Returns(mockSet.Object); var prodcontroller = new Open.GI.hypermart.Controllers.ProductsController() { db = mockEFContext.Object }; var fakeHTTPSession = new TitaniumBunker.PhonySession.FonySession(); fakeHTTPSession.AddFileUpload(new PhonyUploadFile("Screensjot.jpg", GetResourceAsStrream("TestAPI.img100.jpg"), "JPG")); prodcontroller.ControllerContext = fakeHTTPSession.BuildControllerContext(prodcontroller); prodcontroller.Url = new UrlHelper(fakeHTTPSession.BuildRequestContext()); var res = prodcontroller.Create(new Product { ID = 2, Description = "foobar" }); }
public void Can_Add_A_Product_Via_A_Controller() { var mockEFContext = new Mock<IHypermartContext>(); var Products = new List<Product> { new Product{ID = 1,Title = "FirstProduct",Description = "First Product In Database"} }.AsQueryable(); var mockSet = new Mock<DbSet<Product>>(); mockSet.As<IQueryable<Product>>().Setup(m => m.Provider).Returns(Products.Provider); mockSet.As<IQueryable<Product>>().Setup(m => m.Expression).Returns(Products.Expression); mockSet.As<IQueryable<Product>>().Setup(m => m.ElementType).Returns(Products.ElementType); mockSet.As<IQueryable<Product>>().Setup(m => m.GetEnumerator()).Returns(Products.GetEnumerator()); mockEFContext.Setup(x => x.Products).Returns(mockSet.Object); var prodcontroller = new Open.GI.hypermart.Controllers.ProductsController() { db = mockEFContext.Object }; var fakeHTTPSession = new TitaniumBunker.PhonySession.FonySession(); fakeHTTPSession.AddFileUpload(new PhonyUploadFile("Screensjot.jpg", GetResourceAsStrream("TestAPI.img100.jpg"), "JPG")); prodcontroller.ControllerContext = fakeHTTPSession.BuildControllerContext(prodcontroller); prodcontroller.Url = new UrlHelper(fakeHTTPSession.BuildRequestContext()); var res = prodcontroller.Create(new Product { ID = 2, Description = "foobar" }); }