public async Task GetLastWalletEntryAsync_SingleEntry_ReturnsTheEntry()
        {
            //// Arrange

            // Setup In-Memory Database at desired state

            DbContextOptions <WalletContext> dbContextOptions = new DbContextOptionsBuilder <WalletContext>()
                                                                .UseInMemoryDatabase(databaseName: "GetLastWalletEntryAsync_SingleEntry_ReturnsTheEntry")
                                                                .Options;

            WalletEntry expectedEntry = new WalletEntry {
                Id = Guid.NewGuid().ToString(), EventTime = DateTime.UtcNow, Amount = 10, BalanceBefore = 0
            };

            using (WalletContext context = new WalletContext(dbContextOptions))
            {
                context.Add(expectedEntry);
                context.SaveChanges();
            }

            //// Act

            WalletEntry actualEntry;

            using (WalletContext context = new WalletContext(dbContextOptions))
            {
                IWalletRepository walletRepository = new WalletRepository(context);
                actualEntry = await walletRepository.GetLastWalletEntryAsync();
            }

            //// Assert

            Assert.NotNull(actualEntry);
            actualEntry.ShouldCompare(expectedEntry);
        }
Exemplo n.º 2
0
        public async Task CreateRequestForCommandAsync <T>(Guid id)
        {
            var exists = await ExistAsync(id);

            var request = exists ?
                          throw new WalletDomainException($"Request with {id} already exists") :
                                new ClientRequest()
                                {
                                    Id   = id,
                                    Name = typeof(T).Name,
                                    Time = DateTime.UtcNow
                                };

            _context.Add(request);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 3
0
 public async Task <int> addWallet(WalletEntity wallet)
 {
     db.Add(wallet);
     return(await db.SaveChangesAsync());
 }
Exemplo n.º 4
0
 public async Task <int> addUser(UserEntity user)
 {
     db.Add(user);
     return(await db.SaveChangesAsync());
 }