public void teamuserstest() { Data.Entities.HLContext _db = new Data.Entities.HLContext(); Data.UserRepository test = new Data.UserRepository(_db); Data.TeamRepository test2 = new Data.TeamRepository(_db); string username = "******"; string password = "******"; Domain.User user1 = new Domain.User(); user1.UserFill(username, password); string username2 = "Akash"; string password2 = "other"; Domain.User user2 = new Domain.User(); user2.UserFill(username2, password2); bool actual1 = false; bool actual2 = false; bool expected = true; test.AddUser(user1); test.AddUser(user2); test.Save(); var user1inteam2 = test.GetUserByUsername(username); var user2inteam2 = test.GetUserByUsername(username2); List <Domain.User> usersinteam1 = new List <Domain.User>(); usersinteam1.Add(user1inteam2); usersinteam1.Add(user2inteam2); bool user1role = true; bool user2role = false; List <Boolean> team1roleslist = new List <Boolean>(); team1roleslist.Add(user1role); team1roleslist.Add(user2role); Domain.Team team1 = new Domain.Team(usersinteam1, team1roleslist); team1.teamname = "Team1"; test2.AddTeam(team1); _db.SaveChanges(); var team1got = test2.GetByTeamName("Team1"); Assert.AreEqual(team1got.teamname, "Team1"); _db.SaveChanges(); var usersinteamlist = test.TeamUsers(team1.teamname); foreach (var userinteamlist in usersinteamlist) { if (userinteamlist.username == username) { actual1 = true; } if (userinteamlist.username == username2) { actual2 = true; } } Assert.AreEqual(expected, actual1); Assert.AreEqual(expected, actual2); test.DeleteUser(user1inteam2); test.DeleteUser(user2inteam2); test2.DeleteTeam(team1got); test.Save(); _db.SaveChanges(); }
public void AddAndRemoveTeamTest() { Data.Entities.HLContext _db = new Data.Entities.HLContext(); Data.TeamRepository test = new Data.TeamRepository(_db); Data.UserRepository usertest = new Data.UserRepository(_db); bool success; //variable to determine if a team was added or removed successfully. Domain.Team x = new Domain.Team(); x.teamname = "XXstarstrikersXX1113452435x4"; success = test.DeleteTeam(x); _db.SaveChanges(); success = test.AddTeam(x); _db.SaveChanges(); //assert that the team was added to the database Assert.AreEqual(success, true); success = test.AddTeam(x); _db.SaveChanges(); //assert that the team was not added to the database because it already exists Assert.AreEqual(success, false); //assert that the team was successfuly deleted from the database success = test.DeleteTeam(x); _db.SaveChanges(); Assert.AreEqual(success, true); //assert that the team was not deleted from the database because it did not exist success = test.DeleteTeam(x); _db.SaveChanges(); Assert.AreEqual(success, false); //assert that the propery userteam table was added to the database Domain.User anewuser = new Domain.User("newuser89", "newpassword89"); //delete the user from DB incase it exist success = usertest.DeleteUser(anewuser); if (success) { usertest.Save(); } //add the user to the DB success = usertest.AddUser(anewuser); if (success) { usertest.Save(); } //pull the user from the database Domain.User anewuserwithID = usertest.GetUserByUsername("newuser89"); //add the user to the team x.AddMember(anewuserwithID); //add the team to the DB success = test.DeleteTeam(x); _db.SaveChanges(); success = test.AddTeam(x); _db.SaveChanges(); //now check that a usertable was created properly for the team Data.Entities.UserTeam userteam = _db.UserTeam.Where(jj => jj.Userid == anewuserwithID.id).FirstOrDefault(); Assert.AreEqual(userteam.Userid, anewuserwithID.id); //now remove the team from the db success = test.DeleteTeam(x); Data.Entities.UserTeam deleted = _db.UserTeam.Where(jj => jj.Userid == anewuserwithID.id).FirstOrDefault(); //check that the userteam was deleted Assert.AreEqual(deleted, null); //delete the user from the DB to keep it clean usertest.DeleteUser(anewuserwithID); usertest.Save(); }