Пример #1
0
        static void Main(string[] args)
        {
            DefaultServices.RegisterDefaultServices();
            Console.WriteLine("Ef Template Service Tester");
            Console.WriteLine("-------------------------");
            Console.WriteLine("Q)\t Select CustomerOrders");
            Console.WriteLine("I)\t Insert Employee");
            Console.WriteLine("E)\t Exit");
            Console.Write("Select option >>");

            string command = Console.ReadLine();

            while (command.ToUpper() != "E")
            {
                Console.WriteLine("");
                try {
                    HandleOptions(command);
                }
                catch (Exception ex) {
                    ex = ex.GetBaseException();

                    string errorMessage = "ExceptionMessage: " + ex.Message;
                    string stackTrace   = ex.StackTrace;
                    Console.WriteLine(errorMessage);
                    Console.WriteLine("StackTrace: {0}", stackTrace);
                }
                if (command.ToUpper() != "L")
                {
                    Console.WriteLine("Select option >>");
                }
                command = Console.ReadLine();
            }
        }
Пример #2
0
        protected virtual void Application_Start(Object sender, EventArgs e)
        {
            Started = DateTime.Now;

            // Init log system
            if (String.Compare(Environment.GetEnvironmentVariable("GBRAINY_DEBUG"), "false", false) != 0)
            {
                Logger.LogLevel  = Level.DEBUG;
                Logger.LogDevice = new FileLogger();
            }
            else
            {
                Logger.LogLevel  = Level.INFO;
                Logger.LogDevice = new ConsoleLogger();
            }

            // Register services
            DefaultServices services = new DefaultServices();

            services.RemoveService <ITranslations> ();
            services.RegisterServices();

            ServiceLocator.Instance.RegisterService <ITranslations> (new TranslationsWeb());
            ThemeManager.ConfigPath = Defines.THEMES_DIR;

            // Configuration
            ServiceLocator.Instance.GetService <IConfiguration> ().Set(ConfigurationKeys.GamesGraphics, "images/");
            ServiceLocator.Instance.GetService <IConfiguration> ().Set(ConfigurationKeys.AssembliesDir, "bin/");

            Logger.Info("Global.Application_Start.gbrainy web starting");
        }
Пример #3
0
        public void Constructor_DefaultServicesInContainer()
        {
            // Arrange
            var config = new ProcessorConfiguration();

            // Act
            var defaultServices = new DefaultServices(config);

            // Assert
            Assert.IsType(typeof(DefaultCommandHandlerSelector), defaultServices.GetService(typeof(ICommandHandlerSelector)));
            Assert.IsType(typeof(DefaultCommandHandlerActivator), defaultServices.GetService(typeof(ICommandHandlerActivator)));
            Assert.IsType(typeof(DefaultCommandHandlerTypeResolver), defaultServices.GetService(typeof(ICommandHandlerTypeResolver)));
            Assert.IsType(typeof(DefaultAssembliesResolver), defaultServices.GetService(typeof(IAssembliesResolver)));
            Assert.IsType(typeof(DefaultInterceptionProvider), defaultServices.GetService(typeof(IInterceptionProvider)));

            object[] filterProviders = defaultServices.GetServices(typeof(IFilterProvider)).ToArray();
            Assert.Equal(2, filterProviders.Length);
            Assert.IsType(typeof(ConfigurationFilterProvider), filterProviders[0]);
            Assert.IsType(typeof(HandlerFilterProvider), filterProviders[1]);

            Assert.IsType(typeof(DefaultCommandValidator), defaultServices.GetService(typeof(ICommandValidator)));

            object[] interceptors = defaultServices.GetServices(typeof(IInterceptor)).ToArray();
            Assert.Equal(0, interceptors.Length);
        }
Пример #4
0
        public ActionResult ProcessShoppingCart(ShoppingCartObject cart, string subdomain)
        {
            try
            {
                if (cart == null || !cart.ShopingCartItemObjects.Any())
                {
                    return(Json(0, JsonRequestBehavior.AllowGet));
                }

                var store = new SessionHelpers().GetStoreInfo(subdomain);
                if (store == null || store.StoreId < 1)
                {
                    return(Json(new StoreItemStockObject(), JsonRequestBehavior.AllowGet));
                }

                if (string.IsNullOrEmpty(cart.CustomerIpAddress))
                {
                    cart.CustomerIpAddress = ClientIpHelper.GetClientIpAddress(Request);
                }

                cart.DateInitiated = DateTime.Now;
                var processStatus = new DefaultServices().ProcessShoppingCart(cart);

                return(Json(processStatus, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json(new StoreItemStockObject(), JsonRequestBehavior.AllowGet));
            }
        }
Пример #5
0
        public void Constructor_DefaultServicesInContainer()
        {
            // Arrange
            var config = new ProcessorConfiguration();

            // Act
            var defaultServices = new DefaultServices(config);

            // Assert
            Assert.IsType(typeof(DefaultCommandHandlerSelector), defaultServices.GetService(typeof(ICommandHandlerSelector)));
            Assert.IsType(typeof(DefaultCommandHandlerActivator), defaultServices.GetService(typeof(ICommandHandlerActivator)));
            Assert.IsType(typeof(DefaultCommandHandlerTypeResolver), defaultServices.GetService(typeof(ICommandHandlerTypeResolver)));
            Assert.IsType(typeof(DefaultAssembliesResolver), defaultServices.GetService(typeof(IAssembliesResolver)));
            Assert.IsType(typeof(DefaultInterceptionProvider), defaultServices.GetService(typeof(IInterceptionProvider)));

            object[] filterProviders = defaultServices.GetServices(typeof(IFilterProvider)).ToArray();
            Assert.Equal(2, filterProviders.Length);
            Assert.IsType(typeof(ConfigurationFilterProvider), filterProviders[0]);
            Assert.IsType(typeof(HandlerFilterProvider), filterProviders[1]);

            Assert.IsType(typeof(DefaultCommandValidator), defaultServices.GetService(typeof(ICommandValidator)));

            object[] interceptors = defaultServices.GetServices(typeof(IInterceptor)).ToArray();
            Assert.Equal(0, interceptors.Length);
        }
        public DefaultRepositoryServices()
        {
            Services = new DefaultServices()

                       //MasterData

                       .Add <IUserRepository, UserRepository>()
                       .Add <ICandidateRepository, CandidateRepository>()
                       .Add <IConstituencyRepository, ConstituencyRepository>()
                       .Add <ICountyRepository, CountyRepository>()
                       .Add <IElectionRepository, ElectionRepository>()
                       .Add <IPoliticalPartyRepository, PoliticalPartyRepository>()
                       .Add <IPollingCentreRepository, PollingCentreRepository>()
                       .Add <IRaceRepository, RaceRepository>()
                       .Add <IRegionRepository, RegionRepository>()
                       .Add <ISettingsRepository, SettingsRepository>()
                       .Add <IWardRepository, WardRepository>()

                       //Results
                       .Add <IPresidentialResultRepository, PresidentialResultRepository>()
                       .Add <IGubernatorialResultRepository, GubernatorialResultRepository>()
                       .Add <ISenatorialResultRepository, SenatorialResultRepository>()
                       .Add <IMpResultRepository, MpResultRepository>()
                       .Add <IWomenRepResultRepository, WomenRepResultRepository>()
                       .Add <IMcaResultRepository, McaResultRepository>()
                       .Add <IReferendumResultRepository, ReferendumResultRepository>()
            ;
        }
        public void Class_IsDefaultIAssembliesResolver()
        {
            var serviceResolver = new DefaultServices(new HttpConfiguration());

            Assert.IsType <DefaultAssembliesResolver>(
                serviceResolver.GetService(typeof(IAssembliesResolver))
                );
        }
Пример #8
0
 public ViewModelBuilderDefaultContracts()
 {
     Services = new DefaultServices()
                .Add <ICountyViewModelBuilder, CountyViewModelBuilder>()
                .Add <IRegionViewModelBuilder, RegionViewModelBuilder>()
                .Add <IConstituencyViewModelBuilder, ConstituencyViewModelBuilder>()
                .Add <IPoliticalPartyViewModelBuilder, PoliticalPartyViewModelBuilder>();
 }
Пример #9
0
        public void WhenGettingOrThrowUnknowServiceThenThrowsInvalidOperationException()
        {
            ProcessorConfiguration config = new ProcessorConfiguration();
            DefaultServices services = new DefaultServices(config);
            services.Replace(typeof(ICommandHandlerActivator), null);

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => services.GetServiceOrThrow<ICommandHandlerActivator>());
        }
Пример #10
0
        // Runtime code shouldn't call GetService() directly. Instead, have a wrapper (like the ones above) and call through the wrapper.
        private static TService GetService <TService>(this DefaultServices services)
        {
            if (services == null)
            {
                throw Error.ArgumentNull("services");
            }

            return((TService)services.GetService(typeof(TService)));
        }
Пример #11
0
        private static IEnumerable <TService> GetServices <TService>(this DefaultServices services)
        {
            if (services == null)
            {
                throw Error.ArgumentNull("services");
            }

            return(services.GetServices(typeof(TService)).Cast <TService>());
        }
Пример #12
0
        public UnifiedDefaultServices()
        {
            DefaultResultServices   defaultResultServices   = new DefaultResultServices();
            DefaultWorkflowServices defaultWorkflowServices = new DefaultWorkflowServices();

            Services = new DefaultServices();
            AddToServices(defaultResultServices);
            AddToServices(defaultWorkflowServices);
        }
Пример #13
0
        public void WhenGettingOrThrowUnknowServiceThenThrowsInvalidOperationException()
        {
            ProcessorConfiguration config   = new ProcessorConfiguration();
            DefaultServices        services = new DefaultServices(config);

            services.Replace(typeof(ICommandHandlerActivator), null);

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => services.GetServiceOrThrow <ICommandHandlerActivator>());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpConfiguration"/> class.
        /// </summary>
        /// <param name="routes">The <see cref="HttpRouteCollection"/> to associate with this instance.</param>
        public HttpConfiguration(HttpRouteCollection routes)
        {
            if (routes == null)
            {
                throw Error.ArgumentNull("routes");
            }

            _routes  = routes;
            Services = new DefaultServices(this);
        }
Пример #15
0
        public void GetServices_GuardClauses()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.GetServices(serviceType: null), "serviceType");
            ExceptionAssert.ThrowsArgument(() => defaultServices.GetServices(typeof(object)), "serviceType");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpConfiguration"/> class.
        /// </summary>
        /// <param name="routes">The <see cref="HttpRouteCollection"/> to associate with this instance.</param>
        public HttpConfiguration(HttpRouteCollection routes)
        {
            if (routes == null)
            {
                throw Error.ArgumentNull("routes");
            }

            _routes  = routes;
            Services = new DefaultServices(this);
            ParameterBindingRules = DefaultActionValueBinder.GetDefaultParameterBinders();
        }
Пример #17
0
        private static T GetServiceOrThrow <T>(this DefaultServices services)
        {
            T result = services.GetService <T>();

            if (result == null)
            {
                throw Error.InvalidOperation(SRResources.DependencyResolverNoService, typeof(T).FullName);
            }

            return(result);
        }
Пример #18
0
        public void RemoveAt_GuardClauses()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.RemoveAt(serviceType: null, index: 0), "serviceType");
            ExceptionAssert.ThrowsArgument(() => defaultServices.RemoveAt(typeof(object), 0), "serviceType");
            ExceptionAssert.ThrowsArgumentOutOfRange(() => defaultServices.RemoveAt(typeof(IFilterProvider), -1), "index");
        }
Пример #19
0
        public void RemoveAll_GuardClauses()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.RemoveAll(serviceType: null, match: _ => true), "serviceType");
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.RemoveAll(typeof(object), match: null), "match");
            ExceptionAssert.ThrowsArgument(() => defaultServices.RemoveAll(typeof(object), _ => true), "serviceType");
        }
Пример #20
0
        public void AddRange_GuardClauses()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.AddRange(serviceType: null, services: new[] { new object() }), "serviceType");
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.AddRange(typeof(object), services: null), "services");
            ExceptionAssert.ThrowsArgument(() => defaultServices.AddRange(typeof(object), new[] { new object() }), "serviceType");
            ExceptionAssert.ThrowsArgument(() => defaultServices.AddRange(typeof(IFilterProvider), new[] { new object() }), "services");
        }
Пример #21
0
        public void Add_GuardClauses()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.Add(serviceType: null, service: new object()), "serviceType");
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.Add(typeof(object), service: null), "service");
            ExceptionAssert.ThrowsArgument(() => defaultServices.Add(typeof(object), new object()), "serviceType");
            ExceptionAssert.ThrowsArgument(() => defaultServices.Add(typeof(IFilterProvider), new object()), "service");
        }
Пример #22
0
        public void Clear_RemovesAllServices()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act
            defaultServices.Clear(typeof(IFilterProvider));

            // Assert
            Assert.Equal(0, defaultServices.GetServices(typeof(IFilterProvider)).Count());
        }
Пример #23
0
        public void FindIndex_FailedFind()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act
            int index = defaultServices.FindIndex(typeof(IFilterProvider), _ => false);

            // Assert
            Assert.Equal(-1, index);
        }
Пример #24
0
        public void InsertRange_GuardClauses()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.InsertRange(serviceType: null, index: 0, services: new[] { new object() }), "serviceType");
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.InsertRange(typeof(object), 0, services: null), "services");
            ExceptionAssert.ThrowsArgument(() => defaultServices.InsertRange(typeof(object), 0, new[] { new object() }), "serviceType");
            ExceptionAssert.ThrowsArgument(() => defaultServices.InsertRange(typeof(IFilterProvider), 0, new[] { new object() }), "services");
            ExceptionAssert.ThrowsArgumentOutOfRange(() => defaultServices.InsertRange(typeof(IFilterProvider), -1, new[] { new Mock <IFilterProvider>().Object }), "index");
        }
Пример #25
0
        public ActionResult GetStateCities(long stateId, string subdomain)
        {
            var store = new SessionHelpers().GetStoreInfo(subdomain);

            if (store == null || store.StoreId < 1)
            {
                return(Json(new StoreItemStockObject(), JsonRequestBehavior.AllowGet));
            }

            var processStatus = new DefaultServices().GetStateCities(stateId);

            return(Json(processStatus, JsonRequestBehavior.AllowGet));
        }
Пример #26
0
        public void FindIndex_EmptyServiceListAlwaysReturnsFailure()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            defaultServices.Clear(typeof(IFilterProvider));

            // Act
            int index = defaultServices.FindIndex(typeof(IFilterProvider), _ => true);

            // Assert
            Assert.Equal(-1, index);
        }
Пример #27
0
        public void ReplaceRange_ReplacesAllValuesWithTheGivenServices()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock <IFilterProvider>().Object;
            var filterProvider2 = new Mock <IFilterProvider>().Object;

            // Act
            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Assert
            Assert.Equal(new[] { filterProvider1, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider)));
        }
Пример #28
0
        public void GetServices_ReturnsEmptyEnumerationWhenServiceListEmpty()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            defaultServices.Clear(typeof(IFilterProvider));

            // Act
            IEnumerable <object> services = defaultServices.GetServices(typeof(IFilterProvider));

            // Assert
            Assert.Equal(0, services.Count());
        }
Пример #29
0
        public void GetService_ReturnsNullWhenServiceListEmpty()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            defaultServices.Clear(typeof(ICommandHandlerSelector));

            // Act
            object service = defaultServices.GetService(typeof(ICommandHandlerSelector));

            // Assert
            Assert.Null(service);
        }
Пример #30
0
        public void AddRange_SkipsNullObjects()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            IEnumerable <object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));

            // Act
            defaultServices.AddRange(typeof(IFilterProvider), new object[] { null });

            // Assert
            IEnumerable <object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));

            Assert.Equal(servicesBefore.ToArray(), servicesAfter.ToArray());
        }
Пример #31
0
        private void GetService_PrefersServiceInDependencyInjectionContainer_Impl(IDependencyResolver resolver, TestActionValueBinder serviceInstance)
        {
            // Arrange
            HttpConfiguration  config          = new HttpConfiguration();
            DefaultServices    defaultServices = new DefaultServices(config);
            IActionValueBinder filterProvider  = serviceInstance;

            config.DependencyResolver = resolver;

            // Act
            object service = defaultServices.GetService(typeof(IActionValueBinder));

            // Assert
            Object.ReferenceEquals(filterProvider, service).ShouldBeTrue();
        }
Пример #32
0
        public void Add_AddsServiceToEndOfServicesList()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider = new Mock<IFilterProvider>().Object;
            IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));

            // Act
            defaultServices.Add(typeof(IFilterProvider), filterProvider);

            // Assert
            IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));
            Assert.Equal(servicesBefore.Concat(new[] { filterProvider }).ToArray(), servicesAfter.ToArray());
        }
Пример #33
0
        public void AddRange_AddsServicesToEndOfServicesList()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider  = new Mock <IFilterProvider>().Object;
            IEnumerable <object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));

            // Act
            defaultServices.AddRange(typeof(IFilterProvider), new[] { filterProvider });

            // Assert
            IEnumerable <object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));

            Assert.Equal(servicesBefore.Concat(new[] { filterProvider }).ToArray(), servicesAfter.ToArray());
        }
Пример #34
0
        public void RemoteAt_RemovesService()
        {
            // Arrange
            var config          = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock <IFilterProvider>().Object;
            var filterProvider2 = new Mock <IFilterProvider>().Object;

            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Act
            defaultServices.RemoveAt(typeof(IFilterProvider), 1);

            // Assert
            Assert.Equal(new[] { filterProvider1 }, defaultServices.GetServices(typeof(IFilterProvider)));
        }
Пример #35
0
        public void ReplaceRange_ReplacesAllValuesWithTheGivenServices()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock<IFilterProvider>().Object;
            var filterProvider2 = new Mock<IFilterProvider>().Object;

            // Act
            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Assert
            Assert.Equal(new[] { filterProvider1, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider)));
        }
Пример #36
0
        public void RemoteAt_RemovesService()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock<IFilterProvider>().Object;
            var filterProvider2 = new Mock<IFilterProvider>().Object;
            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Act
            defaultServices.RemoveAt(typeof(IFilterProvider), 1);

            // Assert
            Assert.Equal(new[] { filterProvider1 }, defaultServices.GetServices(typeof(IFilterProvider)));
        }
Пример #37
0
        public void RemoveAt_GuardClauses()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.RemoveAt(serviceType: null, index: 0), "serviceType");
            ExceptionAssert.ThrowsArgument(() => defaultServices.RemoveAt(typeof(object), 0), "serviceType");
            ExceptionAssert.ThrowsArgumentOutOfRange(() => defaultServices.RemoveAt(typeof(IFilterProvider), -1), "index");
        }
Пример #38
0
        public void GetServices_GuardClauses()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.GetServices(serviceType: null), "serviceType");
            ExceptionAssert.ThrowsArgument(() => defaultServices.GetServices(typeof(object)), "serviceType");
        }
Пример #39
0
        public void AddRange_SkipsNullObjects()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));

            // Act
            defaultServices.AddRange(typeof(IFilterProvider), new object[] { null });

            // Assert
            IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));
            Assert.Equal(servicesBefore.ToArray(), servicesAfter.ToArray());
        }
Пример #40
0
        public void InsertRange_GuardClauses()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.InsertRange(serviceType: null, index: 0, services: new[] { new object() }), "serviceType");
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.InsertRange(typeof(object), 0, services: null), "services");
            ExceptionAssert.ThrowsArgument(() => defaultServices.InsertRange(typeof(object), 0, new[] { new object() }), "serviceType");
            ExceptionAssert.ThrowsArgument(() => defaultServices.InsertRange(typeof(IFilterProvider), 0, new[] { new object() }), "services");
            ExceptionAssert.ThrowsArgumentOutOfRange(() => defaultServices.InsertRange(typeof(IFilterProvider), -1, new[] { new Mock<IFilterProvider>().Object }), "index");
        }
Пример #41
0
        public void GetService_ReturnsNullWhenServiceListEmpty()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            defaultServices.Clear(typeof(ICommandHandlerSelector));

            // Act
            object service = defaultServices.GetService(typeof(ICommandHandlerSelector));

            // Assert
            Assert.Null(service);
        }
Пример #42
0
        public void GetServices_CachesResultFromDependencyInjectionContainer()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var mockDependencyResolver = new Mock<IDependencyResolver>();
            config.DependencyResolver = mockDependencyResolver.Object;

            // Act
            defaultServices.GetServices(typeof(IFilterProvider));
            defaultServices.GetServices(typeof(IFilterProvider));

            // Assert
            mockDependencyResolver.Verify(dr => dr.GetServices(typeof(IFilterProvider)), Times.Once());
        }
Пример #43
0
        public void GetServices_PrependsServiceInDependencyInjectionContainer()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider));
            var filterProvider = new Mock<IFilterProvider>().Object;
            var mockDependencyResolver = new Mock<IDependencyResolver>();
            mockDependencyResolver.Setup(dr => dr.GetServices(typeof(IFilterProvider))).Returns(new[] { filterProvider });
            config.DependencyResolver = mockDependencyResolver.Object;

            // Act
            IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider));

            // Assert
            Assert.Equal(new[] { filterProvider }.Concat(servicesBefore).ToArray(), servicesAfter.ToArray());
        }
Пример #44
0
        public void GetServices_ReturnsEmptyEnumerationWhenServiceListEmpty()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            defaultServices.Clear(typeof(IFilterProvider));

            // Act
            IEnumerable<object> services = defaultServices.GetServices(typeof(IFilterProvider));

            // Assert
            Assert.Equal(0, services.Count());
        }
Пример #45
0
        protected virtual void Application_Start(Object sender, EventArgs e)
        {
            Started = DateTime.Now;

            // Init log system
            if (String.Compare (Environment.GetEnvironmentVariable ("GBRAINY_DEBUG"), "false", false) != 0)
            {
                Logger.LogLevel = Level.DEBUG;
                Logger.LogDevice = new FileLogger ();
            } else
            {
                Logger.LogLevel = Level.INFO;
                Logger.LogDevice = new ConsoleLogger ();
            }

            // Register services
            DefaultServices services = new DefaultServices ();
            services.RemoveService <ITranslations> ();
            services.RegisterServices ();

            ServiceLocator.Instance.RegisterService <ITranslations> (new TranslationsWeb ());
            ThemeManager.ConfigPath = Defines.THEMES_DIR;

            // Configuration
            ServiceLocator.Instance.GetService <IConfiguration> ().Set (ConfigurationKeys.GamesGraphics, "images/");
            ServiceLocator.Instance.GetService <IConfiguration> ().Set (ConfigurationKeys.AssembliesDir, "bin/");

            Logger.Info ("Global.Application_Start.gbrainy web starting");
        }
Пример #46
0
        public void RemoveAll_SuccessfulMatch()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock<IFilterProvider>().Object;
            var filterProvider2 = new Mock<IFilterProvider>().Object;
            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Act
            defaultServices.RemoveAll(typeof(IFilterProvider), _ => true);

            // Assert
            Assert.Equal(0, defaultServices.GetServices(typeof(IFilterProvider)).Count());
        }
Пример #47
0
        public void InsertRange_AddsElementAtTheRequestedLocation()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock<IFilterProvider>().Object;
            var filterProvider2 = new Mock<IFilterProvider>().Object;
            var newFilterProvider1 = new Mock<IFilterProvider>().Object;
            var newFilterProvider2 = new Mock<IFilterProvider>().Object;
            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Act
            defaultServices.InsertRange(typeof(IFilterProvider), 1, new[] { newFilterProvider1, newFilterProvider2 });

            // Assert
            Assert.Equal(new[] { filterProvider1, newFilterProvider1, newFilterProvider2, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider)));
        }
Пример #48
0
        public void GetService_PrefersServiceInDependencyInjectionContainer()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider = new Mock<ICommandHandlerSelector>().Object;
            var mockDependencyResolver = new Mock<IDependencyResolver>();
            mockDependencyResolver.Setup(dr => dr.GetService(typeof(ICommandHandlerSelector))).Returns(filterProvider);
            config.DependencyResolver = mockDependencyResolver.Object;

            // Act
            object service = defaultServices.GetService(typeof(ICommandHandlerSelector));

            // Assert
            Assert.Same(filterProvider, service);
        }
Пример #49
0
        public void Remove_ObjectNotFound()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            var filterProvider1 = new Mock<IFilterProvider>().Object;
            var filterProvider2 = new Mock<IFilterProvider>().Object;
            var notPresentFilterProvider = new Mock<IFilterProvider>().Object;
            defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 });

            // Act
            defaultServices.Remove(typeof(IFilterProvider), notPresentFilterProvider);

            // Assert
            Assert.Equal(new[] { filterProvider1, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider)));
        }
Пример #50
0
        public void RemoveAll_GuardClauses()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act & assert
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.RemoveAll(serviceType: null, match: _ => true), "serviceType");
            ExceptionAssert.ThrowsArgumentNull(() => defaultServices.RemoveAll(typeof(object), match: null), "match");
            ExceptionAssert.ThrowsArgument(() => defaultServices.RemoveAll(typeof(object), _ => true), "serviceType");
        }
Пример #51
0
        public void FindIndex_FailedFind()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act
            int index = defaultServices.FindIndex(typeof(IFilterProvider), _ => false);

            // Assert
            Assert.Equal(-1, index);
        }
Пример #52
0
        public void Clear_RemovesAllServices()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);

            // Act
            defaultServices.Clear(typeof(IFilterProvider));

            // Assert
            Assert.Equal(0, defaultServices.GetServices(typeof(IFilterProvider)).Count());
        }
Пример #53
0
        public void FindIndex_EmptyServiceListAlwaysReturnsFailure()
        {
            // Arrange
            var config = new ProcessorConfiguration();
            var defaultServices = new DefaultServices(config);
            defaultServices.Clear(typeof(IFilterProvider));

            // Act
            int index = defaultServices.FindIndex(typeof(IFilterProvider), _ => true);

            // Assert
            Assert.Equal(-1, index);
        }
Пример #54
0
 public Configuration()
 {
     Services = new DefaultServices(this);
 }