public ActionResult Location(SetupOptionsModel model)
        {
            if (string.IsNullOrEmpty(model.LocationToAdd))
            {
                ModelState.AddModelError("AvailableLocations", "Please choose a location");
                return View("SetupOptions", CreateSetupOptionsModel());
            }

            var profileId = GetProfileFromCookie();
            var request = new AddLocationToProfileRequest
                              {
                                  Location = model.LocationToAdd,
                                  ProfileId = profileId
                              };

            var handler = new AddLocationToProfileRequestHandle(new ProfileRepository(), new LocationRepository());

            var response = handler.Handle(request);

            if (response.Status == ResponseCodes.Success)
            {
                return RedirectToAction("SetupOptions", "Setup");
            }

            var errorMessage = response.Status.GetMessage();
            ModelState.AddModelError("", errorMessage);

            return RedirectToAction("SetupOptions", "Setup");
        }
        public void ReturnsLocationNotFoundStatusIfTheLocationSpecifiedCouldNotBeFound()
        {
            var request = new AddLocationToProfileRequest
                              {
                Location = "Hamsterton"
            };
            CreateMockProfileAndLocationRepos("Moo", request.Location);
            _mockLocationRepo.Setup(x => x.FindByName(request.Location)).Returns(() => null);
            var handler = new AddLocationToProfileRequestHandle(_mockProfileRepo.Object, _mockLocationRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.LocationNotFound));
            Assert.False(_profileWasSavedSuccessfully);
        }
        public void ReturnsLocationAlreadyInProfileIfTheLocationSpecifiedIsAlreadyAttachedToThePRofile()
        {
            const string profileId = "profId";
            var request = new AddLocationToProfileRequest
                              {
                                  Location = "Bend",
                                  ProfileId = profileId
                              };
            _profile = new Profile();
            _profile.Locations.Add(new Location("Bend"));
            CreateMockProfileAndLocationRepos(profileId, request.Location);
            var handler = new AddLocationToProfileRequestHandle(_mockProfileRepo.Object, _mockLocationRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.LocationAlreadyInProfile));
            Assert.That(_profile.Locations.Count, Is.EqualTo(1));
        }
        public void CanAddLocationToProfile()
        {
            const string location = "Bend";
            const string profileId = "123";
            _profile = new Profile
                           {
                               ProfileName = profileId
                           };
            var request = new AddLocationToProfileRequest
                              {
                                  Location = location,
                                  ProfileId = profileId
                              };
            CreateMockProfileAndLocationRepos(profileId, location);
            var handler = new AddLocationToProfileRequestHandle(_mockProfileRepo.Object, _mockLocationRepo.Object);

            var response = handler.Handle(request);

            Assert.That(_profile.Locations.Count, Is.Not.EqualTo(0));
            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
            Assert.True(_profileWasSavedSuccessfully);
        }
        public void ThrowsExceptionIfLocationWasNotSpeicified()
        {
            var request = new AddLocationToProfileRequest
                              {
                                  Location = null
                              };
            CreateMockProfileAndLocationRepos("Moo", null);
            var handler = new AddLocationToProfileRequestHandle(_mockProfileRepo.Object, _mockLocationRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.LocationNotSpecified));
            Assert.False(_profileWasSavedSuccessfully);
        }