public void ThrowsExceptionWhenThereIsNoSportSpecified()
        {
            var request = new AddSportToProfileRequest();
            var handler = new AddSportToProfileRequestHandle(_mockIProfileUpdater.Object, _mockSportRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.SportNotSpecified));
        }
        public void CreatesADefaultSkillLevelIfNoneIsSpecified()
        {
            const string uniqueId = "MyId";
            _request = new AddSportToProfileRequest
                           {
                Sport = "Soccer",
                UniqueId = uniqueId
            };
            _profile = new Profile();
            SetUpMockProfileUpdaterAndSportRepo(uniqueId);
            var handler = new AddSportToProfileRequestHandle(_mockIProfileUpdater.Object, _mockSportRepo.Object);

            handler.Handle(_request);

            _mockIProfileUpdater.Verify(x => x.AddSportToProfile(_profile,
                It.Is<SportWithSkillLevel>(n => n.SkillLevel.Level ==Constants.DefaultSkillLevel)));
        }
        public void CanAddSportToProfileViaUniqueIdOfPerson()
        {
            const int skillLevel = 5;
            const string uniqueId = "MyId";
            _request = new AddSportToProfileRequest
                           {
                               SkillLevel = skillLevel,
                               Sport = "Soccer",
                               UniqueId = uniqueId
                           };
            _profile = new Profile();

            SetUpMockProfileUpdaterAndSportRepo(uniqueId);
            _mockIProfileUpdater.Setup(x => x.AddSportToProfile(It.Is<Profile>(d => d == _profile), It.IsAny<SportWithSkillLevel>())).
                Callback(() => _profileWasSavedSuccessfully = true);

            var handler = new AddSportToProfileRequestHandle(_mockIProfileUpdater.Object, _mockSportRepo.Object);
            var response = handler.Handle(_request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
            Assert.True(_profileWasSavedSuccessfully);
        }
        public void WillNotAddSportIfItAlreadyIsInProfile()
        {
            _profile = TestData.MockProfile1();
            _request = new AddSportToProfileRequest
                           {
                               SkillLevel = 1,
                               Sport = "Soccer",
                               UniqueId = _profile.ProfileName
                           };
            SetUpMockProfileUpdaterAndSportRepo(_profile.ProfileName);
            _mockSportRepo.Setup(x => x.FindByName(_request.Sport)).Returns(new Sport {Name = "Soccer"});
            var handler = new AddSportToProfileRequestHandle(_mockIProfileUpdater.Object, _mockSportRepo.Object);

            var response = handler.Handle(_request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.SportAlreadyPlayed));
        }
Ejemplo n.º 5
0
        public ActionResult Sports(SetupOptionsModel model)
        {
            if (string.IsNullOrEmpty(model.ChosenSport) || string.IsNullOrEmpty(model.ChosenSkillLevel))
            {
                ModelState.AddModelError("AvailableSports", "Please choose a sport AND a skill level");
                return View("SetupOptions", CreateSetupOptionsModel());
            }

            var profile = GetProfileFromCookie();
            var request = new AddSportToProfileRequest
                              {
                                  SkillLevel = int.Parse(model.ChosenSkillLevel),
                                  Sport = model.ChosenSport,
                                  UniqueId = profile
                              };

            var handler = new AddSportToProfileRequestHandle(new ProfileRepository(), new SportRepository());

            var response = handler.Handle(request);

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

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

            return View("SetupOptions", CreateSetupOptionsModel());
        }