Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        public async Task Add_ShouldAddParticipant()
        {
            // Arrange
            var options = BuildContextOptions();

            using (var context = new BorrowBuddyContext(options)) {
                // Act
                var service = new ParticipantService(context);
                var dto     = new ParticipantDto {
                    FirstName  = "FirstName",
                    LastName   = "LastName",
                    MiddleName = "MiddleName"
                };
                await service.AddAsync(dto);
            }

            // Assert
            using (var context = new BorrowBuddyContext(options)) {
                var participant = context.Participants.FirstOrDefault();
                Assert.NotNull(participant);
                Assert.Equal("FirstName", participant.FirstName);
                Assert.Equal("LastName", participant.LastName);
                Assert.Equal("MiddleName", participant.MiddleName);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public async Task Update_ShouldUpdateParticipant()
        {
            // Arrange
            var options = BuildContextOptions();

            Participant participant;

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

            // Act
            using (var context = new BorrowBuddyContext(options)) {
                var service = new ParticipantService(context);

                await service.UpdateAsync(participant.Id, new ParticipantDto {
                    FirstName  = "FirstName_Modified",
                    LastName   = "LastName_Modified",
                    MiddleName = "MiddleName_Modified"
                });
            }

            // Assert
            using (var context = new BorrowBuddyContext(options)) {
                var result = context.Participants.FirstOrDefault();
                Assert.NotNull(result);
                Assert.Equal("FirstName_Modified", result.FirstName);
                Assert.Equal("LastName_Modified", result.LastName);
                Assert.Equal("MiddleName_Modified", result.MiddleName);
            }
        }
        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));
        }
        public static Participant AddParticipant(this BorrowBuddyContext context)
        {
            var participant = new Participant();

            context.Participants.Add(participant);
            context.SaveChanges();
            return(participant);
        }
Exemplo n.º 7
0
        public async Task Get_CodeIsNull_ShouldThrow()
        {
            // Arrange
            var options = BuildContextOptions();

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

                // Act
                // Assert
                await Assert.ThrowsAsync <ArgumentNullException>(() => service.GetAsync(null));
            }
        }
        public static Currency AddCurrency(this BorrowBuddyContext context, string code = "")
        {
            if (string.IsNullOrEmpty(code))
            {
                code = Guid.NewGuid().ToString();
            }
            var currency = new Currency {
                Code = code
            };

            context.Currencies.Add(currency);
            context.SaveChanges();
            return(currency);
        }
Exemplo n.º 9
0
        public async Task Get_DontExist_ShouldReturnNull()
        {
            // Arrange
            var options = BuildContextOptions();

            using (var context = new BorrowBuddyContext(options)) {
                var service = new ParticipantService(context);
                // Act
                var result = await service.GetAsync(Guid.NewGuid());

                // Assert
                Assert.Null(result);
            }
        }
Exemplo n.º 10
0
        public async Task Get_DontExist_ShouldReturnNull()
        {
            // Arrange
            var options = BuildContextOptions();

            using (var context = new BorrowBuddyContext(options)) {
                var service = new CurrencyService(context);
                // Act
                var result = await service.GetAsync("code");

                // Assert
                Assert.Null(result);
            }
        }
        public static Flow AddFlow(this BorrowBuddyContext context, Participant from, Participant to, Currency currency, long amount)
        {
            var flow = new Flow {
                Lendee = to,
                Lender = from,
                Amount = new Money {
                    Currency = currency,
                    Value    = amount
                }
            };

            context.Flows.Add(flow);
            context.SaveChanges();
            return(flow);
        }
Exemplo n.º 12
0
        public async Task Get_DontExist_ShouldReturnEmptyList()
        {
            // Arrange
            var options = BuildContextOptions();

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

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

                // Assert
                Assert.NotNull(result);
                Assert.Empty(result);
            }
        }
Exemplo n.º 13
0
        public async Task Get_Exists_ShouldReturnCurrency()
        {
            // Arrange
            var options = BuildContextOptions();

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

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

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

                // Assert
                Assert.NotNull(result);
            }
        }
Exemplo n.º 14
0
        public async Task Get_Exists_ShouldReturnFlow()
        {
            // Arrange
            var  options = BuildContextOptions();
            Flow flow;

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

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

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

                // Assert
                Assert.NotNull(result);
            }
        }
Exemplo n.º 15
0
        public async Task Get_Exists_ShouldReturnParticipants()
        {
            // Arrange
            var options = BuildContextOptions();

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

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

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

                // Assert
                Assert.NotNull(result);
                Assert.Equal(2, result.Count);
            }
        }
Exemplo n.º 16
0
        public async Task Add_ShouldAddCurrency()
        {
            var options = BuildContextOptions();

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

                await service.AddAsync(new CurrencyDto {
                    Code = "code"
                });
            }

            // Assert
            using (var context = new BorrowBuddyContext(options)) {
                // Assert
                var result = context.Currencies.FirstOrDefault();
                Assert.NotNull(result);
                Assert.Equal("code", result.Code);
            }
        }
Exemplo n.º 17
0
        public async Task Delete_ShouldDeleteFlow()
        {
            // Arrange
            var options = BuildContextOptions();

            Flow flow;

            using (var context = new BorrowBuddyContext(options)) {
                flow = context.AddFlow();
            }

            using (var context = new BorrowBuddyContext(options)) {
                // Act
                var service = new FlowService(context);
                await service.DeleteAsync(flow.Id);
            }

            using (var context = new BorrowBuddyContext(options)) {
                // Assert
                var result = context.Flows.FirstOrDefault();
                Assert.Null(result);
            }
        }
Exemplo n.º 18
0
        public async Task Delete_ShouldDeleteParticipant()
        {
            // Arrange
            var options = BuildContextOptions();

            Participant participant;

            using (var context = new BorrowBuddyContext(options)) {
                participant = context.AddParticipant();
            }

            using (var context = new BorrowBuddyContext(options)) {
                // Act
                var service = new ParticipantService(context);
                await service.DeleteAsync(participant.Id);
            }

            using (var context = new BorrowBuddyContext(options)) {
                // Assert
                var result = context.Participants.FirstOrDefault();
                Assert.Null(result);
            }
        }
Exemplo n.º 19
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);
            }
        }
Exemplo n.º 20
0
        public async Task Update_ShouldUpdateFlow()
        {
            // Arrange
            var         options = BuildContextOptions();
            Flow        flow;
            Participant newLender;
            Participant newLendee;

            using (var context = new BorrowBuddyContext(options)) {
                flow      = context.AddFlow();
                newLender = context.AddParticipant();
                newLendee = context.AddParticipant();
                context.SaveChanges();
            }

            // Act
            using (var context = new BorrowBuddyContext(options)) {
                var service = new FlowService(context);

                await service.UpdateAsync(flow.Id, new FlowDto {
                    Amount   = 123,
                    Comment  = "newComment",
                    LendeeId = newLendee.Id,
                    LenderId = newLender.Id
                });
            }

            // Assert
            using (var context = new BorrowBuddyContext(options)) {
                var result = context.Flows.FirstOrDefault();
                Assert.NotNull(result);
                Assert.Equal(123, result.Amount.Value);
                Assert.Equal("newComment", result.Comment);
                Assert.Equal(newLendee.Id, result.Lendee.Id);
                Assert.Equal(newLender.Id, result.Lender.Id);
            }
        }
Exemplo n.º 21
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);
            }
        }
Exemplo n.º 22
0
 public ParticipantService(BorrowBuddyContext context)
 {
     _context = context;
 }
Exemplo n.º 23
0
 public BalanceService(BorrowBuddyContext context)
 {
     _context = context;
 }
Exemplo n.º 24
0
 public FlowService(BorrowBuddyContext context)
 {
     _context = context;
 }
Exemplo n.º 25
0
 public CurrencyService(BorrowBuddyContext context)
 {
     _context = context;
 }
Exemplo n.º 26
0
 public DbMigrator(BorrowBuddyContext context)
 {
     _context = context;
 }