コード例 #1
0
        public async Task Balance_ShouldAddToEachOtherAsync()
        {
            // Arrange
            var         options = BuildContextOptions();
            Participant from;
            Participant to;
            Currency    currency;

            using (var context = new BorrowBuddyContext(options)) {
                currency = context.AddCurrency();
                from     = context.AddParticipant();
                to       = context.AddParticipant();
                context.AddFlow(from, to, currency, 50);
                context.AddFlow(from, to, currency, 100);
            }

            using (var context = new BorrowBuddyContext(options)) {
                var service = new BalanceService(context);
                // Act
                var balance = await service.BalanceAsync(from.Id, to.Id, currency.Code);

                // Assert
                Assert.Equal(150, balance);
            }
        }
コード例 #2
0
        public async Task Update_ShouldUpdateCurrency()
        {
            var options = BuildContextOptions();

            // Arrange
            Currency currency;

            using (var context = new BorrowBuddyContext(options)) {
                currency = context.AddCurrency();
            }

            // Act
            using (var context = new BorrowBuddyContext(options)) {
                var service = new CurrencyService(context);
                await service.UpdateAsync(currency.Code, new CurrencyDto {
                    Scale  = 123,
                    Symbol = "symbol123"
                });
            }

            using (var context = new BorrowBuddyContext(options)) {
                // Assert
                var result = context.Currencies.FirstOrDefault();
                Assert.NotNull(result);
                Assert.Equal(currency.Code, result.Code);
                Assert.Equal(123, result.Scale);
                Assert.Equal("symbol123", result.Symbol);
            }
        }
コード例 #3
0
        public static Flow AddFlow(this BorrowBuddyContext context, long amount = 0)
        {
            var currency = context.AddCurrency();
            var from     = context.AddParticipant();
            var to       = context.AddParticipant();

            return(context.AddFlow(from, to, currency, amount));
        }
コード例 #4
0
        public async Task Get_Exists_ShouldReturnCurrencies()
        {
            // Arrange
            var options = BuildContextOptions();

            using (var context = new BorrowBuddyContext(options)) {
                context.AddCurrency();
                context.AddCurrency();
                context.SaveChanges();
            }

            using (var context = new BorrowBuddyContext(options)) {
                var service = new CurrencyService(context);

                // Act
                var result = await service.GetAsync();

                // Assert
                Assert.NotNull(result);
                Assert.Equal(2, result.Count);
            }
        }
コード例 #5
0
        public async Task Delete_ShouldDeleteCurrency()
        {
            // Arrange
            var options = BuildContextOptions();

            Currency currency;

            using (var context = new BorrowBuddyContext(options)) {
                currency = context.AddCurrency();
            }

            using (var context = new BorrowBuddyContext(options)) {
                // Act
                var service = new CurrencyService(context);
                await service.DeleteAsync(currency.Code);
            }

            using (var context = new BorrowBuddyContext(options)) {
                // Assert
                var result = context.Currencies.FirstOrDefault();
                Assert.Null(result);
            }
        }
コード例 #6
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);
            }
        }