public void ReturnsAnEmptyListIfNoProfilesExistForAccount()
        {
            const string accountName = "User1";
            var request = new GetProfilesForAccountRequest() { Account = accountName };
            var mockProfileRepo = new Mock<IProfileRepository>();
            mockProfileRepo.Setup(x => x.GetByAccount(accountName)).Returns(new List<Profile>());
            var handler = new GetProfilesForAccountRequestHandle(mockProfileRepo.Object);

            var response = handler.Handle(request);

            Assert.That((object) response.Profiles.Count, Is.EqualTo(0));
        }
        public void CanRetrieveAListOfProfilesAssociatedToAnAccount()
        {
            const string accountName = "User1";
            var request = new GetProfilesForAccountRequest() { Account = accountName };
            var mockProfileRepo = new Mock<IProfileRepository>();
            mockProfileRepo.Setup(x => x.GetByAccount(accountName)).Returns(new List<Profile>()
                { new Profile(), new Profile() });
            var handler = new GetProfilesForAccountRequestHandle(mockProfileRepo.Object);

            var response = handler.Handle(request);

            Assert.That((object) response.Profiles.Count, Is.EqualTo(2));
        }
Esempio n. 3
0
        public ActionResult ChooseProfile()
        {
            var request = new GetProfilesForAccountRequest
                              {
                                  Account = HttpContext.User.Identity.Name
                              };

            var handler = new GetProfilesForAccountRequestHandle(new ProfileRepository());

            var response = handler.Handle(request);

            if (response.Profiles.Count == 0)
                return RedirectToAction("CreateProfile");

            ViewData[ViewDataConstants.Profiles] = response.Profiles;

            var cookie = HttpContext.Request.Cookies[Constants.CookieName] ??
            new HttpCookie(Constants.CookieName) { Expires = DateTime.Now.AddHours(1) };
            cookie.Values[Constants.CurrentProfileCookieField] = response.Profiles[0].ProfileName;

            HttpContext.Response.Cookies.Add(cookie);

            return RedirectToAction("Index", "Home");
        }