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