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(); } }
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"); }
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 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)); } }
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)) ); }
public ViewModelBuilderDefaultContracts() { Services = new DefaultServices() .Add <ICountyViewModelBuilder, CountyViewModelBuilder>() .Add <IRegionViewModelBuilder, RegionViewModelBuilder>() .Add <IConstituencyViewModelBuilder, ConstituencyViewModelBuilder>() .Add <IPoliticalPartyViewModelBuilder, PoliticalPartyViewModelBuilder>(); }
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>()); }
// 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))); }
private static IEnumerable <TService> GetServices <TService>(this DefaultServices services) { if (services == null) { throw Error.ArgumentNull("services"); } return(services.GetServices(typeof(TService)).Cast <TService>()); }
public UnifiedDefaultServices() { DefaultResultServices defaultResultServices = new DefaultResultServices(); DefaultWorkflowServices defaultWorkflowServices = new DefaultWorkflowServices(); Services = new DefaultServices(); AddToServices(defaultResultServices); AddToServices(defaultWorkflowServices); }
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); }
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(); }
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); }
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"); }
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"); }
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"); }
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"); }
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()); }
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); }
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"); }
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)); }
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); }
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))); }
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()); }
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); }
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()); }
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(); }
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()); }
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()); }
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))); }
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))); }
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))); }
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"); }
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"); }
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()); }
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"); }
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); }
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()); }
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()); }
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()); }
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"); }
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()); }
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))); }
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); }
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))); }
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"); }
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); }
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()); }
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); }
public Configuration() { Services = new DefaultServices(this); }