Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
RavenDB Build 888 - Failing test for Projection with Integer Id
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Maverix  
View profile   Translate to Translated (View Original)
 More options May 31 2012, 2:06 am
From: Maverix <ajha...@gmail.com>
Date: Wed, 30 May 2012 23:06:30 -0700 (PDT)
Local: Thurs, May 31 2012 2:06 am
Subject: RavenDB Build 888 - Failing test for Projection with Integer Id

I'm not sure if this is 'by design' but here is the failing test anyway.

using System.Collections.Generic;using System.ComponentModel.Composition.Hosting;using System.Linq;using Microsoft.VisualStudio.TestTools.UnitTesting;using Raven.Abstractions.Indexing;using Raven.Client;using Raven.Client.Document;using Raven.Client.Indexes;using Raven.Client.Linq;using Raven.Client.Listeners;using Raven.Client.Embedded;
 namespace SLC.CoreTests
{
    [TestClass]
    public class SearchFailingTest
    {
        public static DocumentStore Store() {
            DocumentStore store = new EmbeddableDocumentStore {
                RunInMemory = true,
                UseEmbeddedHttpServer = true,
                Conventions = { DefaultQueryingConsistency = ConsistencyOptions.QueryYourWrites }
            };
            store.Initialize();
            store.RegisterListener(new NonStaleQueryListener());

            var indexes = (from type in typeof(Users_Emails).Assembly.GetTypes()
                           where type.IsSubclassOf(typeof(AbstractIndexCreationTask))
                           select type).ToArray();

            IndexCreation.CreateIndexes(
                new CompositionContainer(new TypeCatalog(indexes)),
                store.DatabaseCommands,
                store.Conventions);

            return store;
        }

        public Result[] Lookup(IDocumentSession session, string name, bool first = true) {
            var index = session.Query<Result, Users_Emails>().Where(v => v.Query.StartsWith(name)).AsProjection<Result>();
            var contacts = index.Take(5).ToArray();
            if (contacts != null && contacts.Length > 0) return contacts;

            if (first) {
                var suggestions = index.Suggest();
                if (suggestions.Suggestions != null && suggestions.Suggestions.Length > 0)
                    return Lookup(session, suggestions.Suggestions.FirstOrDefault(), false);
            }
            return new Result[0];
        }

        [TestMethod]
        public void TestMethod() {
            UserInfo user = new UserInfo { displayName = "John Smith" };
            user.emails.Add("j...@smithy.com");
            user.emails.Add("john.sm...@workplace.com");

            using (var store = Store()) {
                using (var session = store.OpenSession()) {
                    session.Store(user);
                    session.SaveChanges();
                }

                using (var session = store.OpenSession()) {
                    var results = Lookup(session, "john");
                    Assert.IsNotNull(results);
                }
            }
        }
    }

    public class UserInfo {
        public UserInfo() { emails = new List<string>(); }
        public int Id { get; set; }
        public string displayName { get; set; }
        public List<string> emails { get; set; }
    }

    public class Result {
        public int Id { get; set; }
        public string name { get; set; }
        public string email { get; set; }
        public string Query { get; set; }
    }

    public class Users_Emails : AbstractIndexCreationTask<UserInfo, Result> {
        public Users_Emails() {
            Map = contacts => from contact in contacts
                              where contact.emails != null && contact.emails.Count > 0
                              from email in contact.emails
                              select new {
                                  Id = contact.Id,
                                  name = contact.displayName,
                                  email = email,
                                  Query = new object[] {
                                        contact.displayName,
                                      }
                              };

            Indexes.Add(x => x.Query, FieldIndexing.Analyzed);
            Stores.Add(x => x.Id, FieldStorage.Yes);
            Stores.Add(x => x.name, FieldStorage.Yes);
            Stores.Add(x => x.email, FieldStorage.Yes);
        }
    }

    public class NonStaleQueryListener : IDocumentQueryListener {
        public void BeforeQueryExecuted(IDocumentQueryCustomization customization) {
            customization.WaitForNonStaleResults();
        }
    }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Maverix  
View profile  
 More options May 31 2012, 3:26 am
From: Maverix <ajha...@gmail.com>
Date: Thu, 31 May 2012 00:26:33 -0700 (PDT)
Local: Thurs, May 31 2012 3:26 am
Subject: Re: RavenDB Build 888 - Failing test for Projection with Integer Id

Seems to work if I omit the Id from the map select.
I'm guessing the RavenDB Client is able to populate the correct ID via
inference?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Eini (Ayende Rahien)  
View profile  
 More options May 31 2012, 5:23 am
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Thu, 31 May 2012 12:23:30 +0300
Local: Thurs, May 31 2012 5:23 am
Subject: Re: [RavenDB] RavenDB Build 888 - Failing test for Projection with Integer Id

Unrelated, but you do know that you can change:

var indexes = (from type in typeof(Users_Emails).Assembly.GetTypes()
                           where
type.IsSubclassOf(typeof(AbstractIndexCreationTask))
                           select type).ToArray();

            IndexCreation.CreateIndexes(
                new CompositionContainer(new TypeCatalog(indexes)),
                store.DatabaseCommands,
                store.Conventions);

To:

            IndexCreation.CreateIndexes( typeof(Users_Emails).Assembly,
                store.DatabaseCommands,
                store.Conventions);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Eini (Ayende Rahien)  
View profile   Translate to Translated (View Original)
 More options May 31 2012, 5:24 am
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Thu, 31 May 2012 12:24:12 +0300
Local: Thurs, May 31 2012 5:24 am
Subject: Re: [RavenDB] Re: RavenDB Build 888 - Failing test for Projection with Integer Id

 Id = contact.Id,

You are trying to make this into an integer, but this is actually a string
on the server side, not an int.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Maverix  
View profile  
 More options May 31 2012, 10:16 pm
From: Maverix <ajha...@gmail.com>
Date: Thu, 31 May 2012 19:16:00 -0700 (PDT)
Subject: Re: [RavenDB] RavenDB Build 888 - Failing test for Projection with Integer Id

Hi Oren,

I'm aware that you can pull indexes out of an assembly, but in my project I
have two types of databases: a membership database and tenant databases.
By using the TypeCatalog I can ensure i'm not pulling in the wrong indexes.

I also use this pattern for testing to speed up the test run (minimising
unwanted index creation)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »