Example #1
0
        public void When_documents_are_stored_after_each_other_then_the_first_id_should_be_less_than_the_second()
        {
            using (var container = ContainerFactory.Configure(
                       // SAMPLE: configuring-global-sequentialguid
                       options => options.DefaultIdStrategy = (mapping, storeOptions) => new CombGuidIdGeneration()
                                                              // ENDSAMPLE
                       ))
            {
                container.GetInstance <DocumentCleaner>().CompletelyRemoveAll();
                var store = container.GetInstance <IDocumentStore>();

                StoreUser(store, "User1");
                Thread.Sleep(4); //we need some time inbetween to ensure the timepart of the CombGuid is different
                StoreUser(store, "User2");
                Thread.Sleep(4);
                StoreUser(store, "User3");

                var users = GetUsers(store);

                var id1 = FormatIdAsByteArrayString(users, "User1");
                var id2 = FormatIdAsByteArrayString(users, "User2");
                var id3 = FormatIdAsByteArrayString(users, "User3");

                id1.CompareTo(id2).ShouldBe(-1);
                id2.CompareTo(id3).ShouldBe(-1);
            }
        }
Example #2
0
        public void can_build_the_event_schema_objects_in_a_separted_schema()
        {
            var container = ContainerFactory.Configure(_ =>
                                                       // SAMPLE: override_schema_name_event_store
                                                       _.Events.DatabaseSchemaName = "event_store"
                                                       // ENDSAMPLE
                                                       );

            container.GetInstance <DocumentCleaner>().CompletelyRemoveAll();

            var schema = container.GetInstance <IDocumentSchema>();

            schema.EnsureStorageExists(typeof(EventStream));

            var store = container.GetInstance <IDocumentStore>();

            store.EventStore.InitializeEventStoreInDatabase(true);

            var schemaFunctionNames = schema.DbObjects.SchemaFunctionNames();

            schemaFunctionNames.ShouldContain("event_store.mt_append_event");

            var schemaTableNames = schema.DbObjects.SchemaTables();

            schemaTableNames.ShouldContain("event_store.mt_streams");
            schemaTableNames.ShouldContain("event_store.mt_events");
        }
        public void When_a_custom_id_generation_is_used()
        {
            using (var container = ContainerFactory.Configure(
                       // SAMPLE: configuring-global-custom
                       options => options.DefaultIdStrategy = (mapping, storeOptions) => new CustomdIdGeneration()))
            // ENDSAMPLE
            {
                container.GetInstance <DocumentCleaner>().CompletelyRemoveAll();

                var store = container.GetInstance <IDocumentStore>();

                // SAMPLE: configuring-global-custom-test
                using (var session = store.OpenSession())
                {
                    session.Store(new UserWithString {
                        LastName = "last"
                    });
                    session.SaveChanges();
                }

                using (var session1 = store.QuerySession())
                {
                    var users = session1.Query <UserWithString>().ToArray <UserWithString>();
                    users.Single(user => user.LastName == "last").Id.ShouldBe("newId");
                }
                // ENDSAMPLE
            }
        }
 public void When_a_custom_stregy_is_defined_for_a_single_document_then_Guid_should_be_used_as_Default()
 {
     using (var container = ContainerFactory.Configure(
                // SAMPLE: configuring-mapping-specific-custom
                options => options.Schema.For <UserWithString>().IdStrategy(new CustomdIdGeneration())
                // ENDSAMPLE
                ))
     {
         var store = container.GetInstance <IDocumentStore>();
         store.Schema.MappingFor(typeof(UserWithString)).As <DocumentMapping>().IdStrategy.ShouldBeOfType <CustomdIdGeneration>();
     }
 }
        public void can_build_the_mt_stream_schema_objects_in_different_database_schema()
        {
            var container = ContainerFactory.Configure(options => options.DatabaseSchemaName = "other");

            container.GetInstance <DocumentCleaner>().CompletelyRemoveAll();

            var schema = container.GetInstance <IDocumentSchema>();

            schema.EnsureStorageExists(typeof(EventStream));

            var schemaFunctionNames = schema.DbObjects.SchemaFunctionNames();

            schemaFunctionNames.ShouldContain("other.mt_append_event");

            var schemaTableNames = schema.DbObjects.SchemaTables();

            schemaTableNames.ShouldContain("other.mt_streams");
            schemaTableNames.ShouldContain("other.mt_events");
        }
Example #6
0
        public void When_documents_are_stored_after_each_other_then_the_first_id_should_be_less_than_the_second()
        {
            using (
                var container =
                    ContainerFactory.Configure(options => options.DefaultIdStrategy = (mapping, storeOptions) => new IdentityKeyGeneration(mapping.As <DocumentMapping>(), storeOptions.HiloSequenceDefaults)))
            {
                container.GetInstance <DocumentCleaner>().CompletelyRemoveAll();

                var store = container.GetInstance <IDocumentStore>();

                StoreUser(store, "User1");
                StoreUser(store, "User2");
                StoreUser(store, "User3");

                var users = GetUsers(store);

                GetId(users, "User1").ShouldBe("userwithstring/1");
                GetId(users, "User2").ShouldBe("userwithstring/2");
                GetId(users, "User3").ShouldBe("userwithstring/3");
            }
        }