public void Can_get_type_of_result_from_query()
        {
            var compiled = new LinqTransformer(query, "docs", typeof(JsonDynamicObject)).Compile();
            var instance = (AbstractViewGenerator)Activator.CreateInstance(compiled);
            var argument = instance.ViewDefinition.Body.Type.GetGenericArguments()[0];

            Assert.NotNull(argument.GetProperty("Key"));
            Assert.NotNull(argument.GetProperty("Value"));
            Assert.NotNull(argument.GetProperty("Size"));

            Assert.Equal(typeof(string), argument.GetProperty("Key").PropertyType);
            Assert.Equal(typeof(string), argument.GetProperty("Value").PropertyType);
            Assert.Equal(typeof(int), argument.GetProperty("Size").PropertyType);
        }
        public void AddView(string viewDefinition)
        {
            var transformer = new LinqTransformer(viewDefinition, "docs", typeof(JsonDynamicObject));
            Type type = transformer.Compile();
            var generator = (AbstractViewGenerator)Activator.CreateInstance(type);

            byte[] compiled = File.ReadAllBytes(transformer.PathToAssembly);
            Storage.Batch(actions =>
            {
                actions.AddView(transformer.Name, viewDefinition, compiled);
                actions.CreateViewTable(transformer.Name, generator.GeneratedType);
                foreach (var key in actions.DocumentKeys())
                {
                    actions.QueueDocumentForViewTransformation(transformer.Name, key);
                }
                actions.Commit();
            });
        }
        public void Can_query_json()
        {
            var documents = GetDocumentsFromString(@"[
            {'type':'page', title: 'hello', content: 'foobar', size: 2},
            {'type':'page', title: 'there', content: 'foobar 2', size: 3},
            {'type':'revision', size: 4}
            ]");
            var compiled = new LinqTransformer(query, "docs", typeof(JsonDynamicObject)).Compile();
            var compiledQuery = (AbstractViewGenerator)Activator.CreateInstance(compiled);
            var actual = compiledQuery.Execute(documents)
                .Cast<object>().ToArray();
            var expected = new[]
            {
                "{ Key = hello, Value = foobar, Size = 2 }",
                "{ Key = there, Value = foobar 2, Size = 3 }"
            };

            Assert.Equal(expected.Length, actual.Length);
            for (var i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], actual[i].ToString());
            }
        }
        public void Can_execute_query()
        {
            var compiled = new LinqTransformer(query, "docs", typeof(JsonDynamicObject)).Compile();
            var generator = (AbstractViewGenerator)Activator.CreateInstance(compiled);
            var results = generator.Execute(new[]
            {
                new JsonDynamicObject(@"
                {
                    'Type': 'page',
                    'Title': 'doc1',
                    'Content': 'Foobar',
                    'Size': 31
                }"),
                new JsonDynamicObject(@"
                {
                    'Type': 'not a page',
                }"),
                new JsonDynamicObject(@"
                {
                    'Type': 'page',
                    'Title': 'doc2',
                    'Content': 'Foobar',
                    'Size': 31
                }"),
            }).Cast<object>().ToArray();

            var expected = new[]
            {
                "{ Key = doc1, Value = Foobar, Size = 31 }",
                "{ Key = doc2, Value = Foobar, Size = 31 }"
            };

            for (int i = 0; i < results.Length; i++)
            {
                Assert.Equal(expected[i], results[i].ToString());
            }
        }
 public void Will_compile_query_successfully()
 {
     var compiled = new LinqTransformer(query, "docs", typeof(JsonDynamicObject)).Compile();
     Assert.NotNull(compiled);
 }
 public void Can_create_new_instance_from_query()
 {
     var compiled = new LinqTransformer(query, "docs", typeof(JsonDynamicObject)).Compile();
     Activator.CreateInstance(compiled);
 }