public void WhenExportTypeContractListIsCalledFor_ResultingFieldsContainEachTrue() { // arrange var mockDependents = new MockDependents(); IExportSettingLogic testunit = MakeTestsLogic(true, ref mockDependents); var testGuid = new Guid(); var testExportType = ExportType.List; var testListType = ListType.Contract; var expected = "Each"; // act ExportOptionsModel results = testunit.ReadCustomExportOptions(testGuid, testExportType, testListType); // assert results.Fields .Select(f => f.Field) .ToList() .Contains(expected) .Should() .BeTrue(); }
public void CallWithGoodType_CallsCacheRepositoryRemoveItemTwice() { // arrange var mockDependents = new MockDependents(); ICacheListLogic testunit = MakeTestsLogic(false, ref mockDependents); var testContext = new UserSelectedContext { BranchId = "FUT", CustomerId = "234567" }; var testListType = ListType.Custom; // act testunit.RemoveTypeOfListsCache(testContext, testListType); // assert mockDependents.CacheRepository.Verify(m => m.RemoveItem(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(2), "not called"); }
public void AnyCall_CallsCacheRepositoryGetItem() { // arrange var mockDependents = new MockDependents(); ICacheListLogic testunit = MakeTestsLogic(false, ref mockDependents); var testContext = new UserSelectedContext { BranchId = "FUT", CustomerId = "234567" }; var testtype = ListType.Contract; var testHeaderOnly = false; // act List <ListModel> results = testunit.GetCachedTypedLists(testContext, testtype, testHeaderOnly); // assert mockDependents.CacheRepository.Verify( m => m.GetItem <List <ListModel> >(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once, "not called"); }
public void GoodCustomerIdAndBranch_ReturnsExpectedList() { // arrange MockDependents mockDependents = new MockDependents(); IRemindersListLogic testunit = MakeTestsLogic(true, ref mockDependents); UserSelectedContext testcontext = new UserSelectedContext { BranchId = "FUT", CustomerId = "123456" }; int expectedListId = 1; UserProfile fakeUser = new UserProfile(); bool headerOnly = false; // act ListModel results = testunit.ReadList(fakeUser, testcontext, headerOnly); // assert results.ListId .Should() .Be(expectedListId); }
public void WhenOrderTransmissionIsSuccessful_HasNoExceptions() { // arrange Queue <string> successfulResponseQueue = GetSuccessfulResponseQueue(); MockDependents mockDependents = new MockDependents(); mockDependents.MockOrderSocketConnectionRepository .Setup(m => m.Receive()) .Returns(() => successfulResponseQueue.Dequeue()); IOrderQueueLogic testunit = MakeUnitToBeTested(true, mockDependents); // act string jsonOrderFile = GetMockData("OrderFile.json"); OrderFile order = JsonConvert.DeserializeObject <OrderFile>(jsonOrderFile); Action sendToHost = () => testunit.SendToHost(order); // assert sendToHost.Should().NotThrow(); }
public void GoodOrder_HasSubtotalOnReturnModel() { // arrange double expected = (double)200.00; MockDependents mockDependents = new MockDependents(); IOrderLogic testLogic = MakeTestsLogic(false, ref mockDependents); Guid testGuid = new Guid("00000000-0000-0000-0000-000000000000"); UserSelectedContext testContext = new UserSelectedContext() { BranchId = "FUT", CustomerId = "111111" }; PagingModel testPaging = new PagingModel() { Size = 50, From = 0, Sort = new List <SortInfo>() { new SortInfo() { Field = "createdate", Order = "desc" } }, Filter = null }; // act PagedResults <Order> result = testLogic.GetPagedOrders(testGuid, testContext, testPaging); // assert result.Results .FirstOrDefault() .OrderTotal .Should() .Be(expected); }
public void BadHeaderId_ReturnsNull() { // arrange int headerId = 157; UserSelectedContext customer = new UserSelectedContext { BranchId = "FUT", CustomerId = "123456" }; UserProfile user = new UserProfile { UserId = new Guid("9615ef5f-fa2a-4497-a59f-69f34cbe6921") }; MockDependents mockDependents = new MockDependents(); ICustomListLogic logic = MakeMockLogic(mockDependents); // act ListModel results = logic.GetListModel(user, customer, headerId); // assert results.Should() .BeNull(); }
public void CallingMethod_HitsTheSaveHeaderMethodOnce() { // arrange UserSelectedContext fakeCustomer = new UserSelectedContext(); ListModel fakeList = new ListModel { ListId = 1, Name = "Fake Name" }; UserProfile fakeUser = new UserProfile(); MockDependents mockDependents = new MockDependents(); ICustomListLogic logic = MakeMockLogic(mockDependents); // expect int expected = 1; // act logic.DeleteList(fakeUser, fakeCustomer, fakeList); // assert mockDependents.MockHeaderRepo.Verify(h => h.SaveCustomListHeader(It.IsAny <CustomListHeader>()), Times.Once); }
private static OrderService MakeUnitToBeTested(bool useAutoFac, MockDependents mockDependents) { if (useAutoFac) { ContainerBuilder containerBuilder = GetTestsContainer(); containerBuilder.RegisterType <OrderService>(); // Register mocks RegisterInContainer(ref containerBuilder, mockDependents); // The OrderService does not use the container built here. // It builds a container from a builder it obtains from the DependencyMapFactory. IContainer testcontainer = containerBuilder.Build(); return(testcontainer.Resolve <OrderService>()); } OrderService testunit = new OrderService(); return(testunit); }
public void CallingMethod_HitsTheSaveHeaderMethodOnce() { // arrange bool fakeActive = true; UserSelectedContext fakeCustomer = new UserSelectedContext(); int fakeId = 1; string fakeName = "fake name"; UserProfile fakeUser = new UserProfile(); MockDependents mockDependents = new MockDependents(); ICustomListLogic logic = MakeMockLogic(mockDependents); // expect int expected = 1; // act long results = logic.CreateOrUpdateList(fakeUser, fakeCustomer, fakeId, fakeName, fakeActive); // assert mockDependents.MockHeaderRepo .Verify(h => h.SaveCustomListHeader(It.IsAny <CustomListHeader>()), Times.Once); }
public void WhenGettingInvoiceCustomersWhenForAllCustomersIsTrue_ResultingFirstInvoiceCustomerNumberInvoicesIsThree() { // arrange MockDependents mockDependents = new MockDependents(); IOnlinePaymentsLogic testunit = MakeTestsLogic(useAutoFac: true, mockDependents: ref mockDependents); var testUser = new UserProfile(); var testContext = new UserSelectedContext { BranchId = "XXXXX", CustomerId = "111111" }; var testPaging = new PagingModel() { Sort = new List <SortInfo>() { new SortInfo() { Field = "invoiceamount", Order = "desc" } } }; var testAllCustomers = true; BEKConfiguration.Add( "WebNowUrl", "http://invoice.benekeith.com/webnow/index.jsp?action=filter&username=anonymous&drawer={branch}AR501&tab={customer}&field4={invoice}"); var expected = 3; // act var result = testunit.GetInvoiceCustomers(testUser, testContext, testPaging, testAllCustomers); BEKConfiguration.Reset(); // assert result.customers.First() .NumberInvoices .Should() .Be(expected); }
public void CallWithGoodList_CallsCacheRepositoryRemoveItemOnce() { // arrange var mockDependents = new MockDependents(); ICacheListLogic testunit = MakeTestsLogic(false, ref mockDependents); var testList = new ListModel { BranchId = "FUT", CustomerNumber = "123456", Type = ListType.Contract, ListId = 5 }; // act testunit.RemoveSpecificCachedList(testList); // assert mockDependents.CacheRepository.Verify(m => m.RemoveItem(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once, "not called"); }
public void NewHeader_ReturnsTheNextAvailableHeaderId() { // arrange bool fakeActive = true; UserSelectedContext fakeCustomer = new UserSelectedContext(); int fakeId = 0; string fakeName = "fake name"; UserProfile fakeUser = new UserProfile(); MockDependents mockDependents = new MockDependents(); ICustomListLogic logic = MakeMockLogic(mockDependents); // expect int expected = 1; // act long results = logic.CreateOrUpdateList(fakeUser, fakeCustomer, fakeId, fakeName, fakeActive); // assert results.Should() .Be(expected); }
private static IOrderQueueLogic MakeUnitToBeTested(bool useAutoFac, MockDependents mockDependents) { if (useAutoFac) { ContainerBuilder cb = GetTestsContainer(); // Register mocks RegisterInContainer(ref cb, mockDependents); IContainer testcontainer = cb.Build(); return(testcontainer.Resolve <IOrderQueueLogic>()); } OrderQueueLogicImpl testunit = new OrderQueueLogicImpl( mockDependents.MockEventLogRepository.Object, mockDependents.MockGenericQueueRepository.Object, mockDependents.MockOrderSocketConnectionRepository.Object, mockDependents.MockSpecialOrderRepository.Object); return(testunit); }
public static void RegisterInContainer(ref ContainerBuilder cb, MockDependents mockDependents) { cb.RegisterInstance(mockDependents.MockOrderHistoryHeaderRepository.Object) .As <IOrderHistoryHeaderRepsitory>(); cb.RegisterInstance(mockDependents.MockPurchaseOrderRepository.Object) .As <IPurchaseOrderRepository>(); cb.RegisterInstance(mockDependents.MockKPayInvoiceRepository.Object) .As <IKPayInvoiceRepository>(); cb.RegisterInstance(mockDependents.MockCatalogLogic.Object) .As <ICatalogLogic>(); cb.RegisterInstance(mockDependents.MockOrderHistoryDetailRepository.Object) .As <IOrderHistoryDetailRepository>(); cb.RegisterInstance(mockDependents.MockUnitOfWork.Object) .As <IUnitOfWork>(); cb.RegisterInstance(mockDependents.MockEventLogRepository.Object) .As <IEventLogRepository>(); cb.RegisterInstance(mockDependents.MockGenericQueueRepository.Object) .As <IGenericQueueRepository>(); cb.RegisterInstance(mockDependents.MockOrderConversionLogic.Object) .As <IOrderConversionLogic>(); cb.RegisterInstance(mockDependents.MockCustomerRepository.Object) .As <ICustomerRepository>(); cb.RegisterInstance(mockDependents.MockSocketListenerRepository.Object) .As <ISocketListenerRepository>(); cb.RegisterInstance(mockDependents.MockGenericSubscriptionQueueRepository.Object) .As <IGenericSubscriptionQueueRepository>(); }
public void CallWith2ListsInCollection_CallsCacheRepositoryRemoveItem10Times() { // arrange var mockDependents = new MockDependents(); ICacheListLogic testunit = MakeTestsLogic(false, ref mockDependents); var testContext = new UserSelectedContext { BranchId = "FUT", CustomerId = "234567" }; var fakeUser = new UserProfile(); var testLists = new List <ListModel> { new ListModel { BranchId = "FUT", CustomerNumber = "123456", Type = ListType.Contract, ListId = 5 }, new ListModel { BranchId = "FUT", CustomerNumber = "123456", Type = ListType.Favorite, ListId = 5 } }; // act testunit.ClearCustomersListCaches(fakeUser, testContext.CustomerId, testContext.BranchId, testLists); // assert mockDependents.CacheRepository.Verify(m => m.RemoveItem(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(10), "not called"); }
public void GoodHeaderIdWithoutItems_ReturnsExpectedListModel() { // arrange int headerId = 1; UserSelectedContext userSelectedContext = new UserSelectedContext { BranchId = "FUT", CustomerId = "123456" }; MockDependents mockDependents = new MockDependents(); ICustomListLogic logic = MakeMockLogic(mockDependents); // expect int expected = 1; // act ListModel result = logic.ReadList(headerId, userSelectedContext, true); // assert result.ListId .Should() .Be(expected); }
public void AnyCall_CallsCacheRepositoryAddItem() { // arrange var mockDependents = new MockDependents(); ICacheListLogic testunit = MakeTestsLogic(false, ref mockDependents); var testContext = new UserSelectedContext { BranchId = "FUT", CustomerId = "234567" }; var lists = new List <string>(); // act testunit.AddCachedLabels(testContext, lists); // assert mockDependents.CacheRepository.Verify(m => m.AddItem(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TimeSpan>(), It.IsAny <List <string> >()), Times.Exactly(2), "not called"); }
public void BadCustomerIdWithDetails_ReturnsListWithNoHeaders() { // arrange UserSelectedContext customer = new UserSelectedContext { BranchId = "FUT", CustomerId = "999999" }; UserProfile user = new UserProfile(); MockDependents mockDependents = new MockDependents(); ICustomListLogic logic = MakeMockLogic(mockDependents); // expect int expected = 0; // act List <ListModel> results = logic.ReadLists(user, customer, false); // assert results.Count .Should() .Be(expected); }
public void CustomerWithNoSharedList_DoesNotSeeList() { // arrange UserSelectedContext customer = new UserSelectedContext { BranchId = "FUT", CustomerId = "222222" }; UserProfile user = new UserProfile(); MockDependents mockDependents = new MockDependents(); ICustomListLogic logic = MakeMockLogic(mockDependents); // expect int expected = 0; // act List <ListModel> results = logic.ReadLists(user, customer, false); // assert results.Count .Should() .Be(expected); }
public void GoodCustomerWithoutDetails_ReturnsExpectedCountOfTwo() { // arrange UserSelectedContext customer = new UserSelectedContext { BranchId = "FUT", CustomerId = "123456" }; UserProfile user = new UserProfile(); MockDependents mockDependents = new MockDependents(); ICustomListLogic logic = MakeMockLogic(mockDependents); // expect int expected = 2; // act List <ListModel> results = logic.ReadLists(user, customer, true); // assert results.Count .Should() .Be(expected); }
public void StreamContainingRawOrderHistory_IsSentToParseMainframeFile() { // arrange MockDependents mockDependents = new MockDependents(); OrderService testunit = MakeUnitToBeTested(true, mockDependents); // act object state = null; testunit.ProcessOrderUpdatesTick(state); // assert // The OrderService does not use the mocks verified here. // The container where the mocked instances are registered is replaced by the OrderService // The OrderService builds a container from a builder it obtains from the DependencyMapFactory. //mockDependents.MockOrderHistoryLogic // .Verify(m => m.ParseMainframeFile(It.IsAny<StreamReader>()), Times.Once, "not called."); //mockDependents.MockGenericQueueRepository // .Verify(m => m.BulkPublishToQueue(It.IsAny<List<string>>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once, "not called."); }
private static IRemindersListLogic MakeTestsLogic(bool useAutoFac, ref MockDependents mockDependents) { if (useAutoFac) { ContainerBuilder cb = GetTestsContainer(); // Register mocks cb.RegisterInstance(MakeMockHeaderRepo()) .As <IRemindersListHeadersRepository>(); cb.RegisterInstance(MakeMockDetailsRepo()) .As <IRemindersListDetailsRepository>(); IContainer testcontainer = cb.Build(); return(testcontainer.Resolve <IRemindersListLogic>()); } mockDependents = new MockDependents(); mockDependents.headersRepository = new Mock <IRemindersListHeadersRepository>(); mockDependents.detailsRepository = new Mock <IRemindersListDetailsRepository>(); ReminderItemsListLogicImpl testunit = new ReminderItemsListLogicImpl(mockDependents.headersRepository.Object, mockDependents.detailsRepository.Object); return(testunit); }
public void WhenPortIsInUse_HasNoException() { // arrange MockDependents mockDependents = new MockDependents(); ISocketListenerRepository testunit = MakeUnitToBeTested(true, mockDependents); var slowClosinglistener = StartListener(Configuration.MainframeConfirmationListeningPort); // starts the port in use condition if (slowClosinglistener.IsBound == false) { throw new Exception("Test logic failure: failed to start contending listener."); } Task.Run(() => StopListenerAfterDelay(slowClosinglistener, 30000)); // keep the port in use condition // act Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Action bindSocketToPort = () => testunit.BindSocketToPort(listener, Configuration.MainframeConfirmationListeningPort); // assert bindSocketToPort.Should().NotThrow(); }
private static IDivisionLogic MakeTestsLogic(bool useAutoFac, ref MockDependents mockDependents) { if (useAutoFac) { ContainerBuilder cb = GetTestsContainer(); // Register mocks MockDependents.RegisterInContainer(ref cb); var testcontainer = cb.Build(); return(testcontainer.Resolve <IDivisionLogic>()); } else { mockDependents = new MockDependents(); mockDependents.DivisionRepository = MockDependents.MakeDivisionRepositoryMock(); mockDependents.BranchSupportRepository = MockDependents.MakeBranchSupportRepositoryMock(); var testunit = new DivisionLogicImpl(mockDependents.DivisionRepository.Object, mockDependents.BranchSupportRepository.Object); return(testunit); } }
public void AnyCall_CallsCacheRepositoryAddItem() { // arrange var mockDependents = new MockDependents(); ICacheListLogic testunit = MakeTestsLogic(false, ref mockDependents); var testContext = new UserSelectedContext { BranchId = "FUT", CustomerId = "234567" }; var testtype = ListType.Contract; var list = new ListModel(); // act testunit.AddCachedSpecificList(testContext, testtype, 5, list); // assert mockDependents.CacheRepository.Verify(m => m.AddItem(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <TimeSpan>(), It.IsAny <ListModel>()), Times.Once, "not called"); }
private static IConfirmationLogic MakeUnitToBeTested(bool useAutoFac, MockDependents mockDependents) { if (useAutoFac) { ContainerBuilder cb = GetTestsContainer(); // Register mocks RegisterInContainer(ref cb, mockDependents); IContainer testcontainer = cb.Build(); return(testcontainer.Resolve <IConfirmationLogic>()); } ConfirmationLogicImpl testunit = new ConfirmationLogicImpl( mockDependents.MockEventLogRepository.Object, mockDependents.MockSocketListenerRepository.Object, mockDependents.MockGenericQueueRepository.Object, mockDependents.MockOrderConversionLogic.Object, mockDependents.MockUnitOfWork.Object, mockDependents.MockGenericSubscriptionQueueRepository.Object); return(testunit); }
public void WhenThereIsJustOneContractChange_CallsForMessageTemplateLogicBuildHeader() { // arrange MockDependents mockDependents = new MockDependents(); IContractListChangesLogic testunit = MakeTestsLogic(false, ref mockDependents); mockDependents.ContractChangesRepository.SetupSequence(f => f.ReadNextSet()) .Returns(new List <ContractChange> { new ContractChange { CustomerNumber = "123456", BranchId = "FUT", CatalogId = "FUT", ItemNumber = "123456", Status = "Added" } }) .Returns(null); // act testunit.ProcessContractChanges(); // assert mockDependents.MessageTemplateLogic.Verify(m => m.BuildHeader(It.IsAny <string>(), It.IsAny <Customer>()), Times.Once, "not called"); }
public void WhenThereIsJustOneContractChange_CallsContractChangesRepositoryReadNextSetTwice() { // arrange MockDependents mockDependents = new MockDependents(); IContractListChangesLogic testunit = MakeTestsLogic(false, ref mockDependents); mockDependents.ContractChangesRepository.SetupSequence(f => f.ReadNextSet()) .Returns(new List <ContractChange> { new ContractChange { CustomerNumber = "123456", BranchId = "FUT", CatalogId = "FUT", ItemNumber = "123456", Status = "Added" } }) .Returns(null); // act testunit.ProcessContractChanges(); // assert mockDependents.ContractChangesRepository.Verify(m => m.ReadNextSet(), Times.Exactly(2), "not called"); }
public void WhenGoodBranchAndGoodInvoiceYieldGoodOrderWithItemInCatalog_ResultingDetailIsExpected() { // arrange MockDependents mockDependents = new MockDependents(); IOrderLogic testunit = MakeTestsLogic(false, ref mockDependents); mockDependents.ICatalogLogic.Setup(m => m.GetProductsByIds("FUT", new List <string> { "111111" })) .Returns(new ProductsReturn { Products = new List <Product> { new Product { ItemNumber = "111111", Name = "Fake Name", BrandExtendedDescription = "Fake Brand", ItemClass = "Fake Class", Size = "Fake Size", Pack = "2" } } }); string testBranch = "FUT"; string testInvoice = "1111111"; string expected = "Fake Name / 111111 / Fake Brand / Fake Class / 2 / Fake Size"; // act Order result = testunit.GetOrder(testBranch, testInvoice); // assert result.Items .First() .Detail .Should() .Be(expected); }