public void TestMapDataToDomain()
        {
            Data.Entities.Team team1 = new Data.Entities.Team();
            team1.Teamname = "testteam";
            int gamemode = 1;

            Data.Entities.Rank datrank = new Data.Entities.Rank();
            datrank.Gamemodeid = gamemode;
            datrank.Team       = team1;

            Domain.Rank domrank = Data.Mapper.Map(datrank);

            Assert.AreEqual(domrank.team.teamname, "testteam");
            Assert.AreEqual(domrank.gamemodeid, 1);
        }
        public static Data.Entities.Team Map(Domain.Team dmTeam)
        {
            Data.Entities.Team            deTeam     = new Entities.Team();
            List <Data.Entities.UserTeam> deUserTeam = new List <Entities.UserTeam>();

            if (dmTeam.Userlist.Count > 0 && dmTeam.Userlist.Count == dmTeam.Roles.Count)
            {
                for (int i = 0; i < dmTeam.Userlist.Count; i++)
                {
                    Data.Entities.UserTeam soloUserTeam = new Data.Entities.UserTeam();
                    soloUserTeam.Leader = dmTeam.Roles[i];
                    soloUserTeam.Userid = dmTeam.Userlist[i].id;
                    deUserTeam.Add(soloUserTeam);
                }
            }

            if (dmTeam.id != null)
            {
                deTeam.Id = (int)dmTeam.id;
            }
            deTeam.UserTeam = deUserTeam;
            deTeam.Teamname = dmTeam.teamname;
            return(deTeam);
        }
Exemple #3
0
        public void UpdateTeamTest()
        {
            Data.Entities.HLContext _db      = new Data.Entities.HLContext();
            Data.TeamRepository     test     = new Data.TeamRepository(_db);
            Data.UserRepository     usertest = new Data.UserRepository(_db);

            //preliminary stuff to clean database in case this stuff is already in there
            //first see if the team used in this test is in the DB
            Data.Entities.Team isthisteamhere = _db.Team.Where(o => o.Teamname.Equals("testteamname")).FirstOrDefault();
            if (isthisteamhere != null)
            {
                //obtain the primary key for this team
                int primarykey = isthisteamhere.Id;
                //remove the userteam(s) associated with this team
                IEnumerable <UserTeam> ww = _db.UserTeam.Where(mm => mm.Teamid == primarykey);
                foreach (var item in ww)
                {
                    _db.UserTeam.Remove(item);
                }
                _db.SaveChanges();
                //now we can remove the team
                _db.Team.Remove(isthisteamhere);
                _db.SaveChanges();
            }

            //now we can remove our user1 and 2 if they exist
            Data.Entities.User isthisuserhere = _db.User.Where(p => p.Username.Equals("username1")).FirstOrDefault();
            if (isthisuserhere != null)
            {
                _db.User.Remove(isthisuserhere);
                _db.SaveChanges();
            }
            Data.Entities.User isthisuserhere2 = _db.User.Where(p => p.Username.Equals("username2")).FirstOrDefault();
            if (isthisuserhere2 != null)
            {
                _db.User.Remove(isthisuserhere2);
                _db.SaveChanges();
            }



            bool what;    //random bool to hold data about success of methods.
            bool success; //initialize boolean for asserts

            //first case, we pass the method a faulty team check for null case and count case.
            Domain.Team team = new Domain.Team();
            success = test.UpdateTeam(team);
            Assert.AreEqual(success, false);



            //second test case for we have an empty team in the database and it is updated to contain a team.
            team.teamname = "testteamname";

            Domain.User user = new Domain.User("username1", "password1");

            //need to add user to db and pull it to get a stupid id
            success = usertest.DeleteUser(user);
            usertest.Save();
            //add user to the database;
            success = usertest.AddUser(user);
            usertest.Save();
            if (!success)
            {
                Assert.Fail();
            }
            _db.SaveChanges();

            //obtain the user from the database so it has the userID
            var x = _db.User.Where(a => a.Username.Equals(user.username)).FirstOrDefault();

            Domain.User user1withID = Mapper.Map(x);

            team.Roles.Add(true);
            team.Userlist.Add(user1withID);

            what = test.DeleteTeam(team);
            what = test.AddTeam(team);

            //now I will add another user to the team and see if it updates.
            Domain.User user2 = new Domain.User("username2", "password2");
            usertest.AddUser(user2);
            usertest.Save();
            var xx = _db.User.Where(a => a.Username.Equals(user2.username)).FirstOrDefault();

            Domain.User user2withID = Mapper.Map(xx);
            team.AddMember(user2withID);

            success = test.UpdateTeam(team);
            Assert.AreEqual(success, true);
            //keep database clean and undo the things i put in it
            //first remove the userteams
            //preliminary stuff to clean database in case this stuff is already in there
            //first see if the team used in this test is in the DB
            Data.Entities.Team isthisteamhere3 = _db.Team.Where(o => o.Teamname.Equals("testteamname")).FirstOrDefault();
            if (isthisteamhere3 != null)
            {
                //obtain the primary key for this team
                int primarykey = isthisteamhere3.Id;
                //remove the userteam(s) associated with this team
                IEnumerable <UserTeam> ww = _db.UserTeam.Where(mm => mm.Teamid == primarykey);
                foreach (var item in ww)
                {
                    _db.UserTeam.Remove(item);
                }
                _db.SaveChanges();
                //now we can remove the team
                _db.Team.Remove(isthisteamhere3);
                _db.SaveChanges();
            }

            //now we can remove our user1 and 2 if they exist
            Data.Entities.User isthisuserhere3 = _db.User.Where(p => p.Username.Equals("username1")).FirstOrDefault();
            if (isthisuserhere3 != null)
            {
                _db.User.Remove(isthisuserhere3);
                _db.SaveChanges();
            }
            Data.Entities.User isthisuserhere4 = _db.User.Where(p => p.Username.Equals("username2")).FirstOrDefault();
            if (isthisuserhere4 != null)
            {
                _db.User.Remove(isthisuserhere4);
                _db.SaveChanges();
            }
        }