示例#1
0
        private static void ConfigureCoreContextByDefault()
        {
            var cs = DbRegistry.GetConnectionString("core");

            if (cs == null)
            {
                throw new ConfigurationErrorsException("Can not configure CoreContext: connection string with name core not found.");
            }

            var tenantService = new CachedTenantService(new DbTenantService(cs));
            var userService   = new CachedUserService(new DbUserService(cs));
            var azService     = new CachedAzService(new DbAzService(cs));
            var quotaService  = new CachedQuotaService(new DbQuotaService(cs));
            var subService    = new CachedSubscriptionService(new DbSubscriptionService(cs));
            var tariffService = new TariffService(cs, quotaService, tenantService);

            Configuration        = new ClientConfiguration(tenantService);
            TenantManager        = new ClientTenantManager(tenantService, quotaService, tariffService);
            PaymentManager       = new ClientPaymentManager(Configuration, quotaService, tariffService);
            UserManager          = new ClientUserManager(userService);
            GroupManager         = new ClientUserManager(userService);
            Authentication       = new ClientAuthManager(userService);
            AuthorizationManager = new ClientAzManager(azService);
            SubscriptionManager  = new ClientSubscriptionManager(subService);
        }
示例#2
0
 public TariffServiceTest()
 {
     LoggerMock             = new Mock <ILogger <TariffService> >();
     MappingConfig          = new MapperConfiguration(cfg => { cfg.AddProfile(new MappingProfile()); });
     Mapper                 = MappingConfig.CreateMapper();
     TariffServiceUnderTest = new TariffService(Mapper, LoggerMock.Object);
 }
示例#3
0
        public void Configure(string name, TenantManager options)
        {
            Configure(options);

            options.TenantService = TenantService.Get(name);
            options.QuotaService  = QuotaService.Get(name);
            options.TariffService = TariffService.Get(name);
        }
        public TariffControllerTest()
        {
            LoggerMock    = new Mock <ILogger <TariffService> >();
            MappingConfig = new MapperConfiguration(cfg => { cfg.AddProfile(new MappingProfile()); });
            Mapper        = MappingConfig.CreateMapper();

            ITariffService provider = new TariffService(Mapper, LoggerMock.Object);

            _controller = new TariffController(provider);
        }
示例#5
0
        public void SetTariff(int tenant, bool paid)
        {
            var quota = QuotaService.GetTenantQuotas().FirstOrDefault(q => paid ? q.NonProfit : q.Trial);

            if (quota != null)
            {
                TariffService.SetTariff(tenant, new Tariff {
                    QuotaId = quota.Id, DueDate = DateTime.MaxValue,
                });
            }
        }
示例#6
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));
        }
示例#7
0
 public void Configure(string name, HostedSolution hostedSolution)
 {
     Configure(hostedSolution);
     hostedSolution.Region              = name;
     hostedSolution.TenantService       = TenantService.Get(name);
     hostedSolution.UserService         = UserService.Get(name);
     hostedSolution.QuotaService        = QuotaService.Get(name);
     hostedSolution.TariffService       = TariffService.Get(name);
     hostedSolution.ClientTenantManager = TenantManager.Get(name);
     hostedSolution.TenantUtil          = TenantUtil.Get(name);
     hostedSolution.SettingsManager     = DbSettingsManager.Get(name);
     hostedSolution.CoreSettings        = CoreSettings.Get(name);
 }
        public TariffServiceTests()
        {
            _mockDateTimeWrapper = new Mock <IDateTimeWrapper>();
            _mockDbConfig        = new Mock <DatabaseConfig>();
            _mockTariffConfig    = new Mock <TariffConfig>();
            _mockConfigProvider  = new Mock <IConfigProvider>();
            _mockLogger          = new Mock <ILogger <TariffService> >();
            _mockRepository      = new Mock <ITeslaMateRepository>();

            _mockConfigProvider.Setup(x => x.Get <DatabaseConfig>())
            .Returns(_mockDbConfig.Object);

            _mockConfigProvider.Setup(x => x.Get <TariffConfig>())
            .Returns(_mockTariffConfig.Object);

            _service = new TariffService(_mockConfigProvider.Object, _mockDateTimeWrapper.Object,
                                         _mockLogger.Object, _mockRepository.Object);
        }
示例#9
0
 public void SaveButton(int tariffId, string partnerId, string buttonUrl)
 {
     TariffService.SaveButton(tariffId, partnerId, buttonUrl);
 }
示例#10
0
 public void SetTariff(int tenant, Tariff tariff)
 {
     TariffService.SetTariff(tenant, tariff);
 }
示例#11
0
 public Tariff GetTariff(int tenant, bool withRequestToPaymentSystem = true)
 {
     return(TariffService.GetTariff(tenant, withRequestToPaymentSystem));
 }
示例#12
0
 public TariffController(TariffContext context)
 {
     tariffService = new TariffService(context);
 }
示例#13
0
 public TariffController(TariffService tariffService)
 {
     this.tariffService = tariffService;
 }