public void FindEntity_GenericExceptionCaught_LogsAndRethrowsException() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new DivisionRepository(dbContext); var name = "Division"; A.CallTo(() => dbContext.Divisions.Find(A <string> .Ignored)).Throws <Exception>(); // Act Division result = null; Assert.Throws <Exception>(() => result = repository.FindEntity(name)); // Assert Assert.IsNull(result); }
public void FindEntity_InvalidOperationExceptionCaught_ThrowsObjectNotFoundException() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new DivisionRepository(dbContext); var name = "Division"; A.CallTo(() => dbContext.Divisions.Find(A <string> .Ignored)).Throws <InvalidOperationException>(); // Act Division result = null; Assert.Throws <ObjectNotFoundException>(() => { result = repository.FindEntity(name); }); // Assert Assert.IsNull(result); }
public void FindEntity_HappyPath() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new DivisionRepository(dbContext); var name = "Division"; var division = new Division(); A.CallTo(() => dbContext.Divisions.Find(A <string> .Ignored)).Returns(division); // Act var result = repository.FindEntity(name); // Assert A.CallTo(() => dbContext.Divisions.Find(name)).MustHaveHappenedOnceExactly(); Assert.AreSame(division, result); }
public void FindEntity_EntityNotFoundInDataStore_ThrowsObjectNotFoundException() { // Arrange var dbContext = A.Fake <ProFootballEntities>(); var repository = new DivisionRepository(dbContext); var name = "Division"; Division division = null; A.CallTo(() => dbContext.Divisions.Find(A <string> .Ignored)).Returns(division); // Act Division result = null; Assert.Throws <ObjectNotFoundException>(() => { result = repository.FindEntity(name); }); // Assert A.CallTo(() => dbContext.Divisions.Find(name)).MustHaveHappenedOnceExactly(); Assert.IsNull(result); }