public void MoveStudentToNewTeam_StudentIsNull_ExpectArgumentException() { // arrange var studentRepo = studentRepoMock.Object; var teamRepo = teamRepoMock.Object; var fromTeam = new Team() { Id = 1, Students = new List <Student>() }; var toTeam = new Team() { Id = 2, Students = new List <Student>() }; teamRepo.Add(fromTeam); teamRepo.Add(toTeam); var studentsBeforeTest = new List <Student>(studentRepo.GetAll()); var teamsBeforeTest = new List <Team>(teamRepo.GetAll()); var service = new StudentTeamService(studentRepo, teamRepo); // act + assert var ex = Assert.Throws <ArgumentException>(() => service.MoveStudentToNewTeam(fromTeam, toTeam, null)); Assert.Equal("Student is missing", ex.Message); teamRepoMock.Verify(repo => repo.Update(It.Is <Team>(t => t == fromTeam)), Times.Never); teamRepoMock.Verify(repo => repo.Update(It.Is <Team>(t => t == toTeam)), Times.Never); // verify that repositories contains same objects as before act. Assert.Equal(studentsBeforeTest, studentRepoMock.Object.GetAll()); Assert.Equal(teamsBeforeTest, teamRepoMock.Object.GetAll()); }
public void MoveStudentToNewTeam_LegalMove() { // arrange var studentRepo = studentRepoMock.Object; var teamRepo = teamRepoMock.Object; var s1 = new Student() { Id = 1 }; var s2 = new Student() { Id = 2 }; // all students exists in studentRepo studentRepo.Add(s1); studentRepo.Add(s2); var t1 = new Team() { Id = 1, Students = new List <Student>() { s1, s2 } }; var t2 = new Team() { Id = 2, Students = new List <Student>() { } }; // team t exists in teamRepo teamRepo.Add(t1); teamRepo.Add(t2); var studentsBeforeTest = new List <Student>(studentRepo.GetAll()); var teamsBeforeTest = new List <Team>(teamRepo.GetAll()); var service = new StudentTeamService(studentRepo, teamRepo); // act service.MoveStudentToNewTeam(t1, t2, s2); // assert Assert.True(t1.Students.Count == 1); Assert.Contains(s1, t1.Students); Assert.True(t2.Students.Count == 1); Assert.Contains(s2, t2.Students); teamRepoMock.Verify(repo => repo.Update(It.Is <Team>(t => t == t1)), Times.Once); teamRepoMock.Verify(repo => repo.Update(It.Is <Team>(t => t == t2)), Times.Once); // verify that repositories contains same objects as before act. Assert.Equal(studentsBeforeTest, studentRepoMock.Object.GetAll()); Assert.Equal(teamsBeforeTest, teamRepoMock.Object.GetAll()); }
public void MoveStudentToNewTeam_StudentNotMemberOfFromTeam_ExpectInvalidOperationException() { // arrange var studentRepo = studentRepoMock.Object; var teamRepo = teamRepoMock.Object; // student exists in student repository var student = new Student() { Id = 1 }; studentRepo.Add(student); // both teams exist in team repository // student is not a member of fromTeam var fromTeam = new Team() { Id = 1, Students = new List <Student>() }; var toTeam = new Team() { Id = 2, Students = new List <Student>() }; teamRepo.Add(fromTeam); teamRepo.Add(toTeam); var studentsBeforeTest = new List <Student>(studentRepo.GetAll()); var teamsBeforeTest = new List <Team>(teamRepo.GetAll()); var service = new StudentTeamService(studentRepo, teamRepo); // act + assert var ex = Assert.Throws <InvalidOperationException>(() => service.MoveStudentToNewTeam(fromTeam, toTeam, student)); Assert.Equal("Student is not a member of From Team", ex.Message); teamRepoMock.Verify(repo => repo.Update(It.Is <Team>(t => t == fromTeam)), Times.Never); teamRepoMock.Verify(repo => repo.Update(It.Is <Team>(t => t == toTeam)), Times.Never); // verify that repositories contains same objects as before act. Assert.Equal(studentsBeforeTest, studentRepoMock.Object.GetAll()); Assert.Equal(teamsBeforeTest, teamRepoMock.Object.GetAll()); }
public void MoveStudentToNewTeam_ToTeamIsFull_ExpectInvalidOperationException() { // arrange var studentRepo = studentRepoMock.Object; var teamRepo = teamRepoMock.Object; // students exists in student repository var s1 = new Student() { Id = 1 }; var s2 = new Student() { Id = 2 }; var s3 = new Student() { Id = 3 }; var s4 = new Student() { Id = 4 }; var s5 = new Student() { Id = 5 }; studentRepo.Add(s1); studentRepo.Add(s2); studentRepo.Add(s3); studentRepo.Add(s4); studentRepo.Add(s5); // both teams exist in team repository // student is not a member of fromTeam var fromTeam = new Team() { Id = 1, Students = new List <Student>() { s5 } }; var toTeam = new Team() { Id = 2, Students = new List <Student>() { s1, s2, s3, s4 } }; teamRepo.Add(fromTeam); teamRepo.Add(toTeam); var studentsBeforeTest = new List <Student>(studentRepo.GetAll()); var teamsBeforeTest = new List <Team>(teamRepo.GetAll()); var service = new StudentTeamService(studentRepo, teamRepo); // act + assert var ex = Assert.Throws <InvalidOperationException>(() => service.MoveStudentToNewTeam(fromTeam, toTeam, s5)); Assert.Equal("To Team is full", ex.Message); teamRepoMock.Verify(repo => repo.Update(It.Is <Team>(t => t == fromTeam)), Times.Never); teamRepoMock.Verify(repo => repo.Update(It.Is <Team>(t => t == toTeam)), Times.Never); // verify that repositories contains same objects as before act. Assert.Equal(studentsBeforeTest, studentRepoMock.Object.GetAll()); Assert.Equal(teamsBeforeTest, teamRepoMock.Object.GetAll()); }