public void SignIn_should_add_adminUser_to_session_when_email_and_password_match_user_in_database()
        {
            var adminUser = new AdminUser();
            var fakeSession = new Mock<HttpSessionStateBase>();
            fakeSession.Setup(x => x.Add(It.IsAny<string>(), It.IsAny<object>())).Verifiable();

            service.SignIn(adminUser, fakeSession.Object);

            fakeSession.Verify(x=>x.Add(It.Is<string>(y=>y == "adminUser"), It.IsAny<object>()), Times.AtLeastOnce());
        }
        public void SignIn(AdminUser adminUser, HttpSessionStateBase session)
        {
            if (adminUser == null)
            {
                throw new ArgumentNullException("Invalid authentication");
            }

            formsAuthentication.SetAuthCookie(adminUser.Name, false);
            session.Add("adminUser", adminUser);
        }
        public void LogOn_should_redirect_to_Index_action_on_HomeController_when_user_is_valid_and_url_is_not_local()
        {
            AdminUser adminUser = new AdminUser();
            service.Setup(x => x.IsValidUser(It.IsAny<string>(), It.IsAny<string>(), out adminUser)).Returns(true).Verifiable();
            service.Setup(x => x.SignIn(It.IsAny<AdminUser>(), It.IsAny<HttpSessionStateBase>())).Verifiable();
            //var mockUrlHelper = new Mock<UrlHelper>();
            //mockUrlHelper.Setup(x => x.IsLocalUrl(It.IsAny<string>())).Returns(false);
            var controllerContext = Fakes.MockedContext();
            var routes = new RouteCollection();

            controller.ControllerContext = controllerContext.Object;
            controller.Url = new UrlHelper(new RequestContext(controllerContext.Object.HttpContext, new RouteData()), routes);

            var action = controller.LogOn(new LogOnModel(), "http://www.disney.com") as RedirectResult;

            Assert.That(action.Url, Is.EqualTo("/Home/Index"));
        }
Exemplo n.º 4
0
        public void ThisMethod_should_create_data_for_ChopShop_when_it_is_executed()
        {
            using (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted))
            {
                // Create Categories
                var engines = new Category { Name = "Engines", Description = "All the engines you can imagine" };
                var tyres = new Category { Name = "Tyres", Description = "We have round tyres and square tyres!" };
                var parts = new Category { Name = "Body Parts", Description = "Doors, Wings and all sorts of Panels" };
                var cars = new Category { Name = "Cars", Description = "All shapes, most sizes, lots of prices" };
                var lorries = new Category { Name = "Lorries", Description = "Red ones, Yellow ones and even Blue ones" };
                var bicycles = new Category
                                   {
                                       Name = "Bicycles",
                                       Description = "Some of these have two wheels - some have only one"
                                   };
                var bicycleParts = new Category { Name = "Bicycle Parts", Description = "Derailleurs, Gears, Pedals" };

                engines.Parent = cars;
                tyres.Parent = cars;
                bicycleParts.Parent = bicycles;
                parts.Parent = lorries;

                var categories = new List<Category>
                                     {
                                         engines,
                                         tyres,
                                         parts,
                                         cars,
                                         lorries,
                                         bicycles,
                                         bicycleParts
                                     };
                foreach (var category in categories)
                {
                    session.Save(category);
                }

                // Create Products
                var bluepedal = new Product
                                    {
                                        Name = "Blue Pedal",
                                        Description = "This pedal is blue",
                                        Quantity = 10,
                                        Sku = "BluePedal0001"
                                    };
                var redpedal = new Product
                                   {
                                       Name = "Red Pedal",
                                       Description = "This pedal is red",
                                       Quantity = 3,
                                       Sku = "RedPedal0002"
                                   };
                var bigEngine = new Product
                                    {
                                        Name = "3.0 L V12",
                                        Description = "This is a fast one",
                                        Sku = "Eng00v12",
                                        Quantity = 2
                                    };

                var products = new List<Product> { bluepedal, redpedal, bigEngine };
                products.AddRange(GetProducts());
                foreach (var product in products)
                {
                    session.Save(product);
                }

                // Associate Categories To Products
                bicycleParts.Products = new List<Product> { bluepedal, redpedal };
                engines.Products = new List<Product> { bigEngine };

                session.SaveOrUpdate(bicycleParts);
                session.SaveOrUpdate(engines);

                var adminUser = new AdminUser { Email = "*****@*****.**", Name = "admin", Password = "******" };
                session.SaveOrUpdate(adminUser);

                tx.Commit();
            }
        }
 public bool IsValidUser(string email, string password,out AdminUser adminUser)
 {
     adminUser = adminService.GetUserForLogin(email, password);
     return adminUser != null;
 }
        public void LogOn_should_redirect_to_URL_requested_when_user_is_valid_and_url_is_local()
        {
            AdminUser adminUser = new AdminUser();
            service.Setup(x => x.IsValidUser(It.IsAny<string>(), It.IsAny<string>(), out adminUser)).Returns(true).Verifiable();
            service.Setup(x => x.SignIn(It.IsAny<AdminUser>(), It.IsAny<HttpSessionStateBase>())).Verifiable();
            var routes = new RouteCollection();
            controller.ControllerContext = Fakes.MockedContext().Object;
            controller.Url = new UrlHelper(new RequestContext(Fakes.MockedContext().Object.HttpContext, new RouteData()), routes);

            var action = controller.LogOn(new LogOnModel(), "/Product/List") as RedirectResult;

            Assert.That(action.Url, Is.EqualTo("/Product/List"));
        }