public void Can_create_ClassWithAResolvableContructors() { var request = new ClassWithIntConstructor(1); var factory = new FactoryProvider(); factory.Register(new HttpRequestContext(request, null)); factory.Register(new BasicApplicationContext(null, null, null)); var typeFactory = CreateWithFactory(factory); var result = typeFactory.Create(typeof(ClassWithAResolvableContructors)); var newInstance = result as ClassWithAResolvableContructors; Assert.That(newInstance, Is.Not.Null); Assert.That(newInstance.RequestContext, Is.Not.Null); Assert.That(newInstance.ApplicationContext, Is.Not.Null); var resolvedRequest = ((HttpRequestContext)newInstance.RequestContext).Dto as ClassWithIntConstructor; Assert.That(resolvedRequest, Is.Not.Null); Assert.That(resolvedRequest.IntValue, Is.EqualTo(1)); }
public void TryGetBuilder2() { var provider = new FactoryProvider(); var collection = new FactoryCollection <Type>(); var factory = new Factory <string>(); factory.Add("empty", new GameObjectBuilderEmpty()); factory.Add("prefab", new GameObjectBuilder(new GameObject("prefab"))); collection.Add(typeof(IGameObjectBuilder), factory); provider.Add(collection); bool result1 = provider.TryGetBuilder(typeof(IGameObjectBuilder), "empty", out IGameObjectBuilder builder1); bool result2 = provider.TryGetBuilder(typeof(IGameObjectBuilder), "prefab", out IGameObjectBuilder builder2); bool result3 = provider.TryGetBuilder(typeof(int), "empty", out IBuilder builder3); bool result4 = provider.TryGetBuilder(typeof(IGameObjectBuilder), "prefab2", out IGameObjectBuilder builder4); Assert.True(result1); Assert.True(result2); Assert.False(result3); Assert.False(result4); Assert.NotNull(builder1); Assert.NotNull(builder2); Assert.Null(builder3); Assert.Null(builder4); }
public IEnumerable <User> GetAll() { var factory = FactoryProvider.GetDataFactory(); var repository = factory.CreateUserRepository(); return(repository.GetAll()); }
public void CreateTest() { IFile XmlFile = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.xml); Student addedStudent = XmlFile.Create(student); Assert.AreEqual(student, addedStudent); }
public User Insert(User user) { var factory = FactoryProvider.GetDataFactory(); var repository = factory.CreateUserRepository(); return(repository.Insert(user)); }
public void A_registered_db4o_provider_manager_can_be_resolved() { var db4oProvider = new Db4OFileProviderManager("test.db4o"); var factory = new FactoryProvider(this.factoryConfig); factory.Register(db4oProvider); var provider = factory.Resolve<IPersistenceProviderManager>(); }
private AppHost() { LogManager.LogFactory = new Log4NetFactory(true); var factory = new FactoryProvider(FactoryUtils.ObjectFactory, LogManager.LogFactory); var providerManager = new Db4oFileProviderManager(Config.ConnectionString); var configDb4o = Db4oFactory.Configure(); configDb4o.ActivationDepth(5); configDb4o.UpdateDepth(5); configDb4o.OptimizeNativeQueries(true); factory.Register(providerManager); //Keep the manager from disposing providers it created factory.Register(providerManager.GetProvider()); // Create the ApplicationContext injected with the static service implementations ApplicationContext.SetInstanceContext(new ApplicationContext { Factory = factory, Cache = new MemoryCacheClient(), Resources = new ConfigurationResourceManager(), }); SetConfig(new EndpointHostConfig { ServiceName = Config.ServiceName, OperationsNamespace = Config.OperationNamespace, ServiceModelFinder = ServiceModelFinder.Instance, ServiceController = new ServiceController(new ServiceResolver()), }); }
/// <summary> /// EditarUsuarioAsync /// </summary> /// <returns>JsonResult</returns> /// <author>Oscar Julian Rojas Garces</author> /// <date>26/06/2020</date> public async Task <object> EditarUsuarioAsync(UsuarioViewModel usuario) { string uripeticion = "http://localhost:5002/manage"; var peticiones = FactoryProvider.CrearProvider(_config, _cache, uripeticion); return(await peticiones.PutAsync <object>(usuario)); }
public void A_non_existant_provider_returns_null() { var factory = new FactoryProvider(this.factoryConfig); var config = factory.Resolve <IResourceManager>(); Assert.That(config, Is.Null); }
/// <summary> /// ObtenerUsuarioAsync /// </summary> /// <returns>Usuario</returns> /// <author>Oscar Julian Rojas Garces</author> /// <date>26/06/2020</date> public async Task <Usuario> ObtenerUsuarioAsync(string Id) { string uripeticion = $"http://localhost:5002/manage/{Id}"; var peticiones = FactoryProvider.CrearProvider(_config, _cache, uripeticion); return(await peticiones.GetAsync <Usuario>()); }
/// <summary> /// ObtenerUsuarioAsync /// </summary> /// <returns>Lista de usuarios</returns> /// <author>Oscar Julian Rojas Garces</author> /// <date>26/06/2020</date> public async Task <IReadOnlyList <Usuario> > ObtenerUsuariosAsync() { string uripeticion = "http://localhost:5002/manage"; var peticiones = FactoryProvider.CrearProvider(_config, _cache, uripeticion); return(await peticiones.GetAsync <IReadOnlyList <Usuario> >()); }
public void ClassWithResolvableAndMultipleContructors_should_pick_contructor_with_most_params() { var request = new ClassWithIntConstructor(1); var factory = new FactoryProvider(); factory.Register(new HttpRequestContext(request, null)); factory.Register(new BasicApplicationContext(null, null, null)); var typeFactory = CreateWithFactory(factory); var result = typeFactory.Create(typeof(ClassWithResolvableAndMultipleContructors)); var newInstance = result as ClassWithResolvableAndMultipleContructors; Assert.That(newInstance, Is.Not.Null); Assert.That(newInstance.RequestContext, Is.Not.Null); Assert.That(newInstance.ApplicationContext, Is.Not.Null); Assert.That(newInstance.IntValue, Is.EqualTo(default(int))); var resolvedRequest = ((HttpRequestContext)newInstance.RequestContext).Dto as ClassWithIntConstructor; Assert.That(resolvedRequest, Is.Not.Null); Assert.That(resolvedRequest.IntValue, Is.EqualTo(1)); }
private TypeDiscovery(params string[] paths) { _factoryProvider = new FactoryProvider(); _paths = new HashSet <string>(); if (paths == null) { paths = new string[] { } } ; ExcludedAssemblies = new List <string>(); FilterAssembly = c => true; FilterFilename = c => true; Assemblies = () => AppDomain.CurrentDomain.GetAssemblies() .Where(c => !ExcludedAssemblies.Contains(c.GetName().Name) ).ToList(); //OnRegisterException = e => Logger.Error(e); HideAssemblyLoadException = true; var dir = FolderBinResolver.IsWebApplication() ? FolderBinResolver.GetWebBinPath().ToList() : FolderBinResolver.GetConsoleBinPath().ToList(); AddDirectories(dir.Where(c => c.Exists).ToArray()); AddDirectories(paths); }
static void Main(string[] args) { var factory = FactoryProvider.GetFactory(ConfigurationManager.AppSettings["OS"]); var app = new Application(factory); app.Start(); }
public void A_registered_db4o_provider_manager_can_be_resolved() { var db4oProvider = new Db4OFileProviderManager("test.db4o"); var factory = new FactoryProvider(this.factoryConfig); factory.Register(db4oProvider); var provider = factory.Resolve <IPersistenceProviderManager>(); }
public void Count() { var provider = new FactoryProvider(); provider.Add(new FactoryCollection <int>()); Assert.AreEqual(1, provider.Collections.Count); }
/// <summary> /// EliminarUsuarioAsync /// </summary> /// <returns>JsonResult</returns> /// <author>Oscar Julian Rojas Garces</author> /// <date>26/06/2020</date> public async Task <object> EliminarUsuarioAsync(string Id) { string uripeticion = $"http://localhost:5002/manage/{Id}"; var peticiones = FactoryProvider.CrearProvider(_config, _cache, uripeticion); var usuario = await peticiones.GetAsync <Usuario>(); return(await peticiones.DeleteAsync <Usuario>(usuario)); }
public void A_config_provider_is_resolvable_by_type() { var provider = new FactoryProvider(factoryConfig); var resolvedGateway = provider.Resolve<TestGateway>(); Assert.That(resolvedGateway, Is.Not.Null); var xmlServiceClient = (XmlServiceClient)resolvedGateway.ServiceClient; Assert.That(xmlServiceClient.BaseUri, Is.EqualTo("http://mock.org/service.svc")); }
//################################################################################ #region Constructor public Client(CountryCode countryCode) { this.m_Factory = FactoryProvider.CreateFactory(countryCode); this.m_Address = this.m_Factory.CreateAddressFormat(); this.m_PhoneNumber = this.m_Factory.CreatePhoneNumberFormat(); this.m_LicencePlate = this.m_Factory.CreateLicencePlateFormat(); }
private void BtnList_Click(object sender, EventArgs e) { string choice = "VuelingFile"; var factory = FactoryProvider.getFactory(choice); var fileFactory = factory.Create((ComboBox.SelectedItem.ToString())); MessageBox.Show(fileFactory.List()); }
public void can_produce_factory() { FactoryProvider<IWeapon> factoryProvider = new FactoryProvider<IWeapon>(); object result = factoryProvider.Create(contextMock.Object); Assert.IsAssignableFrom(typeof(Func<IWeapon>), result); }
public void DeleteTest() { IFile textFile = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.txt); Student newStudent = textFile.Create(student); Assert.IsTrue(textFile.Delete(newStudent)); }
private void BtnUpdate_Click(object sender, EventArgs e) { Student student = new Student(int.Parse(txtBoxStudentId.Text), txtBoxName.Text, txtBoxSurname.Text, DateTime.Parse(txtBoxBirthDate.Text)); string choice = "VuelingFile"; var factory = FactoryProvider.getFactory(choice); var fileFactory = factory.Create((ComboBox.SelectedItem.ToString())); fileFactory.Update(student); }
public void AllTest() { IFile textFile = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.txt); Student newStudent = textFile.Create(student); Student newStudent2 = textFile.Create(student2); Assert.AreEqual(newStudent.Name, textFile.All()[0].Name); Assert.AreEqual(newStudent2.Name, textFile.All()[1].Name); }
public void CreatesTest() { IFile textFile = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.txt); Student newStudent = textFile.Create(student); Assert.AreEqual(student, newStudent); }
public void A_registered_provider_is_resolvable_by_an_interface_type() { var gateway = new TestGateway(new XmlServiceClient("http://mock.org/service.svc")); var provider = new FactoryProvider(gateway); var resolvedGateway = provider.Resolve<ITestGateway>(); Assert.That(resolvedGateway, Is.Not.Null); var xmlServiceClient = (XmlServiceClient)resolvedGateway.ServiceClient; Assert.That(xmlServiceClient.BaseUri, Is.EqualTo("http://mock.org/service.svc")); }
static void Main(string[] args) { IFactory f = FactoryProvider.GetFactory("fs"); f.GetLogger().Log("Hello"); IFactory f2 = FactoryProvider.GetFactory("db"); f2.GetLogger().Log("Hallo"); }
public void factory_uses_kernel_for_each() { kernel.Bind<IWeapon>().To<Sword>(); FactoryProvider<IWeapon> factoryProvider = new FactoryProvider<IWeapon>(); var result = (Func<IWeapon>)factoryProvider.Create(contextMock.Object); Assert.NotEqual(result(), result()); }
public void ContainsKey() { var provider = new FactoryProvider(); provider.Add(new FactoryCollection <int>()); bool result = provider.Collections.ContainsKey(typeof(int)); Assert.True(result); }
public void Remove() { var provider = new FactoryProvider(); var collection = new FactoryCollection <int>(); provider.Add(collection); provider.Remove(collection); Assert.AreEqual(0, provider.Collections.Count); }
public void GetGeneric() { var provider = new FactoryProvider(); provider.Add(new FactoryCollection <int>()); IFactoryCollection <int> collection = provider.Get <int>(); Assert.NotNull(collection); }
private static void Commands() { Student student = new Student(10, "Sergi", "Virgilius", 2000); Student student2 = new Student(11, "VIRIVIR", "asdasad", 2012); IFile file = FactoryProvider.getFactory(PersitenseTypes. FILE).Create(FileTypes.txt); file.Delete(student2); }
public void A_RsaPrivateKey_can_be_created_and_configured_in_code() { var privateKey = new RsaPrivateKey(ConfigUtils.GetAppSetting("ServerPrivateKey")); var factory = new FactoryProvider(this.factoryConfig); factory.Register(privateKey); var resolvedPrivateKey = factory.Resolve <RsaPrivateKey>(); Assert.That(resolvedPrivateKey, Is.Not.Null); }
public CosmeticMenu() { FactoryProvider prov = new FactoryProvider(); cosRepos = prov.GetFactory().GetCosmeticRepository(); cart = prov.GetFactory().GetCartRepository(); //cart. //cart = new CartFileRepository(); factory = new FlyweightFactory(); }
public void A_config_provider_is_resolvable_by_an_interface_type() { var provider = new FactoryProvider(factoryConfig); var resolvedGateway = provider.Resolve <ITestGateway>(); Assert.That(resolvedGateway, Is.Not.Null); var xmlServiceClient = (XmlServiceClient)resolvedGateway.ServiceClient; Assert.That(xmlServiceClient.BaseUri, Is.EqualTo("http://mock.org/service.svc")); }
public void factory_uses_kernel() { var expectedWeapon = new Sword(); kernel.Bind<IWeapon>().ToConstant(expectedWeapon); FactoryProvider<IWeapon> factoryProvider = new FactoryProvider<IWeapon>(); var result = (Func<IWeapon>)factoryProvider.Create(contextMock.Object); Assert.Equal(expectedWeapon, result()); }
public void Create_ReturnsTheSpecifiedElementFactoryClass(string requestedTypeId, Type expectedType) { Guid typeId = new Guid(requestedTypeId); DefinitionProvider dp = new DefinitionProvider(); IElementDefinition def = dp.GetDefinition(typeId); FactoryProvider fp = new FactoryProvider(); IElementFactory fac = fp.Create(def); Assert.NotNull(fac); Assert.IsType(expectedType,fac); }
public void GetAllFactories_ReturnsAListOfFactories( int expectedCount) { var fp = new FactoryProvider(); IList<IElementFactory> factories = fp.GetAllFactories(); foreach (IElementFactory factory in factories) { Console.WriteLine(string.Format("{0}", factory.GetType().Name)); } Assert.NotNull(factories); Assert.Equal(expectedCount, factories.Count); foreach (IElementFactory factory in factories) { Assert.NotNull(factory); } }
public void PortResolver_can_inject_dependencies_in_handlers_contructor() { var requestContext = new HttpRequestContext(new GetCustomer { CustomerId = 1 }, null); var factory = new FactoryProvider(requestContext); var resolver = new PortResolver(GetType().Assembly) { HandlerFactory = new CreateFromLargestConstructorTypeFactory(factory).Create }; var handler = resolver.FindService(typeof(GetCustomer).Name) as GetCustomerHandler; Assert.That(handler, Is.Not.Null); Assert.That(handler.RequestContext, Is.Not.Null); var requestDto = ((HttpRequestContext)handler.RequestContext).Dto as GetCustomer; Assert.That(requestDto, Is.Not.Null); Assert.That(requestDto.CustomerId, Is.EqualTo(1)); }
public FactoryProviderHandlerFactory(FactoryProvider factoryProvider) { this.constructorTypeFactory = new CreateFromLargestConstructorTypeFactory(factoryProvider); }
public static void Default(IRegistry registry) { registry.ResolutionRules.UnregisteredServices = registry.ResolutionRules.UnregisteredServices.Append( ResolveEnumerableAsStaticArray, ResolveManyDynamically); var funcFactory = new FactoryProvider( (_, __) => new DelegateFactory(GetFuncExpression, Reuse.Singleton), GenericWrapperSetup.With(t => t[t.Length - 1])); foreach (var funcType in FuncTypes) registry.Register(funcType, funcFactory); var lazyFactory = new ReflectionFactory(typeof(Lazy<>), getConstructor: t => t.GetConstructor(new[] { typeof(Func<>).MakeGenericType(t.GetGenericArguments()) }), setup: GenericWrapperSetup.Default); registry.Register(typeof(Lazy<>), lazyFactory); var metaFactory = new FactoryProvider(GetMetaFactoryOrDefault, GenericWrapperSetup.With(t => t[0])); registry.Register(typeof(Meta<,>), metaFactory); var debugExprFactory = new FactoryProvider( (_, __) => new DelegateFactory(GetDebugExpression), GenericWrapperSetup.Default); registry.Register(typeof(DebugExpression<>), debugExprFactory); }
public CreateFromLargestConstructorTypeFactory(FactoryProvider factoryProvider) { this.factoryProvider = factoryProvider; }
private static CreateFromLargestConstructorTypeFactory CreateWithFactory(FactoryProvider factoryProvider) { return new CreateFromLargestConstructorTypeFactory(factoryProvider); }
public void A_non_existant_provider_returns_null() { var factory = new FactoryProvider(this.factoryConfig); var config = factory.Resolve<IResourceManager>(); Assert.That(config, Is.Null); }
public void A_RsaPrivateKey_can_be_created_and_configured_in_code() { var privateKey = new RsaPrivateKey(ConfigUtils.GetAppSetting("ServerPrivateKey")); var factory = new FactoryProvider(this.factoryConfig); factory.Register(privateKey); var resolvedPrivateKey = factory.Resolve<RsaPrivateKey>(); Assert.That(resolvedPrivateKey, Is.Not.Null); }