Esempio n. 1
0
        public void CheckThirdParty_WhenExecute_ThenGetCompletedBatches()
        {
            queues.Add(GenerateVoucher());

            ExpectContextToCreateTransaction();
            ExpectContextToReturnQueues(queues);
            ExpectContextToReturnVouchers(vouchers);
            ExpectToNotDelete();

            var sut = CreatePollingJob();

            sut.Execute(null);

            dipsDbContext.Verify(x => x.Queues);
        }
Esempio n. 2
0
        public void GivenBadVoucher_WhenExecute_ThenPublishMappedVoucherStatus()
        {
            queues.Add(new DipsQueue
            {
                ResponseCompleted = false,
                S_BATCH           = "xxx",
                S_LOCATION        = "ExpertBalanceDone",
                S_LOCK            = "0",
                S_SDATE           = "01/01/15",
                S_STIME           = "12:12:12",
                CorrelationId     = "yyy",
                S_JOB_ID          = "58300013",
                RoutingKey        = "123456"
            });

            vouchers.Add(new DipsNabChq
            {
                S_BATCH                    = "xxx",
                S_TRACE                    = "zzz",
                S_STATUS1                  = "1008",
                micr_unproc_flag           = "0",
                micr_suspect_fraud_flag    = "0",
                manual_repair              = "0",
                doc_type                   = "CRT",
                processing_state           = "SA",
                captureBSB                 = "085384",
                doc_ref_num                = "zzz",
                tpcRequired                = "Y",
                tpcResult                  = "F",
                fxa_unencoded_ECD_return   = "1",
                tpcMixedDepRet             = "1",
                fxa_tpc_suspense_pool_flag = "1",
                highValueFlag              = "1"
            });

            ExpectContextToCreateTransaction();
            ExpectContextToReturnQueues(queues);
            ExpectContextToReturnVouchers(vouchers);
            //ExpectExchangeToPublish();

            var sut = CreatePollingJob();

            sut.Execute(null);

            exchangePublisher.Verify(x => x.PublishAsync(
                                         It.IsAny <CorrectBatchTransactionResponse>(),
                                         "yyy", "123456"));
        }
Esempio n. 3
0
        public void CanRetrievePollByPollId()
        {
            // Arrange
            Guid pollId      = Guid.NewGuid();
            Poll createdPoll = new Poll {
                UUID = pollId
            };

            _dummyPolls.Add(createdPoll);

            // Act
            Poll retrievedPoll = _controller.PollByPollId(pollId, _mockContext);

            // Assert
            Assert.AreEqual(createdPoll, retrievedPoll);
        }
Esempio n. 4
0
        public void ReturnCorrectNumberOfPages_WhenThereIsAQueryPresentAndAMatchInItemName(int itemsCount, int expectedPagesCount)
        {
            // Arrange
            var contextMock     = new Mock <ITravelGuideContext>();
            var userServiceMock = new Mock <IUserService>();
            var factoryMock     = new Mock <IRequestFactory>();

            var requestsMock = new InMemoryDbSet <Request>(true);

            for (int i = 0; i < itemsCount; i++)
            {
                requestsMock.Add(new Request()
                {
                    StoreItem = new StoreItem()
                    {
                        ItemName = "ass"
                    }, User = new User()
                    {
                        UserName = "******"
                    }, FirstName = "xxx", LastName = "svv", CreatedOn = DateTime.Now.AddSeconds(1)
                });
            }

            contextMock.Setup(x => x.Requests).Returns(requestsMock);
            var service = new RequestService(contextMock.Object, userServiceMock.Object, factoryMock.Object);

            string query    = "A";
            var    pageSize = 3;

            // Act
            var pagesCount = service.GetTotalPagesCount(query, pageSize);

            // Assert
            Assert.AreEqual(expectedPagesCount, pagesCount);
        }
        public void ClearingVoteGeneratesRemoveVoteMetric()
        {
            // Arrange
            Guid tokenGuid    = Guid.NewGuid();
            var  existingVote = new Vote()
            {
                Choice = new Choice()
                {
                    Id = 1
                }, Poll = new Poll()
                {
                    UUID = _mainUUID
                }, Ballot = new Ballot()
                {
                    TokenGuid = tokenGuid
                }
            };

            _dummyVotes.Add(existingVote);
            var ballotRequest = new BallotRequestModel();

            // Act
            _controller.Put(_mainUUID, tokenGuid, ballotRequest);

            // Assert
            _mockMetricHandler.Verify(m => m.HandleVoteDeletedEvent(existingVote, _mainUUID), Times.Once());
        }
        public void ReturnCorrectNumberOfPages_WhenNoRequestUserIdIsMatching(int itemsCount, int expectedPagesCount)
        {
            // Arrange
            var contextMock     = new Mock <ITravelGuideContext>();
            var userServiceMock = new Mock <IUserService>();
            var factoryMock     = new Mock <IRequestFactory>();

            var userId = "userId";

            var requestsMock = new InMemoryDbSet <Request>(true);

            for (int i = 0; i < itemsCount; i++)
            {
                requestsMock.Add(new Request());
            }

            contextMock.Setup(x => x.Requests).Returns(requestsMock);
            var service = new RequestService(contextMock.Object, userServiceMock.Object, factoryMock.Object);

            // Act
            var pagesCount = service.GetRequestsPagesCountForUser(userId, 3);

            // Assert
            Assert.AreEqual(expectedPagesCount, pagesCount);
        }
Esempio n. 7
0
        public void GetVouchersInformation_WhenExecute_ThenSaveBatchToDb_AndSaveCommit()
        {
            dipsRequests.Add(GenerateDipsRequest());

            ExpectContextToCreateTransaction();
            ExpectContextToReturnQueues(queues);
            ExpectContextToReturnDipsRequests(dipsRequests);
            ExpectToNotDelete();

            var sut = CreatePollingJob();

            sut.Execute(null);

            dipsDbContext.Verify(x => x.SaveChanges());
            transaction.Verify(x => x.Commit());
        }
Esempio n. 8
0
        public PersonControllerTests()
        {
            _persons   = new InMemoryDbSet <Person>();
            _interests = new InMemoryDbSet <PersonInterest>();
            _images    = new InMemoryDbSet <PersonImage>();

            for (int i = 1; i < 31; i++)
            {
                var newPerson = new Person
                {
                    Id          = i,
                    DateOfBirth = new DateTime(1990, 1, i),
                    FirstName   = $"First{i}",
                    LastName    = $"last{i}",
                    Image       = new PersonImage {
                        PersonId = i, ImageBase64 = i.ToString()
                    },
                    Interests = new List <PersonInterest>(),
                };
                for (int j = 1; j < i / 2; j++)
                {
                    var newInterst = new PersonInterest {
                        Id = i ^ j, Interest = $"Interest{i}_{j}", PersonId = i, Person = newPerson
                    };
                    newPerson.Interests.Add(newInterst);
                    _interests.Add(newInterst);
                }
                if (i == 10 || i == 11)
                {
                    var snowboardingInterest = new PersonInterest {
                        Id = 1000 + i, Interest = "Snowboarding", PersonId = i, Person = newPerson
                    };
                    newPerson.Interests.Add(snowboardingInterest);
                    _interests.Add(snowboardingInterest);
                }

                _images.Add(newPerson.Image);
                _persons.Add(newPerson);
            }

            _mockContext = new Mock <PeopleSearchContext>();
            _mockContext.Setup(x => x.People).Returns(_persons);
            _mockContext.Setup(x => x.Interests).Returns(_interests);
            _mockContext.Setup(x => x.PersonImages).Returns(_images);

            _personRepository = new PersonRepository(_mockContext.Object);
        }
        public void In_memory_DbSet_can_be_used_for_Add()
        {
            var set = new InMemoryDbSet<Product>();
            var product = new Product();

            Assert.Same(product, set.Add(product));
            Assert.Same(product, set.Single());
        }
        public void GivenBadVoucher_WhenExecute_ThenPublishMappedVoucherStatus()
        {
            queues.Add(new DipsQueue
            {
                ResponseCompleted = false,
                S_BATCH           = "xxx",
                S_LOCATION        = "CodelineValidationDone",
                S_LOCK            = "0",
                S_SDATE           = "01/01/15",
                S_STIME           = "12:12:12",
                CorrelationId     = "yyy",
                S_JOB_ID          = "58300013",
                RoutingKey        = "123456"
            });

            //all flags are true
            vouchers.Add(new DipsNabChq
            {
                S_BATCH          = "xxx",
                S_TRACE          = "zzz",
                S_STATUS1        = "1008",
                proc_date        = "20150707",
                processing_state = "SA",
                captureBSB       = "085384",
                doc_ref_num      = "zzz"
            });

            ExpectContextToCreateTransaction();
            ExpectContextToReturnQueues(queues);
            ExpectContextToReturnVouchers(vouchers);

            var sut = CreatePollingJob();

            sut.Execute(null);

            exchangePublisher.Verify(x => x.PublishAsync(
                                         It.Is <ValidateBatchCodelineResponse>(r =>
                                                                               !r.voucher.Single().extraAuxDomStatus &&
                                                                               !r.voucher.Single().auxDomStatus &&
                                                                               !r.voucher.Single().accountNumberStatus &&
                                                                               !r.voucher.Single().amountStatus &&
                                                                               !r.voucher.Single().bsbNumberStatus &&
                                                                               !r.voucher.Single().transactionCodeStatus &&
                                                                               r.voucher.Single().documentReferenceNumber == "zzz"),
                                         "yyy", "123456"));
        }
        public void In_memory_DbSet_can_be_used_for_Remove()
        {
            var set = new InMemoryDbSet<Product>();
            var product = new Product();

            set.Add(product);

            Assert.Same(product, set.Remove(product));
            Assert.Empty(set);
        }
        public void GivenBadVoucher_WhenExecute_ThenPublishMappedVoucherStatus()
        {
            queues.Add(new DipsQueue
            {
                ResponseCompleted = false,
                S_BATCH           = "xxx",
                S_LOCATION        = "AutoBalancingDone",
                S_LOCK            = "0",
                S_SDATE           = "01/01/15",
                S_STIME           = "12:12:12",
                CorrelationId     = "yyy",
                S_JOB_ID          = "58300013",
                RoutingKey        = "123456"
            });

            vouchers.Add(new DipsNabChq
            {
                S_BATCH          = "xxx",
                S_TRACE          = "zzz",
                S_STATUS1        = "1008",
                balanceReason    = "HighValue",
                micr_unproc_flag = "0",
                doc_type         = "CRT",
                processing_state = "SA",
                captureBSB       = "085384",
                doc_ref_num      = "zzz"
            });

            ExpectContextToCreateTransaction();
            ExpectContextToReturnQueues(queues);
            ExpectContextToReturnVouchers(vouchers);
            //ExpectExchangeToPublish();

            var sut = CreatePollingJob();

            sut.Execute(null);

            exchangePublisher.Verify(x => x.PublishAsync(
                                         It.IsAny <ValidateBatchTransactionResponse>(),
                                         "yyy", "123456"));
        }
        public void PostWithoutExistingPendingBallotDeletesTheVotesOfThatBallot()
        {
            // Arrange
            Guid   manageToken   = Guid.NewGuid();
            Vote   voteToRemove  = new Vote();
            Ballot pendingBallot = new Ballot()
            {
                Email = "[email protected]", ManageGuid = manageToken, Votes = new List <Vote> {
                    voteToRemove
                }
            };

            _dummyBallots.Add(pendingBallot);
            _mainPoll.Ballots.Add(pendingBallot);
            _dummyVotes.Add(voteToRemove);

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel>());

            // Assert
            CollectionAssert.AreEquivalent(new List <Vote>(), _dummyVotes.Local);
        }
        public void WhenExecute_ThenGetCompletedBatches()
        {
            queues.Add(new DipsQueue
            {
                ResponseCompleted = false,
                S_LOCATION        = "CodelineCorrectDone",
                S_LOCK            = "0",
                S_SDATE           = "01/01/15",
                S_STIME           = "12:12:12"
            });

            ExpectContextToCreateTransaction();
            ExpectContextToReturnQueues(queues);
            ExpectContextToReturnVouchers(vouchers);
            ExpectToNotDelete();

            var sut = CreatePollingJob();

            sut.Execute(null);

            dipsDbContext.Verify(x => x.Queues);
        }
        public void setup()
        {
            _mainManageID       = Guid.NewGuid();
            _inviteOnlyManageID = Guid.NewGuid();
            _inviteOnlyPollID   = Guid.NewGuid();
            _mainPoll           = new Poll()
            {
                ManageId = _mainManageID, Name = "Main Poll", UUID = Guid.NewGuid(), Ballots = new List <Ballot>()
            };
            _inviteOnlyPoll = new Poll()
            {
                ManageId = _inviteOnlyManageID, UUID = _inviteOnlyPollID, InviteOnly = true, Ballots = new List <Ballot>()
            };

            InMemoryDbSet <Poll> dummyPolls = new InMemoryDbSet <Poll>(true);

            dummyPolls.Add(_mainPoll);
            dummyPolls.Add(_inviteOnlyPoll);

            _dummyVotes   = new InMemoryDbSet <Vote>(true);
            _dummyBallots = new InMemoryDbSet <Ballot>(true);

            var mockContextFactory = new Mock <IContextFactory>();
            var mockContext        = new Mock <IVotingContext>();

            mockContextFactory.Setup(a => a.CreateContext()).Returns(mockContext.Object);
            mockContext.Setup(a => a.Polls).Returns(dummyPolls);
            mockContext.Setup(a => a.Votes).Returns(_dummyVotes);
            mockContext.Setup(a => a.Ballots).Returns(_dummyBallots);

            _mockInvitationService = new Mock <ICorrespondenceService>();
            _mockMetricHandler     = new Mock <IMetricHandler>();

            _controller               = new ManageInvitationController(mockContextFactory.Object, _mockMetricHandler.Object, _mockInvitationService.Object);
            _controller.Request       = new HttpRequestMessage();
            _controller.Configuration = new HttpConfiguration();
        }
Esempio n. 16
0
        public void setup()
        {
            Guid mainUUID  = Guid.NewGuid();
            Guid emptyUUID = Guid.NewGuid();

            _manageMainUUID  = Guid.NewGuid();
            _manageEmptyUUID = Guid.NewGuid();

            _burgerChoice = new Choice {
                Id = 1, Name = "Burger King"
            };
            _pizzaChoice = new Choice {
                Id = 2, Name = "Pizza Hut"
            };
            _dummyChoices = new InMemoryDbSet <Choice>(true);
            _dummyChoices.Add(_burgerChoice);
            _dummyChoices.Add(_pizzaChoice);

            _burgerVote = new Vote()
            {
                Id = 1, Poll = new Poll()
                {
                    UUID = mainUUID
                }, Choice = new Choice()
                {
                    Id = 1
                }
            };
            _dummyVotes = new InMemoryDbSet <Vote>(true);
            _dummyVotes.Add(_burgerVote);

            _dummyPolls = new InMemoryDbSet <Poll>(true);
            _mainPoll   = new Poll()
            {
                UUID = mainUUID, ManageId = _manageMainUUID, Choices = new List <Choice>()
                {
                    _burgerChoice, _pizzaChoice
                }, Ballots = new List <Ballot>()
            };
            Poll emptyPoll = new Poll()
            {
                UUID = emptyUUID, ManageId = _manageEmptyUUID, Choices = new List <Choice>(), Ballots = new List <Ballot>()
            };

            _dummyPolls.Add(_mainPoll);
            _dummyPolls.Add(emptyPoll);

            _dummyTokens = new InMemoryDbSet <Ballot>(true);

            var mockContextFactory = new Mock <IContextFactory>();
            var mockContext        = new Mock <IVotingContext>();

            mockContextFactory.Setup(a => a.CreateContext()).Returns(mockContext.Object);
            mockContext.Setup(a => a.Choices).Returns(_dummyChoices);
            mockContext.Setup(a => a.Polls).Returns(_dummyPolls);
            mockContext.Setup(a => a.SaveChanges()).Callback(SaveChanges);
            mockContext.Setup(a => a.Votes).Returns(_dummyVotes);
            mockContext.Setup(a => a.Ballots).Returns(_dummyTokens);

            _controller               = new ManageController(mockContextFactory.Object, null);
            _controller.Request       = new HttpRequestMessage();
            _controller.Configuration = new HttpConfiguration();
        }
        public void setup()
        {
            _mainUUID    = Guid.NewGuid();
            _otherUUID   = Guid.NewGuid();
            _pointsUUID  = Guid.NewGuid();
            _tokenUUID   = Guid.NewGuid();
            _timedUUID   = Guid.NewGuid();
            _validBallot = new Ballot {
                TokenGuid = Guid.NewGuid()
            };

            _bobBallot = new Ballot {
                TokenGuid = Guid.NewGuid()
            };
            _joeBallot = new Ballot {
                TokenGuid = Guid.NewGuid()
            };
            _otherBallot = new Ballot {
                TokenGuid = Guid.NewGuid()
            };

            Poll mainPoll = new Poll()
            {
                UUID = _mainUUID, ExpiryDateUtc = DateTime.UtcNow.AddMinutes(30), Ballots = new List <Ballot>()
                {
                    _bobBallot, _joeBallot, _otherBallot
                }
            };
            Poll otherPoll = new Poll()
            {
                UUID = _otherUUID, Ballots = new List <Ballot>()
                {
                    _otherBallot
                }
            };
            Poll pointsPoll = new Poll()
            {
                UUID = _pointsUUID, PollType = PollType.Points, MaxPerVote = 5, MaxPoints = 3, Ballots = new List <Ballot>()
                {
                    _otherBallot
                }
            };
            Poll tokenPoll = new Poll()
            {
                UUID = _tokenUUID, Ballots = new List <Ballot>()
                {
                    _validBallot
                }, InviteOnly = true
            };
            Poll timedPoll = new Poll()
            {
                UUID = _timedUUID, ExpiryDateUtc = DateTime.UtcNow.AddMinutes(-30)
            };

            Choice burgerChoice = new Choice {
                Id = 1, Name = "Burger King"
            };
            Choice pizzaChoice = new Choice {
                Id = 2, Name = "Pizza Hut"
            };
            Choice otherChoice = new Choice {
                Id = 3, Name = "Other"
            };

            _dummyVotes = new InMemoryDbSet <Vote>(true);
            InMemoryDbSet <Choice> dummyChoices = new InMemoryDbSet <Choice>(true);
            InMemoryDbSet <Poll>   dummyPolls   = new InMemoryDbSet <Poll>(true);

            dummyChoices.Add(burgerChoice);
            dummyChoices.Add(pizzaChoice);
            dummyChoices.Add(otherChoice);

            mainPoll.Choices = new List <Choice>()
            {
                burgerChoice, pizzaChoice
            };
            otherPoll.Choices = new List <Choice>()
            {
                burgerChoice, pizzaChoice
            };
            pointsPoll.Choices = new List <Choice>()
            {
                burgerChoice, pizzaChoice
            };
            tokenPoll.Choices = new List <Choice>()
            {
                burgerChoice, pizzaChoice
            };
            timedPoll.Choices = new List <Choice>()
            {
                burgerChoice, pizzaChoice
            };

            dummyPolls.Add(mainPoll);
            dummyPolls.Add(otherPoll);
            dummyPolls.Add(pointsPoll);
            dummyPolls.Add(tokenPoll);
            dummyPolls.Add(timedPoll);

            _bobVote = new Vote()
            {
                Id = 1, Ballot = _bobBallot, Choice = burgerChoice, Poll = mainPoll
            };
            _dummyVotes.Add(_bobVote);

            _joeVote = new Vote()
            {
                Id = 2, Poll = mainPoll, Choice = new Choice()
                {
                    Id = 1
                }, Ballot = _joeBallot
            };
            _dummyVotes.Add(_joeVote);

            var mockContextFactory = new Mock <IContextFactory>();
            var mockContext        = new Mock <IVotingContext>();

            mockContextFactory.Setup(a => a.CreateContext()).Returns(mockContext.Object);
            mockContext.Setup(a => a.Votes).Returns(_dummyVotes);
            mockContext.Setup(a => a.Choices).Returns(dummyChoices);
            mockContext.Setup(a => a.Polls).Returns(dummyPolls);
            mockContext.Setup(a => a.SaveChanges()).Callback(SaveChanges);

            var mockValidator = new Mock <IVoteValidator>();

            _mockValidatorFactory = new Mock <IVoteValidatorFactory>();
            _mockValidatorFactory.Setup(a => a.CreateValidator(PollType.Basic)).Returns(mockValidator.Object);

            _mockMetricHandler = new Mock <IMetricHandler>();

            _controller               = new PollVoteController(mockContextFactory.Object, _mockMetricHandler.Object, _mockValidatorFactory.Object);
            _controller.Request       = new HttpRequestMessage();
            _controller.Configuration = new HttpConfiguration();
        }
        public void PostOfExistingPendingEmailIsLeftAsPending()
        {
            // Arrange
            Guid   manageToken   = Guid.NewGuid();
            Ballot pendingBallot = new Ballot()
            {
                Email = "[email protected]", ManageGuid = manageToken
            };

            _dummyBallots.Add(pendingBallot);
            _mainPoll.Ballots.Add(pendingBallot);
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]", SendInvitation = false, ManageToken = manageToken
            };

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert
            Ballot newBallot = _mainPoll.Ballots.FirstOrDefault();

            Assert.IsNotNull(newBallot);
            Assert.AreEqual(manageToken, newBallot.ManageGuid);
            Assert.AreEqual(Guid.Empty, newBallot.TokenGuid);
            Assert.AreEqual("[email protected]", newBallot.Email);
        }