Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public IEnumerable <User> GetAll()
        {
            var factory    = FactoryProvider.GetDataFactory();
            var repository = factory.CreateUserRepository();

            return(repository.GetAll());
        }
Esempio n. 4
0
        public void CreateTest()
        {
            IFile   XmlFile      = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.xml);
            Student addedStudent = XmlFile.Create(student);

            Assert.AreEqual(student, addedStudent);
        }
Esempio n. 5
0
        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>();
 }
Esempio n. 7
0
        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()),
            });
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 10
0
        /// <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>());
        }
Esempio n. 11
0
        /// <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> >());
        }
Esempio n. 12
0
        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));
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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()),
            });
        }
Esempio n. 15
0
        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);
        }
Esempio n. 18
0
        /// <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"));
 }
Esempio n. 20
0
        //################################################################################

        #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();
        }
Esempio n. 21
0
        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());
        }
Esempio n. 22
0
        public void can_produce_factory()
        {
            FactoryProvider<IWeapon> factoryProvider = new FactoryProvider<IWeapon>();

            object result = factoryProvider.Create(contextMock.Object);

            Assert.IsAssignableFrom(typeof(Func<IWeapon>), result);
        }
Esempio n. 23
0
        public void DeleteTest()
        {
            IFile textFile = FactoryProvider.getFactory(PersitenseTypes.FILE).Create(FileTypes.txt);

            Student newStudent = textFile.Create(student);

            Assert.IsTrue(textFile.Delete(newStudent));
        }
Esempio n. 24
0
        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);
        }
Esempio n. 25
0
        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);
        }
Esempio n. 26
0
        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"));
 }
Esempio n. 28
0
        static void Main(string[] args)
        {
            IFactory f = FactoryProvider.GetFactory("fs");

            f.GetLogger().Log("Hello");

            IFactory f2 = FactoryProvider.GetFactory("db");

            f2.GetLogger().Log("Hallo");
        }
Esempio n. 29
0
        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);
        }
Esempio n. 33
0
        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);
        }
Esempio n. 35
0
        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"));
        }
Esempio n. 37
0
        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());
        }
Esempio n. 38
0
        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);
        }
Esempio n. 39
0
        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 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 FactoryProviderHandlerFactory(FactoryProvider factoryProvider)
		{
			this.constructorTypeFactory = new CreateFromLargestConstructorTypeFactory(factoryProvider);
		}
Esempio n. 43
0
        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;
		}
        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 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);
 }