public void AddTeam_HappyPath() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new TeamRepository(dbContext); var team = new Team(); A.CallTo(() => dbContext.Teams.Add(A <Team> .Ignored)).Returns(team); // Act var result = repository.AddEntity(team); // Assert A.CallTo(() => dbContext.Teams.Add(team)).MustHaveHappenedOnceExactly(); Assert.AreSame(team, result); }
public void AddTeam_ExceptionCaught_LogsAndRethrowsException() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new TeamRepository(dbContext); var team = new Team(); A.CallTo(() => dbContext.Teams.Add(A <Team> .Ignored)).Throws <Exception>(); // Act Team result = null; Assert.Throws <Exception>(() => result = repository.AddEntity(team)); // Assert Assert.IsNull(result); }