public static void Init(TestContext context)
        {
            var configuration = new SdkConfigurationInternal(new SdkConfiguration("user", "pass", "host", "vhost", false, "sslServerName", 5, 12, 17, "GBP", SenderChannel.Mobile), null);

            _builderFactory = new BuilderFactoryHelper(configuration).BuilderFactory;
            _endCustomer    = _builderFactory.CreateEndCustomerBuilder().SetId("customerId").SetIp(IPAddress.Loopback).SetDeviceId("deviceId").SetLanguageId("si").Build();
        }
        public void Init()
        {
            var configInternal = new SdkConfigurationInternal(new SdkConfiguration("username", "password", "host", null, true, "sslServerName", 1, 0, 0, "EUR", null, "aaa"), null);

            _cultures = new List <CultureInfo> {
                new CultureInfo("en")
            };

            var uri = new Uri(@"https://api.betradar.com/v1/descriptions/en/markets.xml?include_mappings=true");

            _mockDataFetcher = new Mock <DataFetcherHelper>();
            _mockDataFetcher.Setup(p => p.GetDataAsync(It.IsAny <Uri>())).Returns(new DataFetcherHelper(BuilderFactoryHelper.UriReplacements).GetDataAsync(uri));

            _deserializer = new Deserializer <market_descriptions>();
            _mapper       = new MarketDescriptionsMapperFactory();

            _dataProvider = new DataProvider <market_descriptions, IEnumerable <MarketDescriptionDTO> >(
                uri.AbsoluteUri,
                _mockDataFetcher.Object,
                _mockDataFetcher.Object,
                _deserializer,
                _mapper);

            _marketDescriptionCache = new MarketDescriptionCache(new MemoryCache("InvariantMarketDescriptionCache"),
                                                                 _dataProvider,
                                                                 _cultures,
                                                                 configInternal.AccessToken,
                                                                 TimeSpan.FromHours(4),
                                                                 new CacheItemPolicy {
                SlidingExpiration = TimeSpan.FromDays(1)
            });
        }
        public static ISelectionBuilder Create()
        {
            //TODO: prone to fail in web app
            var configInternal = new SdkConfigurationInternal(new SdkConfiguration(SdkConfigurationSection.GetSection()), null);
            var value          = new Random((int)DateTime.Now.Ticks).Next();
            var dataFetcher    = new LogHttpDataFetcher(new HttpClient(),
                                                        configInternal.AccessToken,
                                                        new IncrementalSequenceGenerator(value, long.MaxValue),
                                                        3,
                                                        12);
            var deserializer = new Deserializer <market_descriptions>();
            var mapper       = new MarketDescriptionsMapperFactory();

            var dataProvider = new DataProvider <market_descriptions, IEnumerable <MarketDescriptionDTO> >(
                configInternal.ApiHost + "/v1/descriptions/{0}/markets.xml?include_mappings=true",
                dataFetcher,
                dataFetcher,
                deserializer,
                mapper);

            var marketDescriptionCache = new MarketDescriptionCache(new MemoryCache("InvariantMarketDescriptionCache"),
                                                                    dataProvider,
                                                                    new [] { new CultureInfo("en") },
                                                                    configInternal.AccessToken,
                                                                    TimeSpan.FromHours(4),
                                                                    new CacheItemPolicy {
                SlidingExpiration = TimeSpan.FromDays(1)
            });
            var marketDescriptionProvider = new MarketDescriptionProvider(marketDescriptionCache, new[] { new CultureInfo("en") });

            return(new SelectionBuilder(marketDescriptionProvider, configInternal, false));
        }
Beispiel #4
0
        public BuilderFactoryHelper(ISdkConfigurationInternal configInternal = null)
        {
            if (configInternal == null)
            {
                configInternal = new SdkConfigurationInternal(new SdkConfiguration(SdkConfigurationSectionTest.Create()), null);
            }

            var container = new UnityContainer();
            var config    = (ISdkConfiguration)configInternal;

            container.RegisterTypes(config, null, null);

            container.RegisterInstance <IDataFetcher>("Base", new DataFetcherHelper(UriReplacements), new ContainerControlledLifetimeManager());

            MarketDescriptionCache = container.Resolve <IMarketDescriptionCache>();

            MarketDescriptionProvider = container.Resolve <IMarketDescriptionProvider>();

            BuilderFactory = container.Resolve <IBuilderFactory>();
        }
        private static void RegisterBaseClasses(IUnityContainer container, ISdkConfiguration config)
        {
            container.RegisterInstance(config, new ContainerControlledLifetimeManager());

            //register common types
            container.RegisterType <HttpClient, HttpClient>(
                new ContainerControlledLifetimeManager(),
                new InjectionConstructor());

            var seed  = (int)DateTime.Now.Ticks;
            var rand  = new Random(seed);
            var value = rand.Next();

            Log.Info($"Initializing sequence generator with MinValue={value}, MaxValue={long.MaxValue}");
            container.RegisterType <ISequenceGenerator, IncrementalSequenceGenerator>(
                new ContainerControlledLifetimeManager(),
                new InjectionConstructor(
                    (long)value,
                    long.MaxValue));

            container.RegisterType <HttpDataFetcher, HttpDataFetcher>("Base",
                                                                      new ContainerControlledLifetimeManager(),
                                                                      new InjectionConstructor(
                                                                          new ResolvedParameter <HttpClient>(),
                                                                          config.AccessToken ?? string.Empty,
                                                                          RestConnectionFailureLimit,
                                                                          RestConnectionFailureTimeoutInSec));

            container.RegisterType <LogHttpDataFetcher, LogHttpDataFetcher>("Base",
                                                                            new ContainerControlledLifetimeManager(),
                                                                            new InjectionConstructor(
                                                                                new ResolvedParameter <HttpClient>(),
                                                                                config.AccessToken ?? string.Empty,
                                                                                new ResolvedParameter <ISequenceGenerator>(),
                                                                                RestConnectionFailureLimit,
                                                                                RestConnectionFailureTimeoutInSec));

            var logFetcher = container.Resolve <LogHttpDataFetcher>("Base");

            container.RegisterInstance <IDataFetcher>("Base", logFetcher, new ContainerControlledLifetimeManager());
            container.RegisterInstance <IDataPoster>("Base", logFetcher, new ContainerControlledLifetimeManager());

            container.RegisterType <ISdkConfigurationInternal, SdkConfigurationInternal>(new ContainerControlledLifetimeManager());
            var configInternal = new SdkConfigurationInternal(config, logFetcher);

            container.RegisterInstance(configInternal);

            if (configInternal.Host.Contains("mtsgate-t1"))
            {
                _environment = "PROD";
            }
            else if (configInternal.Host.Contains("mtsgate-ci"))
            {
                _environment = "CI";
            }
            else
            {
                _environment = "CUSTOM";
            }

            container.RegisterType <IRabbitServer>(new ContainerControlledLifetimeManager());
            var rabbitServer = new RabbitServer(configInternal);

            container.RegisterInstance <IRabbitServer>(rabbitServer);

            container.RegisterType <ConnectionValidator, ConnectionValidator>(new ContainerControlledLifetimeManager());

            container.RegisterType <IConnectionFactory, ConfiguredConnectionFactory>(new ContainerControlledLifetimeManager());

            container.RegisterType <IChannelFactory, ChannelFactory>(new ContainerControlledLifetimeManager());

            container.RegisterInstance <ISequenceGenerator>(new IncrementalSequenceGenerator(), new ContainerControlledLifetimeManager());

            container.RegisterInstance <IConnectionStatus>(new ConnectionStatus(), new ContainerControlledLifetimeManager());
        }