public void GoodCustomerIdAndBranch_CallsDeleteOldRecentlyViewedDetail() { // arrange Mock <IRecentlyViewedListHeadersRepository> mockHeadersRepo; Mock <IRecentlyViewedListDetailsRepository> mockDetailsRepo; IRecentlyViewedListLogic testunit = MakeTestObject(out mockHeadersRepo, out mockDetailsRepo); mockHeadersRepo.Setup(h => h.GetRecentlyViewedHeader(It.IsAny <Guid>(), It.Is <UserSelectedContext>(c => c.BranchId == "FUT" && c.CustomerId == "123456"))) .Returns(new RecentlyViewedListHeader { BranchId = "FUT", CustomerNumber = "123456", Id = 1 }); UserSelectedContext testcontext = new UserSelectedContext { BranchId = "FUT", CustomerId = "123456" }; UserProfile fakeUser = new UserProfile(); // act testunit.DeleteAll(fakeUser, testcontext); // assert - Always returns what is setup provided the mock is called mockDetailsRepo.Verify(h => h.DeleteOldRecentlyViewed(It.IsAny <long>(), It.IsAny <int>()), Times.Once(), "Error updating"); }
/// <summary> /// ctor /// </summary> /// <param name="listLogic"></param> /// <param name="profileLogic"></param> /// <param name="logRepo"></param> public RecentItemController(IListLogic listLogic, IUserProfileLogic profileLogic, IRecentlyViewedListLogic recentlyViewedLogic, IRecentlyOrderedListLogic recentlyOrderedLogic, IListService listService, IEventLogRepository logRepo) : base(profileLogic) { _repo = listLogic; _recentlyViewedLogic = recentlyViewedLogic; _recentlyOrderedLogic = recentlyOrderedLogic; _listService = listService; _log = logRepo; }
public void BadCustomerIdAndBranch_CompletesWithoutError() { // arrange IRecentlyViewedListLogic testunit = MakeTestsObject(); UserSelectedContext testcontext = new UserSelectedContext { BranchId = "XXX", CustomerId = "123456" }; UserProfile fakeUser = new UserProfile(); // act testunit.DeleteAll(fakeUser, testcontext); // assert - Always returns what is setup provided the mock is called } // works differently if you want to verify a mock is called; we can't go through autofac
public void AnyCustomerIdAndBranch_CallsSaveDetailEveryTime() { // arrange Mock <IRecentlyViewedListHeadersRepository> mockHeadersRepo; Mock <IRecentlyViewedListDetailsRepository> mockDetailsRepo; IRecentlyViewedListLogic testunit = MakeTestObject(out mockHeadersRepo, out mockDetailsRepo); UserSelectedContext testcontext = new UserSelectedContext { BranchId = "FUT", CustomerId = "123456" }; UserProfile fakeUser = new UserProfile(); string testRecentViewedItemNumber = "111111"; // act testunit.PostRecentView(fakeUser, testcontext, testRecentViewedItemNumber); // assert - Always returns what is setup provided the mock is called mockDetailsRepo.Verify(h => h.Save(It.IsAny <RecentlyViewedListDetail>()), Times.Once(), "Error updating"); }
public void BadBranchId_ReturnsNull() { // arrange IRecentlyViewedListLogic testunit = MakeTestsObject(); UserSelectedContext testcontext = new UserSelectedContext { BranchId = "XXX", CustomerId = "123456" }; UserProfile fakeUser = new UserProfile { UserId = new Guid("dddddddddddddddddddddddddddddddd") }; bool headerOnly = false; // act ListModel results = testunit.ReadList(fakeUser, testcontext, headerOnly); // assert results.Should() .BeNull(); }
public void HeaderWritten_HasTheRightUserId() { // arrange Mock <IRecentlyViewedListHeadersRepository> mockHeadersRepo; Mock <IRecentlyViewedListDetailsRepository> mockDetailsRepo; IRecentlyViewedListLogic testunit = MakeTestObject(out mockHeadersRepo, out mockDetailsRepo); UserSelectedContext testcontext = new UserSelectedContext { BranchId = "FUT", CustomerId = "123456" }; UserProfile fakeUser = new UserProfile { UserId = new Guid("dddddddddddddddddddddddddddddddd") }; string testRecentViewedItemNumber = "111111"; // act testunit.PostRecentView(fakeUser, testcontext, testRecentViewedItemNumber); // assert - Always returns what is setup provided the mock is called mockHeadersRepo.Verify(h => h.Save(It.Is <RecentlyViewedListHeader>(head => head.UserId == new Guid("dddddddddddddddddddddddddddddddd"))), Times.Once(), "Error updating"); }
public void GoodCustomerIdAndBranch_ReturnsExpectedList() { // arrange IRecentlyViewedListLogic testunit = MakeTestsObject(); UserSelectedContext testcontext = new UserSelectedContext { BranchId = "FUT", CustomerId = "123456" }; int expectedListId = 1; UserProfile fakeUser = new UserProfile { UserId = new Guid("dddddddddddddddddddddddddddddddd") }; bool headerOnly = false; // act ListModel results = testunit.ReadList(fakeUser, testcontext, headerOnly); // assert results.ListId .Should() .Be(expectedListId); }