예제 #1
0
        public async Task <ActionResult <Flow> > PostFlow(FlowPost model)
        {
            var flow = await _flowService.AddAsync(new FlowDto {
                Amount       = model.Amount,
                CurrencyCode = model.CurrencyCode,
                LenderId     = model.Lender,
                LendeeId     = model.Lendee,
                Comment      = model.Comment
            });

            return(CreatedAtAction(nameof(GetFlow), new { id = flow.Id }, Mapper.Map(flow)));
        }
예제 #2
0
        public async Task Add_ShouldAddFlow()
        {
            // Arrange
            var         options = BuildContextOptions();
            Currency    currency;
            Participant lender;
            Participant lendee;

            using (var context = new BorrowBuddyContext(options)) {
                currency = context.AddCurrency();
                lender   = context.AddParticipant();
                lendee   = context.AddParticipant();
                context.SaveChanges();
            }

            using (var context = new BorrowBuddyContext(options)) {
                // Act
                var service = new FlowService(context);
                var dto     = new FlowDto {
                    LendeeId     = lendee.Id,
                    LenderId     = lender.Id,
                    Amount       = 100,
                    CurrencyCode = currency.Code
                };
                await service.AddAsync(dto);
            }

            // Assert
            using (var context = new BorrowBuddyContext(options)) {
                var flow = context.Flows.FirstOrDefault();
                Assert.NotNull(flow);
                Assert.Equal(lender.Id, flow.Lender.Id);
                Assert.Equal(lendee.Id, flow.Lendee.Id);
                Assert.Equal(100, flow.Amount.Value);
                Assert.Equal(currency.Code, flow.Amount.Currency.Code);
            }
        }