コード例 #1
0
ファイル: ShoppingCart.cs プロジェクト: maximn/Verde
        public void AddToCart_ValidItem_Succeeds()
        {
            // Get a product to load the details page for.
            var album = storeDB.Albums
                .Take(1)
                .First();

            var settings = new ExecutorSettings("ShoppingCart/AddToCart/" + album.AlbumId)
            {
                User = new GenericPrincipal(new GenericIdentity("GenghisKahn"), null)
            };

            using (var scope = new MvcExecutorScope(settings))
            {
                Assert.AreEqual(302, scope.HttpContext.Response.StatusCode);
                Assert.AreEqual("/ShoppingCart", scope.HttpContext.Response.RedirectLocation);

                // Now verify that the cart contains the item we just added.
                var cart = MvcMusicStore.Models.ShoppingCart.GetCart(scope.HttpContext);
                var cartItems = cart.GetCartItems();
                Assert.AreEqual(1, cartItems.Count);
                Assert.AreEqual(album.AlbumId, cartItems[0].AlbumId);

                // Finally clear the cart.
                cart.EmptyCart();
            }
        }
コード例 #2
0
ファイル: DetailsPage.cs プロジェクト: xuanvu/Verde
        public void Index_Load_ExpectedHtml()
        {
            // Get a product to load the details page for.
            var album = storeDB.Albums
                .Take(1)
                .First();

            using (var scope = new MvcExecutorScope("Store/Details/" + album.AlbumId))
            {
                Assert.AreEqual(200, scope.HttpContext.Response.StatusCode);
                Assert.IsTrue(scope.Controller is StoreController);
                Assert.AreEqual("Details", scope.Action);

                var model = scope.Controller.ViewData.Model as Album;
                Assert.IsNotNull(model);
                Assert.AreEqual(album.AlbumId, model.AlbumId);

                Assert.IsFalse(String.IsNullOrEmpty(scope.ResponseText));

                // Load the ResponseText into an HtmlDocument
                var html = new HtmlDocument();
                html.LoadHtml(scope.ResponseText);

                // Use ScrappySharp CSS selector to make assertions about the rendered HTML
                Assert.AreEqual(album.Title, html.DocumentNode.CssSelect("#main h2").First().InnerText);
            }
        }
コード例 #3
0
ファイル: Account.cs プロジェクト: xuanvu/Verde
        public void Register_InvalidPassword_Fails()
        {
            string invalidPassword = "******";
            var formData = new HttpValueCollection {
                {"UserName", "Bill"},
                {"Email", "*****@*****.**"},
                {"Password", invalidPassword},
                {"ConfirmPassword", invalidPassword}
            };

            using (var scope = new MvcExecutorScope(new ExecutorSettings("Account/Register") { Form = formData }))
            {
                var responseText = scope.ResponseText;

                Assert.IsFalse(scope.ViewData.ModelState.IsValid);

                var errors = new List<string>();
                foreach (var modelState in scope.ViewData.ModelState.Values)
                    errors.AddRange(modelState.Errors.Select<ModelError, string>(e => e.ErrorMessage));

                Assert.AreEqual(1, errors.Count);

                string passwordError = "The Password must be at least 6 characters long.";
                Assert.AreEqual(passwordError, errors[0]);

                var html = new HtmlDocument();
                html.LoadHtml(scope.ResponseText);

                var passwordErrorSpan = html.DocumentNode.CssSelect("span.field-validation-error");
                Assert.AreEqual(1, passwordErrorSpan.Count());
                Assert.AreEqual(passwordError, passwordErrorSpan.ElementAt(0).InnerText);
            }
        }
コード例 #4
0
ファイル: Store.cs プロジェクト: xuanvu/Verde
        public void ControllerEvents_DoExecute()
        {
            using (var scope = new MvcExecutorScope("Store"))
            {
                var model = scope.ViewData.Model as IList<Genre>;
                Assert.IsNotNull(model);

                Assert.IsTrue((bool)scope.HttpContext.Items["OnActionExecuting"]);
                Assert.IsTrue((bool)scope.HttpContext.Items["OnActionExecuted"]);
                Assert.IsTrue((bool)scope.HttpContext.Items["OnResultExecuting"]);
                Assert.IsTrue((bool)scope.HttpContext.Items["OnResultExecuted"]);
            }
        }
コード例 #5
0
ファイル: Checkout.cs プロジェクト: maximn/Verde
        public void Checkout_Success()
        {
            string userName = "******";
            int numItemsInCart = 2;

            var cart = TestUtil.AddItemsToCart(userName, storeDB.Albums.Take(numItemsInCart));

            var form = new HttpValueCollection
            {
             { "FirstName","Miles"},
             {"LastName","Davis"},
             {"Address","100 Broadway Ave."},
             {"City","New York"},
             {"State","NY"},
             {"PostalCode","12345"},
             {"Country","United States"},
             {"Phone","111-111-1111"},
             {"Email","*****@*****.**"},
             {"PromoCode","FREE"}
            };

            var settings = new ExecutorSettings("Checkout/AddressAndPayment") {
                Form=form,
                HttpMethod="POST",
                User=TestUtil.CreateUser(userName)
            };

            Order order;
            using (var scope = new MvcExecutorScope(settings))
            {
                Assert.AreEqual(302, scope.HttpContext.Response.StatusCode);

                var match = new Regex("/Checkout/Complete/(\\d+)").Match(scope.HttpContext.Response.RedirectLocation);
                Assert.IsTrue(match.Success);

                var orderId = Int32.Parse(match.Groups[1].Value);

                order = storeDB.Orders.Single(o=>o.OrderId==orderId);
                Assert.AreEqual(form["FirstName"], order.FirstName);
                Assert.AreEqual(form["Email"], order.Email);

                var orderDetails = storeDB.OrderDetails.Where(od => od.OrderId == orderId);
                Assert.AreEqual(numItemsInCart, orderDetails.Count());
            }

            // Cleanup
            storeDB.Orders.Remove(order);
            storeDB.SaveChanges();
        }
コード例 #6
0
ファイル: HomePage.cs プロジェクト: maximn/Verde
        public void Index_Load_ExpectedHtml()
        {
            using (var scope = new MvcExecutorScope(""))
            {
                var controller = scope.Controller as HomeController;
                Assert.IsNotNull(controller);
                Assert.AreEqual(scope.Action, "Index");

                var model = controller.ViewData.Model as List<MvcMusicStore.Models.Album>;
                Assert.IsNotNull(model, "Expected the Model to be a list of Albums.");

                var html = new HtmlDocument();
                html.LoadHtml(scope.ResponseText);

                AssertCategoryMenuValid(html);
                AssertAlbumListValid(html);
            }
        }
コード例 #7
0
ファイル: Meta.cs プロジェクト: xuanvu/Verde
        public void Autofac_ResolveHttpRequest_UsesCorrectLifetimeScope()
        {
            using (var scope = new MvcExecutorScope("Meta", "testparam=1"))
            {
                //var context = DependencyResolver.Current.GetService<HttpContextBase>();

                var request = DependencyResolver.Current.GetService<HttpRequestBase>();
                Assert.AreEqual("1", request.QueryString["testparam"]);
            }

            using (var scope = new MvcExecutorScope("Meta", "testparam=2"))
            {
                //var context = DependencyResolver.Current.GetService<HttpContextBase>();

                var request = DependencyResolver.Current.GetService<HttpRequestBase>();
                Assert.AreEqual("2", request.QueryString["testparam"]);
            }

            // Now that we are outside the executor scope, resolving the HttpRequestBase should return to the
            // actual HttpRequest.
            //Assert.IsNullOrEmpty(DependencyResolver.Current.GetService<HttpRequestBase>().QueryString["scope"]);
        }
コード例 #8
0
ファイル: Account.cs プロジェクト: xuanvu/Verde
        public void Register_ValidInput_Redirects()
        {
            var formData = new HttpValueCollection {
                {"UserName", "ChrisColumbus"},
                {"Email", "*****@*****.**"},
                {"Password", "explore_1492"},
                {"ConfirmPassword", "explore_1492"}
            };

            try
            {
                using (var scope = new MvcExecutorScope(new ExecutorSettings("Account/Register") { Form = formData }))
                {
                    Assert.IsTrue(scope.ViewData.ModelState.IsValid);
                    Assert.AreEqual(302, scope.HttpContext.Response.StatusCode);
                    Assert.AreEqual("/", scope.HttpContext.Response.RedirectLocation);
                }
            }
            finally
            {
                // Cleanup
                Membership.DeleteUser(formData["UserName"]);
            }
        }
コード例 #9
0
ファイル: ShoppingCart.cs プロジェクト: maximn/Verde
        public void ViewCart_ExpectedHtml()
        {
            var albumsToCart = storeDB.Albums.Take(2);
            string userName = "******";

            var cart = TestUtil.AddItemsToCart(userName, albumsToCart);

            var settings = new ExecutorSettings("ShoppingCart/Index")
            {
                User = TestUtil.CreateUser(userName)
            };

            using (var scope = new MvcExecutorScope(settings))
            {
                var viewModel = scope.ViewData.Model as ShoppingCartViewModel;
                Assert.IsNotNull(viewModel);
                Assert.AreEqual(albumsToCart.Count(), viewModel.CartItems.Count);
                foreach (var album in albumsToCart)
                    Assert.IsTrue(viewModel.CartItems.Any(c => c.AlbumId == album.AlbumId));

                Assert.IsFalse(String.IsNullOrEmpty(scope.ResponseText));
            }

            // Cleanup
            cart.EmptyCart();
        }
コード例 #10
0
ファイル: ShoppingCart.cs プロジェクト: maximn/Verde
        public void RemoveFromCart_ValidJson()
        {
            // Add an item to the cart so we have something to remove.
            string userName = "******";
            MvcMusicStore.Models.ShoppingCart cart = TestUtil.AddItemsToCart(
                userName, storeDB.Albums.Take(1));
            var recordId = cart.GetCartItems().First().RecordId;

            var settings = new ExecutorSettings("ShoppingCart/RemoveFromCart/" + recordId)
            {
                User = TestUtil.CreateUser(userName),
                HttpMethod = "POST"
            };

            using (var scope = new MvcExecutorScope(settings))
            {
                Assert.AreEqual("application/json", scope.HttpContext.Response.ContentType, "Expected json to be returned.");

                var deserializedResponse = JsonConvert.DeserializeObject<ShoppingCartRemoveViewModel>(scope.ResponseText);
                Assert.AreEqual(0.0d, deserializedResponse.CartTotal, "The shopping cart total should be $0.00.");
                Assert.AreEqual(0, deserializedResponse.ItemCount, "The shopping cart should have 0 items left.");
                Assert.AreEqual(recordId, deserializedResponse.DeleteId);
            }
        }