private void initProducts(TariffComparisonContext context, IDictionary <string, TariffEntity> tariffs)
        {
            _testProductId_OnDemand = Guid.NewGuid();
            _testProductId_Packaged = Guid.NewGuid();

            ProductEntity[] productEntities = new ProductEntity[]
            {
                new ProductEntity()
                {
                    Id            = _testProductId_OnDemand,
                    Name          = "basic electricity tariff",
                    InitialTariff = tariffs["bet_0"],
                },
                new ProductEntity()
                {
                    Id            = _testProductId_Packaged,
                    Name          = "Packaged tariff",
                    InitialTariff = tariffs["pdt_0"],
                },
            };
            foreach (ProductEntity p in productEntities)
            {
                context.Products.Add(p);
            }
            context.SaveChanges();
        }
Esempio n. 2
0
        public void Setup()
        {
            _opts = new DbContextOptionsBuilder <TariffComparisonContext>()
                    .UseInMemoryDatabase(databaseName: "TEST_TariffService")
                    .Options;

            // Set id for class to access in tests (to have a specific reference)
            _testTariffId = Guid.NewGuid();

            using (TariffComparisonContext context = new TariffComparisonContext(_opts))
            {
                // Insert test data
                // Using dict here and single assignment to have it easier to assign corresponding relationships
                Dictionary <string, TariffEntity> dict = new Dictionary <string, TariffEntity>();

                dict.Add("bet_0", new TariffEntity()
                {
                    Id = Guid.NewGuid(),
                    BaseCostsAnnual        = 5 * 12,
                    ConsumptionCostsPerKWh = 0.22M,
                    NextPricingTier        = null, // no next pricing tier
                    KWhLimit = null,               // no kwHLimit
                });

                dict.Add("pdt_1", new TariffEntity()
                {
                    Id = Guid.NewGuid(),
                    BaseCostsAnnual        = 0,
                    ConsumptionCostsPerKWh = _consumptionCostsPerKwHNextTier,
                    NextPricingTier        = null,
                    KWhLimit = null,
                });

                dict.Add("pdt_0", new TariffEntity()
                {
                    Id = _testTariffId,
                    BaseCostsAnnual        = _baseCostsAnnualTest,
                    ConsumptionCostsPerKWh = 0,
                    NextPricingTier        = dict["pdt_1"], // Reference next higher pricing tier
                    KWhLimit = 4000M,
                });


                foreach (TariffEntity t in dict.Values)
                {
                    context.Tariffs.Add(t);
                }
                context.SaveChanges();
            }

            // Init service for test (separate context)
            _tariffService = new TariffService(new TariffComparisonContext(_opts));
        }
Esempio n. 3
0
        public static void Initialize(TariffComparisonContext context)
        {
            context.Database.EnsureCreated();

            // Evaluate if already initialized
            if (context.Products.Any())
            {
                return; // db seeded
            }

            initTariffs(context, out IDictionary <string, TariffEntity> dict);
            initProducts(context, dict);
        }
        public void Setup()
        {
            _opts = new DbContextOptionsBuilder <TariffComparisonContext>()
                    .UseInMemoryDatabase(databaseName: "TEST_PriceComparisonService")
                    .Options;

            using (TariffComparisonContext context = new TariffComparisonContext(_opts))
            {
                // Insert test data
                initTariffs(context, out IDictionary <string, TariffEntity> tariffs);
                initProducts(context, tariffs);
            }

            // Init service for test (separate context)
            _priceComparisonService = new PriceComparisonService(new TariffComparisonContext(_opts));
        }
Esempio n. 5
0
        private static void initTariffs(TariffComparisonContext context, out IDictionary <string, TariffEntity> dict)
        {
            // Using dict here and single assignment to have it easier to assign corresponding relationships
            dict = new Dictionary <string, TariffEntity>();

            dict.Add("bet_0", new TariffEntity()
            {
                Id = Guid.NewGuid(),
                BaseCostsAnnual        = 5 * 12,
                ConsumptionCostsPerKWh = 0.22M,
                NextPricingTier        = null, // no next pricing tier
                KWhLimit = null,               // no kwHLimit
            });

            dict.Add("pdt_1", new TariffEntity()
            {
                Id = Guid.NewGuid(),
                BaseCostsAnnual        = 0,
                ConsumptionCostsPerKWh = 0.30M,
                NextPricingTier        = null,
                KWhLimit = null,
            });

            dict.Add("pdt_0", new TariffEntity()
            {
                Id = Guid.NewGuid(),
                BaseCostsAnnual        = 800M,
                ConsumptionCostsPerKWh = 0,
                NextPricingTier        = dict["pdt_1"], // Reference next higher pricing tier
                KWhLimit = 4000M,
            });


            foreach (TariffEntity t in dict.Values)
            {
                context.Tariffs.Add(t);
            }
            context.SaveChanges();
        }
Esempio n. 6
0
        public void Setup()
        {
            _opts = new DbContextOptionsBuilder <TariffComparisonContext>()
                    .UseInMemoryDatabase(databaseName: "TEST_ProductService")
                    .Options;

            // Set id for class to access in tests (to have a specific reference)
            _testProductId = Guid.NewGuid();

            using (TariffComparisonContext context = new TariffComparisonContext(_opts))
            {
                // Insert test data
                context.Products.AddRange(
                    new ProductEntity()
                {
                    Id            = Guid.NewGuid(),
                    Name          = "basic electricity tariff",
                    InitialTariff = null,
                },
                    new ProductEntity()
                {
                    Id            = _testProductId,
                    Name          = "Packaged tariff",
                    InitialTariff = new TariffEntity()
                    {
                        Id = Guid.NewGuid(),
                        BaseCostsAnnual        = 800M,
                        ConsumptionCostsPerKWh = 0,
                        NextPricingTier        = null, // Reference next higher pricing tier
                        KWhLimit = 4000M,
                    },
                }
                    );
                context.SaveChanges();
            }

            // Init service for test (separate context)
            _productService = new ProductService(new TariffComparisonContext(_opts));
        }
Esempio n. 7
0
 public void TearDown()
 {
     using TariffComparisonContext context = new TariffComparisonContext(_opts);
     context.Database.EnsureDeleted();
 }
 public ApiInfoService(TariffComparisonContext dbContext)
 {
     _dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
 }