コード例 #1
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));
        }
コード例 #2
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);
        }
    }