public void GetHistoryByUserId_ShouldThrow() { //Arrange var expectedUserId = 1; var expectedTargetId = 2; var expectedStatus = StatusConstants.TargetHuntedHistory; var fakeHistoryList = new List <HistoryModel>() { new HistoryModel() { UserId = expectedUserId, TargetId = expectedTargetId, Status = expectedStatus } }.AsQueryable(); var fakeDbSetHistoryElements = UnitTestsUtil.SetupFakeDbSet(fakeHistoryList.AsQueryable()); var fakeDbContext = A.Fake <DatabaseContext>(); A.CallTo(() => fakeDbContext.History).Returns(fakeDbSetHistoryElements); var fakeDbContextGeneration = A.Fake <IDatabaseContextGeneration>(); A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).Returns(fakeDbContext); var historyModelHelper = new HistoryModelHelper(fakeDbContextGeneration); //Act and assert Assert.Throws <ManagerException>(() => historyModelHelper.GetHistoryByUserId(500), StorageErrorMessages.HistoryElementNotFoundError); }
public void GetHistoryByUserId_ShouldReturnExpected() { //Arrange var expectedUserId = 1; var expectedTargetId = 2; var expectedStatus = StatusConstants.TargetHuntedHistory; var fakeHistoryList = new List <HistoryModel>() { new HistoryModel() { UserId = expectedUserId, TargetId = expectedTargetId, Status = expectedStatus } }.AsQueryable(); var fakeDbSetHistoryElements = UnitTestsUtil.SetupFakeDbSet(fakeHistoryList.AsQueryable()); var fakeDbContext = A.Fake <DatabaseContext>(); A.CallTo(() => fakeDbContext.History).Returns(fakeDbSetHistoryElements); var fakeDbContextGeneration = A.Fake <IDatabaseContextGeneration>(); A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).Returns(fakeDbContext); var historyModelHelper = new HistoryModelHelper(fakeDbContextGeneration); //Act var result = historyModelHelper.GetHistoryByUserId(expectedUserId); //Assert A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).MustHaveHappened(); result.ElementAt(0).UserId.ShouldBe(expectedUserId); result.ElementAt(0).TargetId.ShouldBe(expectedTargetId); result.ElementAt(0).Status.ShouldBe(expectedStatus); }