public void RegisterServices(Container container)
        {
            var serviceAssemblies = new[]
            {
                typeof(IService).Assembly,
                Assembly.Load(AssemblyConstants.ServicesData),
                Assembly.Load(AssemblyConstants.ServicesAdministration),
            };

            var registrations = serviceAssemblies
                .SelectMany(a => a.GetExportedTypes())
                .Where(t => typeof(IService).IsAssignableFrom(t) && !t.IsAbstract && !t.IsGenericTypeDefinition)
                .Select(t => new { Service = t.GetInterfaces().Single(i => i != typeof(IService)), Implementation = t })
                .ToList();

            var webRequestLifestyle = new WebRequestLifestyle();
            foreach (var registration in registrations)
            {
                container.AddRegistration(
                    registration.Service,
                    webRequestLifestyle.CreateRegistration(registration.Service, registration.Implementation, container));
            }

            //// TODO: Register with LINQ!

            ////container.Register<ICacheService, HttpRuntimeCacheService>(webRequestLifestyle);
            ////container.Register<ICacheItemsProviderService, CacheItemsProviderService>(webRequestLifestyle);
            ////container.Register<ITagsDataService, TagsDataService>(webRequestLifestyle);
            ////container.Register<IPostsDataService, PostsDataService>(webRequestLifestyle);
            ////container.Register<ICommentsDataService, CommentsDataService>(webRequestLifestyle);
        }
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            var metadataProviderContributorsAssemblies = new[] { typeof (QueryProcessor).Assembly };

                container.Register(AllTypes.From(metadataProviderContributorsAssemblies.SelectMany(a => a.GetExportedTypes()))
                               	.Where(t => t.Name.EndsWith("Handler") && t.IsAbstract == false)
                               	.Configure(x => x.LifestyleSingleton())
                );
            container.Register(Component.For<IProcessQuery>().ImplementedBy<QueryProcessor>().LifeStyle.Singleton);
            container.Register(Component.For<IProcessCommand>().ImplementedBy<CommandProcessor>().LifeStyle.Singleton);
        }
		public void GeoShapeLineString_Deserializes()
		{
			var coordinates = new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } };

			var q = this.SerializeThenDeserialize(
				f => f.GeoShape,
				f => f.GeoShapeLineString(gq => gq
					.OnField(p => p.MyGeoShape)
					.Coordinates(coordinates)
					)
				);

			var query = q as IGeoShapeLineStringQuery;
			query.Should().NotBeNull();
			query.Field.Should().Be("myGeoShape");
			query.Shape.Should().NotBeNull();
			query.Shape.Type.Should().Be("linestring");
			query.Shape.Coordinates.SelectMany(c => c).Should()
				.BeEquivalentTo(coordinates.SelectMany(c => c));
		}
        public void Execute(DataSetCollection dataSets)
        {
            var export = Wiki;

            // Pages des listes d'objets
            var objectLists = new[]
            {
                "pathfinder-rpg.objets merveilleux",
                "pathfinder-rpg.objets merveilleux apg"
            }.Select(pn => export.Pages[new WikiName(pn)]);

            // Liste des pages décrivant des objets magiques
            var objectPages = objectLists
                .SelectMany(p => p.OutLinks)
                .Distinct()
                .ToList();

            // Feats dataset
            //var ds = dataSets.ResolveDataSet("feats");
        }
		public void GeoShapeMultiLineString_Deserializes()
		{
			var coordinates = new[] 
			{ 
				new[] { new[] { 102.0, 2.0 }, new[] { 103.0, 2.0 }, new[] { 103.0, 3.0 }, new[] { 102.0, 3.0 } },
				new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 } },
				new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 } } 
			};

			var q = this.SerializeThenDeserialize(
				f => f.GeoShape,
				f => f.GeoShapeMultiLineString(gq => gq
					.OnField(p => p.MyGeoShape)
					.Coordinates(coordinates)
					)
				);

			var query = q as IGeoShapeMultiLineStringQuery;
			query.Should().NotBeNull();
			query.Field.Should().Be("myGeoShape");
			query.Shape.Should().NotBeNull();
			query.Shape.Type.Should().Be("multilinestring");
			query.Shape.Coordinates.SelectMany(c => c.SelectMany(cc => cc)).Should()
				.BeEquivalentTo(coordinates.SelectMany(c => c.SelectMany(cc => cc)));
		}
        //public class A
        //{
        //    public string Name { get; set; }
        //}
        public static void Test(Assert assert)
        {
            assert.Expect(8);

            // TEST
            var numbers = new[] { 1, 3, 5, 7 };
            var numberPlusOne = (from n in numbers select n + 1).ToArray();
            assert.DeepEqual(numberPlusOne, new[] { 2, 4, 6, 8 }, "A sequence of ints one higher than the numbers[]");

            // TEST
            var persons = Person.GetPersons();
            var names = (from p in persons select p.Name).ToArray();
            assert.DeepEqual(names, new[] { "Frank", "Zeppa", "John", "Billy", "Dora", "Ian", "Mary", "Nemo" }, "Selects names as instance field");

            // TEST
            string[] strings = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

            var textNumbers = (from n in numbers select strings[n]).ToArray();
            assert.DeepEqual(textNumbers, new[] { "one", "three", "five", "seven" }, "Selects names as items of another array");

            // TEST
            var anonimNames = (from p in persons select new { Name = p.Name }).ToArray();

            object[] anonimNamesToCompare = {
                                                new { Name = "Frank" }, new { Name = "Zeppa" }, new { Name = "John" },
                                                new { Name = "Billy" }, new { Name = "Dora" }, new { Name = "Ian" },
                                                new { Name = "Mary" }, new { Name = "Nemo" } };

            assert.DeepEqual(anonimNames, anonimNamesToCompare, "Selects names as an anonymous type");

            // TEST
            numbers = new[] { 0, 1, 3, 3 };

            var numberssInPlace = numbers
                                    .Select((n, index) => new
                                        {
                                            Number = n,
                                            IsIndex = n == index
                                        })
                                    .ToArray();

            object[] anonimNumbersToCompare = { new { Number = 0, IsIndex = true },
                                                  new { Number = 1, IsIndex = true },
                                                  new { Number = 3, IsIndex = false },
                                                  new { Number = 3, IsIndex = true }
                                              };

            assert.DeepEqual(numberssInPlace, anonimNumbersToCompare, "Selects numbers as an anonymous type");

            // TEST
            var numbersA = new[] { 1, 5, 2 };
            var numbersB = new[] { 3, 4, 2 };
            var simplePairs =
                (from a in numbersA
                 from b in numbersB
                 where a < b
                 select new { A = a, B = b }
                ).ToArray();

            object[] expectedSimplePairs = { new { A = 1, B = 3 }, new { A = 1, B = 4 }, new { A = 1, B = 2 }, new { A = 2, B = 3 }, new { A = 2, B = 4 } };

            assert.DeepEqual(simplePairs, expectedSimplePairs, "Join two numeric arrays with one where clause");

            // TEST
            numbersA = new[] { 1, 5, 2, 4, 3 };
            numbersB = new[] { 3, 4, 2, 5, 1 };

            var pairs =
                (from a in numbersA
                where a > 1
                from b in numbersB
                where b < 4 && a > b
                select new { Sum = a + b }
                ).ToArray();

            object[] expectedPairs = { new { Sum = 8}, new { Sum = 7}, new { Sum = 6}, new { Sum = 3},
                                     new { Sum = 7}, new { Sum = 6}, new { Sum = 5},
                                     new { Sum = 5}, new { Sum = 4},};

            assert.DeepEqual(pairs, expectedPairs, "Join two numeric arrays with two where clauses");

            // TEST
            numbersA = new[] { 1, 5, 2, 4, 3 };
            numbersB = new[] { 3, 4, 2, 5, 1 };

            var manyNumbers = numbersA
                .SelectMany((a, aIndex) => numbersB.Where(b => a == b && b > aIndex).Select(b => new { A = a, B = b, I = aIndex }))
                .ToArray();

            object[] expectedManyNumbers = { new { A = 1, B = 1, I = 0 },
                                           new { A = 5, B = 5, I = 1 },
                                           new { A = 4, B = 4, I = 3 }};

            assert.DeepEqual(manyNumbers, expectedManyNumbers, "SelectMany() two number arrays");
        }
 public void DuplicateAttributes_SingleProperty_SameKey_ThrowsException()
 {
     var model = new[] { typeof(ModelWithDuplicateResourceKeys) };
     Assert.Throws<DuplicateResourceKeyException>(() => model.SelectMany(t => _sut.ScanResources(t)).ToList());
 }
 public void DuplicateAttributes_DiffProperties_SameKey_ThrowsException()
 {
     var model = new[] { typeof(BadResourceWithDuplicateKeysWithinClass) };
     Assert.Throws<DuplicateResourceKeyException>(() => model.SelectMany(t => _sut.ScanResources(t)).ToList());
 }
        public void StructureIntegrity()
        {
            RedBlackTree<int, int> tree = new RedBlackTree<int, int>();

            int range = 10;
            int[] order = new[] { 1, 3, 2, 5, 6 };

            var q = order
                .SelectMany(x => Enumerable.Range((x - 1) * range + 1, range));


            foreach (int i in q)
            {
                Assert.IsFalse(tree.ContainsKey(i));

                tree.Add(i, i);

                AssertStructure(tree.RootElement);
                Assert.IsTrue(tree.ContainsKey(i));
            }

            foreach (int i in q)
            {
                AssertStructure(tree.RootElement);
                Assert.IsTrue(tree.ContainsKey(i));

                tree.Remove(i);

                Assert.IsFalse(tree.ContainsKey(i));
            }

        }
        protected override void Load(ContainerBuilder builder)
        {
            var assemblies = new[] { typeof(LanguageModule).Assembly, _executingAssembly };

            builder.RegisterType<ProgramState>().AsSelf().SingleInstance();

            builder.RegisterAssemblyTypes(assemblies)
                .Where(t => t.GetInterfaces().Contains(typeof(IProgramBody)))
                .AsSelf()
                .InstancePerDependency();

            // values

            var genericValueProviderTypes = assemblies.SelectMany(a => a.GetTypes()
                    .Where(t => t.IsGenericType && t.GetInterfaces().Contains(typeof(IValueProvider))));
            var nonGenericValueProviderTypes = assemblies.SelectMany(a => a.GetTypes()
                    .Where(t => !t.IsGenericType && t.GetInterfaces().Contains(typeof(IValueProvider))));

            // generic value providers
            foreach (var genericValueProviderType in genericValueProviderTypes)
            {
                builder
                    .RegisterGeneric(genericValueProviderType)
                    .As(genericValueProviderType)
                    .InstancePerDependency();
            }

            // non-generic value providers
            foreach (var nonGenericValueProviderType in nonGenericValueProviderTypes)
            {
                builder
                    .RegisterType(nonGenericValueProviderType)
                    .AsSelf()
                    .InstancePerDependency();
            }

            var genericCommandTypes = assemblies.SelectMany(a => a.GetTypes()
                    .Where(t => t.IsGenericType && typeof (BaseCommand).IsAssignableFrom(t)));
            var nonGenericCommandTypes = assemblies.SelectMany(a => a.GetTypes()
                    .Where(t => !t.IsGenericType && typeof(BaseCommand).IsAssignableFrom(t)));

            // generic commands
            foreach (var genericCommandType in genericCommandTypes)
            {
                builder
                    .RegisterGeneric(genericCommandType)
                    .As(genericCommandType)
                    .InstancePerDependency()
                    .OnActivated(activated => ((BaseCommand) activated.Instance).Execute());
            }

            // non-generic commands
            foreach (var nonGenericCommandType in nonGenericCommandTypes)
            {
                builder
                    .RegisterType(nonGenericCommandType)
                    .AsSelf()
                    .InstancePerDependency()
                    .OnActivated(activated => ((BaseCommand) activated.Instance).Execute());
            }

            var genericConditionTypes = assemblies.SelectMany(a => a.GetTypes()
                .Where(t => t.IsGenericType && t.GetInterfaces().Contains(typeof(ICondition))));
            var nonGenericConditionTypes = assemblies.SelectMany(a => a.GetTypes()
                .Where(t => !t.IsGenericType && t.GetInterfaces().Contains(typeof(ICondition))));

            foreach (var genericConditionType in genericConditionTypes)
            {
                builder
                    .RegisterGeneric(genericConditionType)
                    .As(genericConditionType)
                    .InstancePerDependency();
            }

            foreach (var nonGenericConditionType in nonGenericConditionTypes)
            {
                builder
                    .RegisterType(nonGenericConditionType)
                    .As(nonGenericConditionType)
                    .InstancePerDependency();
            }
        }