public void UpdateHistoryModel_ShouldThrow() { var historyElement = new HistoryModel() { Id = 1, UserId = 10, TargetId = 11, Status = StatusConstants.TargetNotHuntedHistory }; var fakeHistoryList = new List <HistoryModel>() { historyElement }.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.UpdateHistoryModel(500, 300), StorageErrorMessages.UserDoesNotExistError); }
public void UpdateHistoryModel_ShouldReturnExpected() { //Arrange var expectedUserId = 1; var expectedTargetId = 2; var expectedStatus = StatusConstants.TargetHuntedHistory; var expectedElement = new HistoryModel() { Id = 1, UserId = expectedUserId, TargetId = expectedTargetId, Status = StatusConstants.TargetNotHuntedHistory }; var fakeHistoryList = new List <HistoryModel>() { expectedElement }.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.UpdateHistoryModel(expectedUserId, expectedTargetId); //Assert A.CallTo(() => fakeDbContextGeneration.BuildDatabaseContext()).MustHaveHappened(); A.CallTo(() => fakeDbContext.SaveChanges()).MustHaveHappened(); result.Id.ShouldBe(1); result.UserId.ShouldBe(expectedUserId); result.TargetId.ShouldBe(expectedTargetId); result.Status.ShouldBe(expectedStatus); }