public void AddTeams() { // Arrange var repository = new TeamRepository(); var dbContext = A.Fake <ProFootballEntities>(); var teams = new List <Team>(); for (int i = 1; i <= 3; i++) { var team = new Team { Name = "Team " + i }; teams.Add(team); } A.CallTo(() => dbContext.Teams.AddRange(A <IEnumerable <Team> > .Ignored)).Returns(teams); // Act var result = repository.AddEntities(dbContext, teams); // Assert A.CallTo(() => dbContext.Teams.AddRange(teams)).MustHaveHappenedOnceExactly(); Assert.AreSame(teams, result); }
public void AddTeams_HappyPath() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new TeamRepository(dbContext); var teams = new List <Team>(); A.CallTo(() => dbContext.Teams.AddRange(A <IEnumerable <Team> > .Ignored)).Returns(teams); // Act var result = repository.AddEntities(teams); // Assert A.CallTo(() => dbContext.Teams.AddRange(teams)).MustHaveHappenedOnceExactly(); Assert.AreSame(teams, result); }
public void AddTeams_ExceptionCaught_LogsAndRethrowsException() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new TeamRepository(dbContext); var teams = new List <Team>(); A.CallTo(() => dbContext.Teams.AddRange(A <IEnumerable <Team> > .Ignored)).Throws <Exception>(); // Act IEnumerable <Team> result = null; Assert.Throws <Exception>(() => result = repository.AddEntities(teams)); // Assert Assert.IsNull(result); }