public async Task FindEntityAsync_EntityFoundInDataStore_ReturnsEntity() { // Arrange var repository = new ConferenceRepository(); var dbContext = A.Fake <ProFootballEntities>(); var name = "Conference"; Conference conference = new Conference(); A.CallTo(() => dbContext.Conferences.FindAsync(A <string> .Ignored)).Returns(conference); // Act var result = await repository.FindEntityAsync(dbContext, name); // Assert A.CallTo(() => dbContext.Conferences.FindAsync(name)).MustHaveHappenedOnceExactly(); Assert.AreSame(conference, result); }
public void FindEntityAsync_InvalidOperationExceptionCaught_ThrowsObjectNotFoundException() { // Arrange var repository = new ConferenceRepository(); var dbContext = A.Fake <ProFootballEntities>(); var name = "Conference"; A.CallTo(() => dbContext.Conferences.FindAsync(A <string> .Ignored)).Throws <InvalidOperationException>(); // Act Conference result = null; Assert.ThrowsAsync <ObjectNotFoundException>(async() => { result = await repository.FindEntityAsync(dbContext, name); }); // Assert Assert.IsNull(result); }
public void FindEntityAsync_EntityNotFoundInDataStore_ThrowsObjectNotFoundException() { // Arrange var repository = new ConferenceRepository(); var dbContext = A.Fake <ProFootballEntities>(); var name = "Conference"; Conference conference = null; A.CallTo(() => dbContext.Conferences.FindAsync(A <string> .Ignored)).Returns(conference); // Act Conference result = null; Assert.ThrowsAsync <ObjectNotFoundException>(async() => { result = await repository.FindEntityAsync(dbContext, name); }); // Assert A.CallTo(() => dbContext.Conferences.FindAsync(name)).MustHaveHappenedOnceExactly(); Assert.IsNull(result); }