public void AddWeekCount() { // Arrange var repository = new WeekCountRepository(); var dbContext = A.Fake <ProFootballEntities>(); var weekCount = new WeekCount { SeasonID = 1 }; A.CallTo(() => dbContext.WeekCounts.Add(A <WeekCount> .Ignored)).Returns(weekCount); // Act var result = repository.AddEntity(dbContext, weekCount); // Assert A.CallTo(() => dbContext.WeekCounts.Add(weekCount)).MustHaveHappenedOnceExactly(); Assert.AreSame(weekCount, result); }
public void FindEntityAsync_InvalidOperationExceptionCaught_ThrowsObjectNotFoundException() { // Arrange var repository = new WeekCountRepository(); var dbContext = A.Fake <ProFootballEntities>(); var seasonID = 2018; A.CallTo(() => dbContext.WeekCounts.FindAsync(A <int> .Ignored)).Throws <InvalidOperationException>(); // Act WeekCount result = null; Assert.ThrowsAsync <ObjectNotFoundException>(async() => { result = await repository.FindEntityAsync(dbContext, seasonID); }); // Assert Assert.IsNull(result); }
public void FindEntity_EntityNotFoundInDataStore_ThrowsObjectNotFoundException() { // Arrange var repository = new WeekCountRepository(); var dbContext = A.Fake <ProFootballEntities>(); var seasonID = 2018; WeekCount weekCount = null; A.CallTo(() => dbContext.WeekCounts.Find(A <int> .Ignored)).Returns(weekCount); // Act WeekCount result = null; Assert.Throws <ObjectNotFoundException>(() => { result = repository.FindEntity(dbContext, seasonID); }); // Assert A.CallTo(() => dbContext.WeekCounts.Find(seasonID)).MustHaveHappenedOnceExactly(); Assert.IsNull(result); }