ryanheath / RavenDB-NodaTime

Noda Time support for RavenDB
Other
20 stars 14 forks source link

The name 'NodaTimeField' does not exist in the current context #6

Closed di97mni closed 9 years ago

di97mni commented 9 years ago

Is this a RavenDB-NodaTime issue or RavenDB?

First test is OK but second test Can_create_Nodatime_index_in_another_db fails with error Raven.Abstractions.Exceptions.IndexCompilationExceptionCompilation Errors: Line 28, Position 12: Error CS0103 - The name 'NodaTimeField' does not exist in the current context

using System.ComponentModel.Composition.Hosting;
using System.Linq;
using NodaTime;
using Raven.Abstractions.Indexing;
using Raven.Bundles.NodaTime;
using Raven.Client.Embedded;
using Raven.Client.Extensions;
using Raven.Client.Indexes;
using Raven.Client.NodaTime;
using Raven.Tests.Helpers;
using Xunit;

namespace Tests
{
    public class NodaTimeBundleTest : RavenTestBase
    {
        [Fact]
        public void Can_create_Nodatime_index_in_default_db()
        {
            var store = new EmbeddableDocumentStore
            {
                RunInMemory = true,
                EnlistInDistributedTransactions = false
            };

            store.Configuration.Catalog.Catalogs.Add(new AssemblyCatalog(typeof (NodaTimeCompilationExtension).Assembly));
            store.Initialize();
            store.ConfigureForNodaTime(DateTimeZoneProviders.Bcl);

            var catalog = new CompositionContainer(new TypeCatalog(typeof(SomeClassIndex)));
            IndexCreation.CreateIndexes(catalog, store);
        }

        [Fact]
        public void Can_create_Nodatime_index_in_another_db()
        {
            var store = new EmbeddableDocumentStore
            {
                RunInMemory = true,
                EnlistInDistributedTransactions = false
            };

            store.Configuration.Catalog.Catalogs.Add(new AssemblyCatalog(typeof (NodaTimeCompilationExtension).Assembly));
            store.Initialize();
            store.ConfigureForNodaTime(DateTimeZoneProviders.Bcl);

            const string dbName = "anotherDb";
            store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists(dbName);
            var dbCatalog = new CompositionContainer(new TypeCatalog(typeof(SomeClassIndex)));
            IndexCreation.CreateIndexes(dbCatalog, store.DatabaseCommands.ForDatabase(dbName), store.Conventions);
        }
    }

    public class SomeClassIndex : AbstractIndexCreationTask<SomeClass>
    {
        public SomeClassIndex()
        {
            Map = docs => from doc in docs
                select new
                {
                    doc.LocalDate,
                    Span = doc.LocalDate.AsLocalDate().DaysBetween(doc.LocalDate.AsLocalDate()),
                };

            StoreAllFields(FieldStorage.Yes);
        }
    }

    public class SomeClass
    {
        public LocalDate LocalDate { get; set; }
    }
}
mattjohnsonpint commented 9 years ago

Last I checked, the embedded store didn't support multiple databases. It's been awhile since I looked though. Has that changed?

mattjohnsonpint commented 9 years ago

The tests pass if you use the store's original catalog, which has the NodaTime plugin registered already.

var dbCatalog = new CompositionContainer(store.Configuration.Catalog);
di97mni commented 9 years ago

I need to split the indexes between different DBs. I posted in the RDB forum because it's probably an issue with RDB then. Or user error :smile:

mattjohnsonpint commented 9 years ago

I think you will need to create two different EmbeddableDocumentStore instances. As far as I am aware, multiple databases are not supported in a single embedded store. Only the full RavenDB server supports multiple databases.