コード例 #1
0
            public void OnlyFilteredCampaignsWithGoodCustomer_ReturnsOneResult()
            {
                // arrange
                var repo    = MockAllFilteredyHeaderRepo();
                var logic   = MakeLogic(headerRepo: repo.Object);
                var context = new UserSelectedContext()
                {
                    BranchId   = "FDF",
                    CustomerId = "123456"
                };
                var expected = 1;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                var test = logic.GetAllAvailableCampaigns(context);

                BEKConfiguration.Reset();

                // assert
                test.campaigns
                .Count
                .Should()
                .Be(expected);
            }
コード例 #2
0
        private static ICatalogRepository MakeTestsRepository()
        {
            BEKConfiguration.Reset();
            BEKConfiguration.Add("ElasticSearchURL", "http://localhost/Test");

            ElasticSearchCatalogRepositoryImpl testunit = new ElasticSearchCatalogRepositoryImpl();

            return(testunit);
        }
コード例 #3
0
            public void BadUrlWithItems_ThrowsException()
            {
                // arrange
                var logic        = MakeLogic();
                var uri          = "bad uri";
                var includeItems = true;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                Action getCampaignByUri = () => logic.GetCampaignByUri(uri, includeItems);

                // assert
                getCampaignByUri.Should()
                .Throw <KeyNotFoundException>();

                BEKConfiguration.Reset();
            }
コード例 #4
0
            public void BadIdWithNoItems_ThrowsException()
            {
                // arrange
                var logic        = MakeLogic();
                var id           = 999;
                var includeItems = false;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                Action getCampaign = () => logic.GetCampaign(id, includeItems);

                // assert
                getCampaign.Should()
                .Throw <KeyNotFoundException>();

                BEKConfiguration.Reset();
            }
コード例 #5
0
            public void GoodCallWithoutItems_CallsGetByCampaignTwice()
            {
                // arrange
                var itemRepo     = MockItemRepo();
                var logic        = MakeLogic(itemRepo: itemRepo.Object);
                var includeItems = true;
                var expected     = 3;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                logic.GetAllCampaigns(includeItems);

                BEKConfiguration.Reset();

                // assert
                itemRepo.Verify(r => r.GetByCampaign(It.IsAny <long>()),
                                Times.Exactly(expected));
            }
コード例 #6
0
            public void GoodCallWithItems_CallsHeaderGetAllOnce()
            {
                // arrange
                var headerRepo   = MockHeaderRepo();
                var logic        = MakeLogic(headerRepo: headerRepo.Object);
                var includeItems = true;
                var expected     = 1;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                logic.GetAllCampaigns(includeItems);

                BEKConfiguration.Reset();

                // assert
                headerRepo.Verify(r => r.GetAll(),
                                  Times.Exactly(expected));
            }
コード例 #7
0
            public void WhenGettingInvoiceHeadersForCustomerAndSortingByAmountAscending_ResultingInvoiceNumbersAreInExpectedOrder()
            {
                // 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 = "amount",
                            Order = "asc"
                        }
                    }
                };
                var testAllCustomers = false;
                var expected         = "2,1,3";

                BEKConfiguration.Add(
                    "WebNowUrl",
                    "http://invoice.benekeith.com/webnow/index.jsp?action=filter&amp;username=anonymous&amp;drawer={branch}AR501&amp;tab={customer}&amp;field4={invoice}");

                // act
                var result = testunit.GetInvoiceHeaders(testUser, testContext, testPaging, testAllCustomers);

                BEKConfiguration.Reset();

                // assert
                var invoiceNumbers = string.Join(",", result.PagedResults
                                                 .Results
                                                 .Select(im => im.InvoiceNumber));

                invoiceNumbers.Should()
                .Be(expected);
            }
コード例 #8
0
            public void GoodIdWithItems_CallsItemRepoOnce()
            {
                // arrange
                var itemRepo     = MockItemRepo();
                var logic        = MakeLogic(itemRepo: itemRepo.Object);
                var uri          = "test uri.jpg";
                var includeItems = true;
                var expected     = 1;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                var test = logic.GetCampaignByUri(uri, includeItems);

                BEKConfiguration.Reset();

                // assert
                itemRepo.Verify(r => r.GetByCampaign(It.Is <long>(i => i == 1)),
                                Times.Exactly(expected));
            }
コード例 #9
0
            public void GoodIdNoItems_CallsGetHeaderOnce()
            {
                // arrange
                var headerRepo   = MockHeaderRepo();
                var logic        = MakeLogic(headerRepo: headerRepo.Object);
                var uri          = "test uri.jpg";
                var includeItems = false;
                var expected     = 1;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                var test = logic.GetCampaignByUri(uri, includeItems);

                BEKConfiguration.Reset();

                // assert
                headerRepo.Verify(r => r.GetByUri(It.Is <string>(s => s == uri)),
                                  Times.Exactly(expected));
            }
コード例 #10
0
            public void GoodIdNoItems_DoesNotCallItemRepo()
            {
                // arrange
                var itemRepo     = MockItemRepo();
                var logic        = MakeLogic(itemRepo: itemRepo.Object);
                var id           = 1;
                var includeItems = false;
                var expected     = 0;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                var test = logic.GetCampaign(id, includeItems);

                BEKConfiguration.Reset();

                // assert
                itemRepo.Verify(r => r.GetByCampaign(It.Is <int>(i => i == 1)),
                                Times.Exactly(expected));
            }
コード例 #11
0
            public void GoodIdNoItems_CallsGetHeaderOnce()
            {
                // arrange
                var headerRepo   = MockHeaderRepo();
                var logic        = MakeLogic(headerRepo: headerRepo.Object);
                var id           = 1;
                var includeItems = false;
                var expected     = 1;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                var test = logic.GetCampaign(id, includeItems);

                BEKConfiguration.Reset();

                // assert
                headerRepo.Verify(r => r.GetHeader(It.Is <int>(i => i == 1)),
                                  Times.Exactly(expected));
            }
コード例 #12
0
            public void WhenThereIsJustOneContractChange1case_PublishesMessageWithExpectedItemNumber()
            {
                // arrange
                MockDependents            mockDependents = new MockDependents();
                IContractListChangesLogic testunit       = MakeTestsLogic(false, ref mockDependents);

                BEKConfiguration.Add("RabbitMQNotificationServer", "Test");
                BEKConfiguration.Add("RabbitMQNotificationPublisherUserName", "Test");
                BEKConfiguration.Add("RabbitMQNotificationPublisherUserPassword", "Test");
                BEKConfiguration.Add("RabbitMQNotificationVHost", "Test");
                BEKConfiguration.Add("RabbitMQNotificationExchangeV2", "Test");

                string expected = ">123456<";

                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();
                BEKConfiguration.Reset();

                // assert
                mockDependents.GenericQueueRepository.Verify(m => m.PublishToDirectedExchange(It.Is <string>(s => s.IndexOf(expected) > -1),
                                                                                              It.IsAny <string>(),
                                                                                              It.IsAny <string>(),
                                                                                              It.IsAny <string>(),
                                                                                              It.IsAny <string>(),
                                                                                              It.IsAny <string>(),
                                                                                              It.IsAny <string>()),
                                                             Times.Once,
                                                             "not called");
            }
コード例 #13
0
            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&amp;username=anonymous&amp;drawer={branch}AR501&amp;tab={customer}&amp;field4={invoice}");
                var expected = 3;

                // act
                var result = testunit.GetInvoiceCustomers(testUser, testContext, testPaging, testAllCustomers);

                BEKConfiguration.Reset();

                // assert
                result.customers.First()
                .NumberInvoices
                .Should()
                .Be(expected);
            }
コード例 #14
0
            public void BadCustomer_CallsGetCustomersTwice()
            {
                // arrange
                var repo    = MockCustomerRepo();
                var logic   = MakeLogic(customerRepository: repo.Object);
                var context = new UserSelectedContext()
                {
                    BranchId   = "FDF",
                    CustomerId = "999999"
                };
                var expected = 2;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                var test = logic.GetAllAvailableCampaigns(context);

                BEKConfiguration.Reset();

                // assert
                repo.Verify(r => r.GetAllCustomersByCampaign(It.IsAny <long>()),
                            Times.Exactly(expected));
            }
コード例 #15
0
            public void GoodCustomer_CallsGetAllheadersOnce()
            {
                // arrange
                var repo    = MockHeaderRepo();
                var logic   = MakeLogic(headerRepo: repo.Object);
                var context = new UserSelectedContext()
                {
                    BranchId   = "FDF",
                    CustomerId = "123456"
                };
                var expected = 1;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                var test = logic.GetAllAvailableCampaigns(context);

                BEKConfiguration.Reset();

                // assert
                repo.Verify(r => r.GetAll(),
                            Times.Exactly(expected));
            }
コード例 #16
0
            public void GoodCustomer_ReturnsTwoRecords()
            {
                // arrange
                var logic   = MakeLogic();
                var context = new UserSelectedContext()
                {
                    BranchId   = "FDF",
                    CustomerId = "123456"
                };
                var expected = 2;

                BEKConfiguration.Add("CampaignImagesUrl", "http://test/");

                // act
                var test = logic.GetAllAvailableCampaigns(context);

                BEKConfiguration.Reset();

                // assert
                test.campaigns
                .Count
                .Should()
                .Be(expected);
            }