Example #1
0
        public async Task GivenRepositoryResponse_WhenGetPayeeInvoked_ThenCorrectPayerPayeeModelReturned()
        {
            var name          = "name";
            var externalId    = "externalId";
            var payerPayeeId  = Guid.NewGuid();
            var userId        = Guid.NewGuid().ToString();
            var expectedPayee = new PayerPayeeViewModel
            {
                ExternalId     = externalId,
                PayerPayeeId   = payerPayeeId,
                PayerPayeeName = name
            };

            _mockCurrentUserContext.SetupGet(context => context.UserId).Returns(userId);

            _mockRepository.Setup(repository => repository.GetPayee(userId, payerPayeeId))
            .ReturnsAsync(() => new PayerPayee
            {
                ExternalId     = externalId,
                UserId         = userId,
                PayerPayeeId   = payerPayeeId.ToString(),
                PayerPayeeName = name
            });

            var service     = new PayerPayeeService(_mockCurrentUserContext.Object, _mockRepository.Object);
            var actualPayer = await service.GetPayee(payerPayeeId);

            Assert.Equal(expectedPayee, actualPayer);
        }
Example #2
0
        public async Task GivenValidUserContext_WhenGetPayeesInvoked_ThenRepositoryCalledWithCorrectArguments()
        {
            var userId = Guid.NewGuid().ToString();

            _mockCurrentUserContext.SetupGet(context => context.UserId).Returns(userId);
            var service = new PayerPayeeService(_mockCurrentUserContext.Object, _mockRepository.Object);
            await service.GetPayees();

            _mockRepository.Verify(repository => repository.GetPayees(userId));
        }
Example #3
0
        GivenValidPayerNameAndUserContext_WhenAutocompletePayeeInvoked_ThenRepositoryCalledWithCorrectArguments()
        {
            var payeeName = "test name";
            var userId    = Guid.NewGuid().ToString();

            _mockCurrentUserContext.SetupGet(context => context.UserId).Returns(userId);

            var service = new PayerPayeeService(_mockCurrentUserContext.Object, _mockRepository.Object);
            await service.AutocompletePayee(payeeName);

            _mockRepository.Verify(repository => repository.AutocompletePayee(userId, payeeName));
        }
Example #4
0
        public async Task GivenRepositoryResponse_ThenCorrectPayeeReturned()
        {
            const string expectedPayeeName  = "payer name 123";
            const string expectedExternalId = "externalId123";
            var          userId             = Guid.NewGuid().ToString();

            _mockCurrentUserContext.SetupGet(context => context.UserId).Returns(userId);

            var service     = new PayerPayeeService(_mockCurrentUserContext.Object, _mockRepository.Object);
            var actualPayee = await service.CreatePayee(new CreatePayerPayeeDto
            {
                Name       = expectedPayeeName,
                ExternalId = expectedExternalId
            });

            Assert.Equal(expectedExternalId, actualPayee.ExternalId);
            Assert.Equal(expectedPayeeName, actualPayee.PayerPayeeName);
            Assert.NotEqual(Guid.Empty, actualPayee.PayerPayeeId);
        }
Example #5
0
        public async Task GivenValidIdAndUserContext_WhenGetPayeeInvoked_ThenRepositoryCalledWithCorrectArguments()
        {
            var payerPayeeId = Guid.NewGuid();
            var userId       = Guid.NewGuid().ToString();

            _mockRepository.Setup(repository => repository.GetPayee(userId, payerPayeeId))
            .ReturnsAsync(() => new PayerPayee
            {
                ExternalId     = "externalId",
                PayerPayeeId   = Guid.NewGuid().ToString(),
                PayerPayeeName = "name"
            });
            _mockCurrentUserContext.SetupGet(context => context.UserId).Returns(userId);

            var service = new PayerPayeeService(_mockCurrentUserContext.Object, _mockRepository.Object);
            await service.GetPayee(payerPayeeId);

            _mockRepository.Verify(repository => repository.GetPayee(userId, payerPayeeId));
        }
Example #6
0
        public async Task GivenRepositoryResponse_WhenAutocompletePayeeInvoked_ThenCorrectPayerPayeeEnumerableReturned()
        {
            var payeeName = "test name";
            var userId    = Guid.NewGuid().ToString();

            _mockCurrentUserContext.SetupGet(context => context.UserId).Returns(userId);

            var repositoryPayees = new List <PayerPayee>
            {
                new()
                {
                    ExternalId     = "externalId1",
                    UserId         = "userId",
                    PayerPayeeId   = Guid.NewGuid().ToString(),
                    PayerPayeeName = "name1"
                },
                new()
                {
                    ExternalId     = "externalId2",
                    UserId         = "userId",
                    PayerPayeeId   = Guid.NewGuid().ToString(),
                    PayerPayeeName = "name2"
                }
            };

            _mockRepository.Setup(repository => repository.AutocompletePayee(userId, payeeName))
            .ReturnsAsync(() => repositoryPayees);

            var service      = new PayerPayeeService(_mockCurrentUserContext.Object, _mockRepository.Object);
            var actualPayees = await service.AutocompletePayee(payeeName);

            var expectedPayees = repositoryPayees.Select(payee => new PayerPayeeViewModel
            {
                ExternalId     = payee.ExternalId,
                PayerPayeeId   = Guid.Parse(payee.PayerPayeeId),
                PayerPayeeName = payee.PayerPayeeName
            });

            Assert.Equal(expectedPayees, actualPayees);
        }
    }
Example #7
0
        public async Task GivenRepositoryResponse_WhenGetPayersInvoked_CorrectIEnumerableReturned()
        {
            var userId = Guid.NewGuid().ToString();

            _mockCurrentUserContext.SetupGet(context => context.UserId).Returns(userId);

            var payers = new List <PayerPayee>
            {
                new()
                {
                    UserId         = "userId123",
                    PayerPayeeId   = Guid.NewGuid().ToString(),
                    PayerPayeeName = "name123",
                    ExternalId     = "id123"
                },
                new()
                {
                    UserId         = "userId1234",
                    PayerPayeeId   = Guid.NewGuid().ToString(),
                    PayerPayeeName = "name123",
                    ExternalId     = "id1234"
                }
            };

            var payerViewModels = payers.Select(payer => new PayerPayeeViewModel
            {
                ExternalId     = payer.ExternalId,
                PayerPayeeId   = Guid.Parse(payer.PayerPayeeId),
                PayerPayeeName = payer.PayerPayeeName
            });

            _mockRepository.Setup(repository => repository.GetPayers(It.IsAny <string>()))
            .ReturnsAsync(() => payers);
            var service = new PayerPayeeService(_mockCurrentUserContext.Object, _mockRepository.Object);

            var response = await service.GetPayers();

            Assert.Equal(payerViewModels, response);
        }
Example #8
0
        GivenValidCreatePayerPayeeDto_ThenRepositoryCalledWithCorrectPayerPayeeModel()
        {
            const string expectedPayeeName  = "payee name 123";
            const string expectedExternalId = "externalId123";
            var          userId             = Guid.NewGuid().ToString();

            _mockCurrentUserContext.SetupGet(context => context.UserId).Returns(userId);

            var service = new PayerPayeeService(_mockCurrentUserContext.Object, _mockRepository.Object);
            await service.CreatePayee(new CreatePayerPayeeDto
            {
                Name       = expectedPayeeName,
                ExternalId = expectedExternalId
            });

            _mockRepository.Verify(repository => repository.CreatePayee(It.Is <PayerPayee>(payerPayee =>
                                                                                           payerPayee.UserId == userId &&
                                                                                           payerPayee.ExternalId == expectedExternalId &&
                                                                                           payerPayee.PayerPayeeName == expectedPayeeName &&
                                                                                           !Guid.Parse(payerPayee.PayerPayeeId).Equals(Guid.Empty)
                                                                                           )));
        }