예제 #1
0
 public void should_allow_self_reference()
 {
     TestingDocumentStore.Basic().Storage.MappingFor(typeof(Employee))
     .As <DocumentMapping>()
     .ForeignKeys
     .ShouldContain(x => x.ColumnName == "manager_id");
 }
예제 #2
0
        public void end_to_end_test_using_the_transform()
        {
            using (var store = TestingDocumentStore.Basic())
            {
                var user = new User {
                    FirstName = "Jeremy", LastName = "Miller"
                };
                var json = new TestsSerializer().ToCleanJson(user);

                var func = TransformFunction.ForFile(new StoreOptions(), _getFullnameJs);

                using (var conn = store.Tenancy.Default.OpenConnection())
                {
                    conn.Execute(cmd => cmd.Sql(func.GenerateFunction()).ExecuteNonQuery());

                    var actual = conn.Execute(cmd =>
                    {
                        return(cmd.Sql("select mt_transform_get_fullname(:json)")
                               .WithJsonParameter("json", json).ExecuteScalar().As <string>());
                    });

                    actual.ShouldBe("{\"fullname\": \"Jeremy Miller\"}");
                }
            }
        }
        public void can_generate_the_patch()
        {
            using (var store1 = TestingDocumentStore.Basic())
            {
                store1.BulkInsert(new User [] { new User {
                                                    UserName = "******"
                                                }, new User {
                                                    UserName = "******"
                                                } });
            }

            using (var store2 = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.Schema.For <User>().SoftDeleted();
            }))
            {
                // Verifying that we didn't lose any data
                using (var session = store2.QuerySession())
                {
                    session.Query <User>().OrderBy(x => x.UserName).Select(x => x.UserName)
                    .ToList().ShouldHaveTheSameElementsAs("bar", "foo");
                }

                var table = store2.Schema.DbObjects.TableSchema(store2.Schema.MappingFor(typeof(User)));

                table.HasColumn(DocumentMapping.DeletedColumn).ShouldBeTrue();
                table.HasColumn(DocumentMapping.DeletedAtColumn).ShouldBeTrue();
            }
        }
예제 #4
0
        public void do_not_rebuild_a_table_that_already_exists()
        {
            using (var store = TestingDocumentStore.Basic())
            {
                using (var session = store.LightweightSession())
                {
                    session.Store(new User());
                    session.Store(new User());
                    session.Store(new User());

                    session.SaveChanges();
                }
            }

            using (var store = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
            }))
            {
                using (var session = store.LightweightSession())
                {
                    session.Query <User>().Count().ShouldBeGreaterThanOrEqualTo(3);
                }
            }
        }
예제 #5
0
 public void should_get_foreign_key_from_attribute()
 {
     TestingDocumentStore.Basic().Storage.MappingFor(typeof(Issue))
     .As <DocumentMapping>()
     .ForeignKeys
     .ShouldContain(x => x.ColumnName == "user_id");
 }
예제 #6
0
        public void will_build_the_new_table_if_the_configured_table_does_not_match_the_existing_table()
        {
            DocumentTable table1;
            DocumentTable table2;

            using (var store = TestingDocumentStore.Basic())
            {
                store.Tenancy.Default.StorageFor(typeof(User));

                store.Tenancy.Default.DbObjects.DocumentTables().ShouldContain("public.mt_doc_user");

                table1 = store.TableSchema(typeof(User));
                table1.ShouldNotContain(x => x.Name == "user_name");
            }

            using (var store = DocumentStore.For(ConnectionSource.ConnectionString))
            {
                store.Storage.MappingFor(typeof(User)).As <DocumentMapping>().DuplicateField("UserName");

                store.Tenancy.Default.StorageFor(typeof(User));

                store.Tenancy.Default.DbObjects.DocumentTables().ShouldContain("public.mt_doc_user");

                table2 = store.TableSchema(typeof(User));
            }

            table2.ShouldNotBe(table1);

            table2.Column("user_name").ShouldNotBeNull();
        }
예제 #7
0
        public ProjectionTrackContext()
        {
            projection = Substitute.For <IProjection>();

            projection.AsyncOptions.Returns(new AsyncOptions());

            theProjectionTrack = new ProjectionTrack(theFetcher, TestingDocumentStore.Basic(), projection, Substitute.For <IDaemonLogger>(), new StubErrorHandler(), Substitute.For <ITenant>());
        }
예제 #8
0
        public override void SetUp()
        {
            _streams.ClearAll();

            _store = TestingDocumentStore.Basic();

            Context.State.Store(_store);
        }
예제 #9
0
        public override void SetUp()
        {
            IdToName.ClearAll();

            Store = TestingDocumentStore.Basic().As <DocumentStore>();
            Store.Advanced.Clean.CompletelyRemoveAll();

            Session = Store.OpenSession();
        }
예제 #10
0
        public void generate_a_table_to_the_database_with_duplicated_field()
        {
            using (var store = TestingDocumentStore.Basic())
            {
                store.Advanced.Clean.CompletelyRemove(typeof(User));

                var mapping = store.Tenancy.Default.MappingFor(typeof(User)).As <DocumentMapping>();
                mapping.DuplicateField("FirstName");

                store.Tenancy.Default.EnsureStorageExists(typeof(User));

                store.Tenancy.Default.DbObjects.DocumentTables().ShouldContain(mapping.Table.QualifiedName);
            }
        }
예제 #11
0
        public void throw_ambigous_alias_exception_when_you_have_duplicate_document_aliases()
        {
            using (var store = TestingDocumentStore.Basic())
            {
                var storage = store.Storage;

                storage.StorageFor(typeof(Examples.User)).ShouldNotBeNull();

                Exception <AmbiguousDocumentTypeAliasesException> .ShouldBeThrownBy(() =>
                {
                    storage.StorageFor(typeof(User));
                });
            }
        }
예제 #12
0
        public void can_build_the_mt_stream_schema_objects()
        {
            var store = TestingDocumentStore.Basic();

            store.Tenancy.Default.EnsureStorageExists(typeof(EventStream));

            var schemaDbObjectNames = store.Tenancy.Default.DbObjects.Functions();

            schemaDbObjectNames.ShouldContain("public.mt_append_event");

            var schemaTableNames = store.Tenancy.Default.DbObjects.SchemaTables();

            schemaTableNames.ShouldContain("public.mt_streams");
            schemaTableNames.ShouldContain("public.mt_events");
            schemaTableNames.ShouldContain("public.mt_event_progression");
        }
예제 #13
0
        public PatchExpressionTests()
        {
            var queryable = Substitute.For <IQueryableDocument>();

            queryable.DocumentType.Returns(typeof(Target));

            var mapping = Substitute.For <IDocumentMapping>();

            mapping.ToQueryableDocument().Returns(queryable);

            _schema.MappingFor(typeof(Target)).Returns(mapping);

            var store = TestingDocumentStore.Basic();

            _expression = new PatchExpression <Target>(null, _schema, new UnitOfWork(store, store.Tenancy.Default), new JsonNetSerializer());
        }
예제 #14
0
        public void can_canonicize_bool()
        {
            using (var store1 = TestingDocumentStore.Basic())
            {
                store1.Schema.EnsureStorageExists(typeof(DocWithBool));

                store1.Schema.ApplyAllConfiguredChangesToDatabase();
            }

            using (var store2 = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.Schema.For <DocWithBool>();
            }))
            {
                store2.Schema.AssertDatabaseMatchesConfiguration();
            }
        }
예제 #15
0
        public void patch_if_missing()
        {
            using (var store1 = TestingDocumentStore.Basic())
            {
                store1.Advanced.Clean.CompletelyRemoveAll();

                store1.Tenancy.Default.EnsureStorageExists(typeof(Target));
            }

            using (var store2 = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.Schema.For <Target>().Index(x => x.Number);
            }))
            {
                var patch = store2.Schema.ToPatch();

                patch.UpdateDDL.ShouldContain("mt_doc_target_idx_number");
            }
        }
예제 #16
0
        public void will_name_nested_class_table_with_containing_class_name_prefix()
        {
            DocumentTable table1;
            DocumentTable table2;

            using (var store = TestingDocumentStore.Basic())
            {
                store.Tenancy.Default.StorageFor(typeof(Foo.Document));
                store.Tenancy.Default.StorageFor(typeof(Bar.Document));

                var documentTables = store.Tenancy.Default.DbObjects.DocumentTables();
                documentTables.ShouldContain("public.mt_doc_foo_document");
                documentTables.ShouldContain("public.mt_doc_bar_document");

                table1 = store.TableSchema(typeof(Foo.Document));
                table1.Identifier.Name.ShouldBe("mt_doc_foo_document");

                table2 = store.TableSchema(typeof(Bar.Document));
                table2.Identifier.Name.ShouldBe("mt_doc_bar_document");
            }


            table2.Equals(table1).ShouldBeFalse();
        }