public void AccountControllerLogin()
        {
            const bool ISAJAX = true;
            var info = new LoginModel()
            {
                Email = "Admin",
                Password = "******"
            };
            string returnUrl = "returnUrl";

            var factory = new WorkChannelFactoryMock();
            var auth = new FakeAuthenticationService();
            var ctrl = new AccountController(factory, auth);
            FakeControllerSession.SetFakeControllerContext(ctrl, ISAJAX);

            //Pass if everything ok
            var res2 = ctrl.Login(info, returnUrl) as RedirectToRouteResult;
            Assert.IsNotNull(res2);
            Assert.AreEqual(res2.RouteValues["action"], "Index");

            var user = ctrl.Session["User"] as UserDTO;
            Assert.IsNotNull(user);
            Assert.AreEqual(user.Email, "Admin");
            Assert.AreEqual(user.Password, "123");

            //Fault when wrong user
            info.Email = "unknown";
            var res3 = ctrl.Login(info, returnUrl) as ViewResult;
            Assert.IsNotNull(res3);
            Assert.AreEqual(res3.Model, "wrong user");
        }
        public void AccountControllerLogoff()
        {
            const bool ISAJAX = true;

            var factory = new WorkChannelFactoryMock();
            var auth = new FakeAuthenticationService();
            var ctrl = new AccountController(factory, auth);
            FakeControllerSession.SetFakeControllerContext(ctrl, ISAJAX);

            var res2 = ctrl.LogOff() as RedirectToRouteResult;
            Assert.IsNotNull(res2);
            Assert.AreEqual(res2.RouteValues["action"], "Index");
        }
        public void AccountControllerRegister()
        {
            const bool ISAJAX = true;
            var info = new RegisterViewModel()
            {
                UserName = "******",
                Password = "******",
                ConfirmPassword = "******",
                Address = "asd"
            };

            var factory = new WorkChannelFactoryMock();
            var auth = new FakeAuthenticationService();
            var ctrl = new AccountController(factory, auth);
            FakeControllerSession.SetFakeControllerContext(ctrl, ISAJAX);

            var res2 = ctrl.Register(info) as RedirectToRouteResult;
            Assert.IsNotNull(res2);
            Assert.AreEqual(res2.RouteValues["action"], "Index");
            Assert.AreEqual(factory.LastWorkChannel.UsersRegistered.Count, 1);
            Assert.AreEqual(factory.LastWorkChannel.UsersRegistered[0].Email, "Admin");
        }
        public void HomeControllerMakeOrder()
        {
            const bool ISAJAX = false;
            var info = new List<OrderInfoDTO>()
            {
                new OrderInfoDTO()
                {
                    Ingredients = new int[] { 1, 2 },
                    Quantities = new string[] { "normal", "extra" },
                    Size = "big"
                }
            };

            var factory = new WorkChannelFactoryMock();
            HomeController ctrl = new HomeController(factory);
            FakeControllerSession.SetFakeControllerContext(ctrl, ISAJAX);

            //Redirect if not logged
            ctrl.Session["LoggedIn"] = false;
            var res1 = ctrl.MakeOrder(info) as RedirectToRouteResult;
            Assert.IsNotNull(res1);
            Assert.AreEqual(res1.RouteValues["action"], "Login");
            Assert.AreEqual(res1.RouteValues["controller"], "Account");

            //Pass if everything ok
            ctrl.Session["LoggedIn"] = true;
            ctrl.MakeOrder(info);

            Assert.IsTrue(factory.LastWorkChannel.OrdersMade.Count == 1);
            Assert.IsTrue(factory.LastWorkChannel.OrdersMade[0].Ingredients.Length == 2);
            Assert.IsNull(factory.LastWorkChannel.OrdersRemoved);

            //Fault when wrong user
            ((UserDTO)ctrl.Session["User"]).Email = "Unknown";
            var res3 = ctrl.MakeOrder(info) as ViewResult;
            Assert.IsNotNull(res3);
            Assert.AreEqual(res3.Model, "wrong user");
        }
        public void HomeControllerEditProfilePOST()
        {
            const bool ISAJAX = true;
            var info = new UserViewModel()
            {
                Email = "Admin",
                Password = "******",
                Address = "Address",
                Phone = 999,
                Name = "AdminName2"
            };

            var factory = new WorkChannelFactoryMock();
            HomeController ctrl = new HomeController(factory);
            FakeControllerSession.SetFakeControllerContext(ctrl, ISAJAX);

            //Redirect if not logged
            // TODO - maybe we need to remove this
            ctrl.Session["LoggedIn"] = false;
            var res1 = ctrl.EditProfile(info) as RedirectToRouteResult;
            Assert.IsNotNull(res1);
            Assert.AreEqual(res1.RouteValues["action"], "Login");
            Assert.AreEqual(res1.RouteValues["controller"], "Account");

            //Pass if everything ok
            ctrl.Session["LoggedIn"] = true;
            var res2 = ctrl.EditProfile(info) as RedirectToRouteResult;
            Assert.IsNotNull(res2);
            Assert.AreEqual(res2.RouteValues["action"], "Index");

            var upd = factory.LastWorkChannel.UsersUpdated;
            Assert.AreEqual(upd.Count, 1);
            Assert.AreEqual(upd[0].Name, ((UserDTO)ctrl.Session["User"]).Name);
            Assert.AreEqual(upd[0].Name, "AdminName2");

            //Fault when wrong user
            ((UserDTO)ctrl.Session["User"]).Email = "Unknown";
            var res3 = ctrl.EditProfile(info) as ViewResult;
            Assert.IsNotNull(res3);
            Assert.AreEqual(res3.Model, "wrong user or password");
        }
        public void HomeControllerEditProfileGET()
        {
            const bool ISAJAX = false;
            var factory = new WorkChannelFactoryMock();
            HomeController ctrl = new HomeController(factory);
            FakeControllerSession.SetFakeControllerContext(ctrl, ISAJAX);

            //Redirect if not logged
            ctrl.Session["LoggedIn"] = false;
            var res1 = ctrl.EditProfile() as RedirectToRouteResult;
            Assert.IsNotNull(res1);
            Assert.AreEqual(res1.RouteValues["action"], "Login");
            Assert.AreEqual(res1.RouteValues["controller"], "Account");

            //Pass if everything ok
            ctrl.Session["LoggedIn"] = true;
            ctrl.EditProfile();
            var res2 = ctrl.EditProfile() as ViewResult;
            Assert.IsNotNull(res2);
            Assert.IsNotNull(res2.Model);

            var user = res2.Model as UserViewModel;
            Assert.IsNotNull(user);
            Assert.AreEqual(user.Email, "Admin");
        }
        public void HomeControllerCreateComplaint()
        {
            const bool ISAJAX = true;
            string body = "complaint body";

            var factory = new WorkChannelFactoryMock();
            HomeController ctrl = new HomeController(factory);
            FakeControllerSession.SetFakeControllerContext(ctrl, ISAJAX);

            //Redirect if not logged
            // TODO - maybe we need to remove this
            ctrl.Session["LoggedIn"] = false;
            var res1 = ctrl.CreateComplaint(body) as RedirectToRouteResult;
            Assert.IsNotNull(res1);
            Assert.AreEqual(res1.RouteValues["action"], "Login");
            Assert.AreEqual(res1.RouteValues["controller"], "Account");

            //Pass if everything ok
            ctrl.Session["LoggedIn"] = true;
            var res2 = ctrl.CreateComplaint(body) as RedirectToRouteResult;
            Assert.IsNotNull(res2);
            Assert.AreEqual(res2.RouteValues["action"], "Index");

            var upd = factory.LastWorkChannel.ComplaintsMade;
            Assert.AreEqual(upd.Count, 1);
            Assert.AreEqual(upd[0].Body, "complaint body");

            //Fault when wrong user
            ((UserDTO)ctrl.Session["User"]).Email = "Unknown";
            var res3 = ctrl.CreateComplaint(body) as ViewResult;
            Assert.IsNotNull(res3);
            Assert.AreEqual(res3.Model, "wrong user");
        }
        public void HomeControllerChangePassword()
        {
            const bool ISAJAX = true;
            var info = new PasswordViewModel()
            {
                NewPassword = "******",
                NewPasswordAgain = "Password2",
                Password = "******"
            };

            var factory = new WorkChannelFactoryMock();
            HomeController ctrl = new HomeController(factory);
            FakeControllerSession.SetFakeControllerContext(ctrl, ISAJAX);

            //Redirect if not logged
            // TODO - maybe we need to remove this
            ctrl.Session["LoggedIn"] = false;
            var res1 = ctrl.ChangePassword(info) as RedirectToRouteResult;
            Assert.IsNotNull(res1);
            Assert.AreEqual(res1.RouteValues["action"], "Login");
            Assert.AreEqual(res1.RouteValues["controller"], "Account");

            //Pass if everything ok
            ctrl.Session["LoggedIn"] = true;
            var res2 = ctrl.ChangePassword(info) as RedirectToRouteResult;
            Assert.IsNotNull(res2);
            Assert.AreEqual(res2.RouteValues["action"], "Index");

            var upd = factory.LastWorkChannel.UsersUpdated;
            Assert.AreEqual(upd.Count, 1);
            Assert.AreEqual(upd[0].Password, ((UserDTO)ctrl.Session["User"]).Password);
            Assert.AreEqual(upd[0].Password, "Password2");

            //Fault when wrong user
            ((UserDTO)ctrl.Session["User"]).Email = "Unknown";
            var res3 = ctrl.ChangePassword(info) as ViewResult;
            Assert.IsNotNull(res3);
            Assert.AreEqual(res3.Model, "wrong user or password");
        }