Exemple #1
0
        public async Task GetTest()
        {
            var options = new DbContextOptionsBuilder <JanusContext>()
                          .UseInMemoryDatabase(databaseName: "merchantDb")
                          .Options;


            using (var context = new JanusContext(options))
            {
                context.Add(new Merchant {
                    Id = 1, Name = "MerchantA", ClientId = "123", ClientSecret = "Megasecret"
                });
                context.SaveChanges();
            }

            using (var newContext = new JanusContext(options))
            {
                var merchantrepo = new MerchantRepository(newContext);
                var result       = await merchantrepo.Get("123");

                Assert.AreEqual(1, result.Id);
                Assert.AreEqual("MerchantA", result.Name);
                Assert.AreEqual("123", result.ClientId);
                Assert.AreEqual("Megasecret", result.ClientSecret);
            }
        }
Exemple #2
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new JanusContext(serviceProvider.GetRequiredService <DbContextOptions <JanusContext> >()))
            {
                if (context.Merchants.Any())
                {
                    // Data is already present
                    return;
                }

                // Add fake merchants
                context.Merchants.Add(new Merchant
                {
                    ClientId     = "123456",
                    ClientSecret = "psss-it-s-a-secret",
                    Id           = 1,
                    Name         = "Merchant1"
                });


                context.Merchants.Add(new Merchant
                {
                    ClientId     = "1",
                    ClientSecret = "psss-it-s-a-secret2",
                    Id           = 2,
                    Name         = "Merchant2"
                });

                context.SaveChanges();
            }
        }
Exemple #3
0
        public async Task GetTest()
        {
            var options = new DbContextOptionsBuilder <JanusContext>()
                          .UseInMemoryDatabase(databaseName: "get-transaction")
                          .Options;

            using (var context = new JanusContext(options))
            {
                context.Add(new Transaction {
                    Id = 1, Amount = 11.45, ExternalId = "externalId", Status = true, MerchantId = 1
                });
                context.Add(new Transaction {
                    Id = 2, Amount = 0.55, ExternalId = "externalId2", Status = false, MerchantId = 1
                });
                context.SaveChanges();
            }

            using (var newContext = new JanusContext(options))
            {
                var paymentRepo = new PaymentRepository(newContext);
                var result      = await paymentRepo.Get("externalId", 1);

                Assert.AreEqual(1, result.Id);
                Assert.AreEqual(11.45, result.Amount);
                Assert.IsTrue(result.Status);
            }
        }