public async Task GivenNoErrors_WhenPostPayeeInvoked_Then200OKReturnedWithCorrectObject()
        {
            var name       = "test name";
            var externalId = "test external id";

            var dto = new CreatePayerPayeeDto
            {
                Name       = name,
                ExternalId = externalId
            };

            var expectedViewModel = new PayerPayeeViewModel
            {
                ExternalId     = externalId,
                PayerPayeeName = name,
                PayerPayeeId   = Guid.NewGuid()
            };

            _mockService.Setup(service => service.CreatePayee(dto)).ReturnsAsync(() => expectedViewModel);

            var controller = new PayersPayeesController(_mockService.Object);
            var response   = await controller.PostPayee(dto);

            var objectResponse = Assert.IsType <OkObjectResult>(response);

            Assert.Equal(StatusCodes.Status200OK, objectResponse.StatusCode);
            Assert.Equal(expectedViewModel, objectResponse.Value);
        }
예제 #2
0
        public async Task GivenValidRequest_WhenPostPayeeEndpointCalled_ThenCorrectPayeePersisted()
        {
            const string expectedPayeeName  = "test payee123";
            const string expectedExternalId = "test external id 123";
            var          cratePayerDto      = new CreatePayerPayeeDto
            {
                Name       = expectedPayeeName,
                ExternalId = expectedExternalId
            };
            var httpContent =
                new StringContent(JsonSerializer.Serialize(cratePayerDto), Encoding.UTF8, "application/json");

            var response = await _httpClient.PostAsync("api/payerspayees/payees", httpContent);

            response.EnsureSuccessStatusCode();

            var scanOutput = await _dynamoDbHelper.ScanTable <PayerPayee>();

            Assert.Collection(scanOutput,
                              payerPayee =>
            {
                Assert.Equal(expectedExternalId, payerPayee.ExternalId);
                Assert.Equal(UserId, payerPayee.UserId);
                Assert.Equal(expectedPayeeName, payerPayee.PayerPayeeName);

                var payerPayeeId = Guid.Parse(payerPayee.PayerPayeeId.Split("payee#")[1]);
                Assert.NotEqual(Guid.Empty, payerPayeeId);
            });
        }
예제 #3
0
        GivenExistingPayersInDatabase_WhenPostPayerEndpointCalled_ThenDuplicatePayerShouldNotBePersisted(
            string expectedPayerName, string expectedExternalId)
        {
            var payer = new PayerPayee
            {
                UserId         = UserId,
                PayerPayeeId   = $"payer#1234567",
                PayerPayeeName = expectedPayerName,
                ExternalId     = expectedExternalId
            };
            var createPayerDto = new CreatePayerPayeeDto
            {
                Name       = expectedPayerName,
                ExternalId = expectedExternalId
            };

            await _dynamoDbHelper.WriteIntoTable(new List <PayerPayee>
            {
                payer,
                new()
                {
                    ExternalId     = "gkrdfhgjkdf",
                    PayerPayeeName = "name",
                    UserId         = UserId,
                    PayerPayeeId   = $"payer#12345676532",
                }
            });
        GivenValidCreatePayerPayeeDto_WhenPostPayeeInvoked_ThenPayerPayeeServiceCreatePayeeCalledWithCorrectDto()
        {
            var dto = new CreatePayerPayeeDto
            {
                Name       = "test name",
                ExternalId = "test external id"
            };
            var controller = new PayersPayeesController(_mockService.Object);
            await controller.PostPayee(dto);

            _mockService.Verify(service => service.CreatePayee(dto));
        }
예제 #5
0
        public async Task <PayerPayeeViewModel> CreatePayer(CreatePayerPayeeDto newPayerPayee)
        {
            var payerPayeeId = Guid.NewGuid();
            await _repository.CreatePayer(new PayerPayee
            {
                PayerPayeeId   = payerPayeeId.ToString(),
                PayerPayeeName = newPayerPayee.Name,
                ExternalId     = newPayerPayee.ExternalId,
                UserId         = _userContext.UserId
            });

            return(new PayerPayeeViewModel
            {
                ExternalId = newPayerPayee.ExternalId,
                PayerPayeeId = payerPayeeId,
                PayerPayeeName = newPayerPayee.Name
            });
        }
예제 #6
0
        public async Task <IActionResult> PostPayee(CreatePayerPayeeDto createPayerPayeeDto)
        {
            var createdPayee = await _payerPayeeService.CreatePayee(createPayerPayeeDto);

            return(Ok(createdPayee));
        }