Exemplo n.º 1
0
 private void CreateProfileWithDataFromBuilder()
 {
     _profile = new Profile
     {
         ProfileName = ProfileId
     };
     _profile.Locations.Add(Location);
     CreateSportAndSkillLevel();
 }
Exemplo n.º 2
0
 public bool AddSportToProfile(Profile profile, SportWithSkillLevel sport)
 {
     using (var db = _connectionFactory.OpenDbConnection())
     using (var dbCmd = db.CreateCommand())
     {
         var playerSportLink = CreatePlayerSportLink(profile, sport);
         dbCmd.Insert(playerSportLink);
         return true;
     }
 }
Exemplo n.º 3
0
 public bool AddLocationToProfile(Profile profile, Location location)
 {
     using (var db = _connectionFactory.OpenDbConnection())
     using (var dbCmd = db.CreateCommand())
     {
         var playerLocationLink = CreatePlayerLocationLink(profile, location);
         dbCmd.Insert(playerLocationLink);
         return true;
     }
 }
        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 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 WontAddPlayerIfTheyAreAlreadyAFriend()
        {
            var request = new AddPlayerToFriendsRequest() { FriendId = "SomeId", ProfileId = "ProfId" };

            var profile = new Profile();
            var friendProfile = new Profile() {ProfileName = request.FriendId};
            profile.FriendsIds.Add(friendProfile.ProfileName);

            _mockProfileRepo = new Mock<IProfileRepository>();
            _mockProfileRepo.Setup(x => x.GetByProfileId(request.ProfileId)).Returns(profile);
            //_mockProfileRepo.Setup(x => x.GetByProfileId(request.FriendId)).Returns(friendProfile);
            //_mockProfileRepo.Setup(x => x.AddFriendToProfile(profile.ProfileId, friendProfile.ProfileId)).Callback(() => profileWasSaved = true);

            var handler = new AddPlayerToFriendsRequestHandle(_mockProfileRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.AlreadyFriend));
        }
        public void CanAddPlayerToFriends()
        {
            bool profileWasSaved = false;
            var request = new AddPlayerToFriendsRequest() {FriendId = "SomeId", ProfileId = "ProfId"};

            var profile = new Profile();
            var friendProfile = new Profile();

            _mockProfileRepo = new Mock<IProfileRepository>();
            _mockProfileRepo.Setup(x => x.GetByProfileId(request.ProfileId)).Returns(profile);
            _mockProfileRepo.Setup(x => x.GetByProfileId(request.FriendId)).Returns(friendProfile);
            _mockProfileRepo.Setup(x => x.AddFriendToProfile(profile.ProfileName, friendProfile.ProfileName)).Callback(() => profileWasSaved = true);

            var handler = new AddPlayerToFriendsRequestHandle(_mockProfileRepo.Object);

            var response = handler.Handle(request);

            Assert.True(profileWasSaved);
            Assert.That(profile.FriendsIds[0], Is.SameAs(friendProfile.ProfileName));
            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
        }
        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 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 DoesNotFindSelf()
        {
            var request = new SearchForFriendsRequest { ProfileName = Name1, Sport = "", Location = "", MyProfile = "MyProfile" };
            var profile = new Profile {ProfileName = request.MyProfile};
            var friendProfile = new Profile {ProfileName = Name1};
            var listOfProfiles = new List<Profile> {profile, friendProfile};

            var mockProfileRepo = new Mock<IProfileRepository>();
            mockProfileRepo.Setup(x => x.FindAllByName(request.ProfileName)).Returns(listOfProfiles);

            var handler = new SearchForFriendsRequestHandle(mockProfileRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Results.Count, Is.EqualTo(1));
            Assert.That(response.Results[0], Is.SameAs(friendProfile));
        }
Exemplo n.º 11
0
 private PlayerLocationLink CreatePlayerLocationLink(Profile profile, Location location)
 {
     return new PlayerLocationLink
                {
                    PlayerId = profile.ProfileName,
                    Location = location.Name
                };
 }
Exemplo n.º 12
0
        public bool Save(Profile profile)
        {
            using (var db = _connectionFactory.OpenDbConnection())
            using (var dbCmd = db.CreateCommand())
            {
                dbCmd.Insert(profile);
                foreach (var sport in profile.SportsPlayed)
                {
                    dbCmd.Insert(CreatePlayerSportLink(profile, sport));
                }

                foreach (var location in profile.Locations)
                {
                    try
                    {
                        dbCmd.Insert(CreatePlayerLocationLink(profile, location));
                    }
                    catch (SqlException ex)
                    {
                        Trace.WriteLine(ex.Message);
                        return true;
                    }
                }
            }
            return true;
        }
Exemplo n.º 13
0
 public static Profile MockProfile2()
 {
     _profile2 = new Profile
                     {
                        ProfileName = "ProfileTwo",
                        SportsPlayed = { CreateSoccerWithSkillLevel() },
                        Locations = {CreateLocation2()}
                    };
     return _profile2;
 }
Exemplo n.º 14
0
 public static Profile MockProfile3()
 {
     _profile3 = new Profile
                     {
                        ProfileName = "ProfileThree",
                        SportsPlayed = { CreateBasketballWithSkillLevel() },
                        Locations = {CreateLocation3()}
                    };
     return _profile3;
 }
 public void SetUp()
 {
     _profile = new Profile();
 }
Exemplo n.º 16
0
 public static Profile MockProfile1()
 {
     _profile1 = new Profile
                     {
                        ProfileName = "ProfileOne",
                        SportsPlayed = { CreateSoccerWithSkillLevel() },
                        Locations = {CreateLocation1()}
                    };
     return _profile1;
 }
Exemplo n.º 17
0
 private PlayerSportLink CreatePlayerSportLink(Profile profile, SportWithSkillLevel sport)
 {
     return new PlayerSportLink
                {
                    PlayerId = profile.ProfileName,
                    Sport = sport.Name,
                    Skill = sport.SkillLevel.Level
                };
 }
        private PickUpGame CreateGame()
        {
            _data.CreateLocationBend();
            _data.CreateSoccerSport();
            _data.CreateBasketballSport();
            _data.CreateAccount1();
            _profile = _data.CreateProfileForAccount1();

            var game = CreatePickUpGameOnly();
            return game;
        }
Exemplo n.º 19
0
        public Profile CreateProfileForAccount2()
        {
            var profileRepo = new ProfileRepository();

            var profile = new Profile
                              {
                                  AccountName = "*****@*****.**",
                                  ProfileName = Profile2Id,
                                  Locations = new List<Location> { new Location(LocationBendName), new Location(LocationPortland) },
                                  SportsPlayed = new List<SportWithSkillLevel>
                                                     {new SportWithSkillLevel
                                                          {
                                                            Name = SoccerName,
                                                            SkillLevel = new SkillLevel(5)
                                                        },
                                                     new SportWithSkillLevel
                                                          {
                                                            Name = Basketballname,
                                                            SkillLevel = new SkillLevel(5)
                                                        }}
                              };
            profileRepo.Save(profile);
            return profile;
        }
Exemplo n.º 20
0
 private void MapSportsAndLocations(Profile profile, IDbCommand dbCmd)
 {
     profile.SportsPlayed = dbCmd.Select<PlayerSportLink>("PlayerId = {0}", profile.ProfileName)
         .Select(x => new SportWithSkillLevel { Name = x.Sport, SkillLevel = new SkillLevel(x.Skill) }).ToList();
     profile.Locations = dbCmd.Select<PlayerLocationLink>("PlayerId = {0}", profile.ProfileName)
         .Select(x => new Location() { Name = x.Location }).ToList();
 }
Exemplo n.º 21
0
        public void CanSaveProfiles()
        {
            _data.CreateAccount1();
            _data.CreateLocationBend();
            _data.CreateSoccerSport();
            var profile = new Profile
                              {
                                  AccountName = AccountId,
                                  ProfileName = Profile1Id,
                                  Locations = new List<Location> { new Location("Bend") },
                                  SportsPlayed = new List<SportWithSkillLevel>
                                                     { new SportWithSkillLevel
                                                           {
                                                            Name = "Soccer",
                                                            SkillLevel = new SkillLevel(1)
                                                        }
                                                     }
                              };

            var wasSuccessful = _repo.Save(profile);

            var returnedProfiles = _repo.GetByAccount(profile.AccountName);
            Assert.True(wasSuccessful);
            Assert.That(returnedProfiles[0].ProfileName, Is.EqualTo(profile.ProfileName));
            Assert.That(returnedProfiles[0].Locations[0].Name, Is.EqualTo(profile.Locations[0].Name));
            Assert.That(returnedProfiles[0].SportsPlayed[0].Name, Is.EqualTo(profile.SportsPlayed[0].Name));
            Assert.That(returnedProfiles[0].SportsPlayed[0].SkillLevel.Level, Is.EqualTo(profile.SportsPlayed[0].SkillLevel.Level));
        }
Exemplo n.º 22
0
        private void CreateExtraProfiles()
        {
            var profileRepo = new ProfileRepository();

            for (int i = 0; i < ProfileIds.Count; i++)
            {
                var profile = new Profile
                                  {
                                      AccountName = AccountIds[i],
                                      ProfileName = ProfileIds[i],
                                      Locations =
                                          new List<Location> { new Location(LocationBendName), new Location(LocationPortland) },
                                      SportsPlayed = new List<SportWithSkillLevel>
                                                         {
                                                             new SportWithSkillLevel
                                                                 {
                                                                     Name = SoccerName,
                                                                     SkillLevel = new SkillLevel(2)
                                                                 },
                                                             new SportWithSkillLevel
                                                                 {
                                                                     Name = Basketballname,
                                                                     SkillLevel = new SkillLevel(7)
                                                                 },
                                                             new SportWithSkillLevel
                                                                 {
                                                                     Name = FootballName,
                                                                     SkillLevel = new SkillLevel(5)
                                                                 }
                                                         }
                                  };
                profileRepo.Save(profile);
            }
        }
Exemplo n.º 23
0
        public void DoesNotThrowOrAddToLocationsIfLocationDoesNotExist()
        {
            _data.CreateAccount1();
            _data.CreateLocationBend();
            var profile = new Profile
            {
                AccountName = AccountId,
                ProfileName = Profile1Id,
                Locations = new List<Location> { new Location("Bend"), new Location("NonExisten") },
            };

            _repo.Save(profile);

            var returnedProfile = _repo.GetByAccount(profile.AccountName).First();
            Assert.That(returnedProfile.Locations[0].Name, Is.EqualTo(profile.Locations[0].Name));
            Assert.That(returnedProfile.Locations.Count, Is.EqualTo(1));
        }
        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));
        }
Exemplo n.º 25
0
        public Profile CreateProfileForAccount1()
        {
            var profileRepo = new ProfileRepository();

            var profile = new Profile
                              {
                                  AccountName = "*****@*****.**",
                                  ProfileName = Profile1Id,
                                  Locations = new List<Location> { new Location(LocationBendName) },
                                  SportsPlayed = new List<SportWithSkillLevel>
                                                     {new SportWithSkillLevel
                                                            {
                                                                Name = Basketballname,
                                                                SkillLevel = new SkillLevel(3)
                                                            }}
                              };
            profileRepo.Save(profile);
            return profile;
        }