public async Task CreditCard_Should_BeSavedAndRestoredWithGivenLimit()
        {
            var ownerId = Guid.NewGuid();
            var owner   = new AccountOwnerBuilder()
                          .WithId(ownerId)
                          .Build();

            var expectedLimit = 100;
            var creditCardId  = Guid.NewGuid();
            var creditCard    = new CreditCardBuilder()
                                .WithId(creditCardId)
                                .WithLimit(expectedLimit)
                                .WithOwnerId(ownerId)
                                .Build();

            using (var context = new CreditCardContext())
            {
                var accountOwnerRepository = new AccountOwnerRepository(context);
                var creditCardRepository   = new CreditCardRepository(context);

                await accountOwnerRepository.Add(owner);

                await creditCardRepository.Add(creditCard);

                await context.SaveChangesAsync();

                var storedCreditCard = await creditCardRepository.Get(creditCardId);

                storedCreditCard.Should().NotBeNull();
                var storedSnapshot = storedCreditCard.GetSnapshot();
                storedSnapshot.AvaliableLimit.Should().Be(expectedLimit);
            }
        }
        public async Task CreditCardReport_Should_ShowValidData()
        {
            var ownerId   = Guid.NewGuid();
            var ownerName = $"Name for {ownerId}";
            var owner     = new AccountOwnerBuilder()
                            .WithId(ownerId)
                            .WithName(ownerName)
                            .Build();


            var expectedLimit = 512.11m;
            var creditCardId  = Guid.NewGuid();
            var creditCard    = new CreditCardBuilder()
                                .WithId(creditCardId)
                                .WithLimit(expectedLimit)
                                .WithOwnerId(ownerId)
                                .Build();

            using (var context = new CreditCardContext())
            {
                var accountOwnerRepository = new AccountOwnerRepository(context);
                var creditCardRepository   = new CreditCardRepository(context);

                await accountOwnerRepository.Add(owner);

                await creditCardRepository.Add(creditCard);

                await context.SaveChangesAsync();

                var reports = new CreditCardReports();

                var reportResult = await reports.Generate();

                var expectedEntry = reportResult.FirstOrDefault(rr => rr.Owner == ownerName);

                expectedEntry.Should().NotBeNull();
                expectedEntry.Limit.Should().Be(expectedLimit);
            }
        }
Ejemplo n.º 3
0
 public CreditCardRepository(CreditCardContext context)
 {
     _context = context;
 }
 public AccountOwnerRepository(CreditCardContext context)
 {
     _context = context;
 }