예제 #1
0
        public SubscriberFixture()
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .AddJsonFile(@"Configuration\appsettings.json");
            var configuration = configurationBuilder.Build();

            IntegrationTest = bool.Parse(configuration["SubscriberTests:IntegrationTest"]);

            AppVeyorCIBuild = bool.Parse(Environment.GetEnvironmentVariable("APPVEYOR") ?? "false");

            if (AppVeyorCIBuild)
            {
                return;
            }

            if (bool.Parse(configuration["SubscriberTests:UseStructureMap"]))
            {
                var container = StructureMapIoC.Initialize(configuration);
                if (!IntegrationTest)
                {
                    container.SetupTestMessage(null);
                }
                container.Configure(x =>
                {
                    x.For <TestMessageSender>().Use(context =>
                                                    new TestMessageSender(context.GetInstance <IGenericServiceProvider>(), IntegrationTest));
                    x.For <IGenericServiceProvider>().Use(new StructureMapServiceProvider(container));
                }
                                    );
                ServiceProvider = container.GetInstance <IGenericServiceProvider>();
            }
            else
            {
                var serviceCollection = DotNetIoC.Initialize(configuration);
                if (!IntegrationTest)
                {
                    serviceCollection.SetupTestMessage(null);
                }
                serviceCollection.AddSingleton(provider =>
                                               new TestMessageSender(provider.GetService <IGenericServiceProvider>(), IntegrationTest));
                serviceCollection.AddSingleton <IGenericServiceProvider>(provider => new DotNetServiceProvider(provider));
                var serviceProvider = serviceCollection.BuildServiceProvider();
                ServiceProvider = serviceProvider.GetService <IGenericServiceProvider>();
            }

            var subscriber = ServiceProvider.GetService <Subscriber>();

            if (subscriber.Initialise(new[] { typeof(SubscriberTests).Assembly }).GetAwaiter().GetResult())
            {
                _subscriberTask = Task.Run(() => subscriber.ListenForMessages(_cancellationTokenSource));
            }
        }
예제 #2
0
        // ReSharper restore UseObjectOrCollectionInitializer
        // ReSharper restore FunctionNeverReturns

        protected static void Initialize()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);

            //mono hack
            CaseInsensitiveViewEngine.Register(ViewEngines.Engines);

            StructureMapIoC.CreateContainer();
            ControllerBuilder.Current.SetControllerFactory(new ControllerFactory(IocContainer.Instance));
            ILocaleProvider localeProvider = IocContainer.Instance.Resolve <ILocaleProvider>();
            LocaleData      defaultLocale  = new LocaleData
            {
                Culture   = CultureInfo.GetCultureInfo("en"),
                FullName  = "English",
                ShortName = "en"
            };

            LocaleData russianLocale = new LocaleData
            {
                Culture   = CultureInfo.GetCultureInfo("ru"),
                FullName  = "Русский",
                ShortName = "ru"
            };

            localeProvider.Init(new[] { defaultLocale, russianLocale }, defaultLocale);

            var timeZoneProvider = IocContainer.Instance.Resolve <ITimeZonesProvider>();

            timeZoneProvider.Init(TimeZonesResources.ResourceManager);

            var iconProvider = IocContainer.Instance.Resolve <IIconProvider>();

            iconProvider.Initizlize();

            var oldValidatorProvider = ModelValidatorProviders.Providers.Single(p => p is DataAnnotationsModelValidatorProvider);

            ModelValidatorProviders.Providers.Remove(oldValidatorProvider);
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
            ModelValidatorProviders.Providers.Add(new DataAnnotationsModelValidatorProvider());
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
            DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(MinPasswordLengthAttribute), typeof(MinPasswordLengthValidator));
            DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(PropertiesMustMatchAttribute), typeof(PropertiesMustMatchValidator));
        }