예제 #1
0
        public async Task GivenValidUserContext_WhenGetPayersInvoked_ThenRepositoryCalledWithCorrectArguments()
        {
            var userId = Guid.NewGuid().ToString();

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

            _mockRepository.Verify(repository => repository.GetPayers(userId));
        }
예제 #2
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);
        }