Exemplo n.º 1
0
        public void can_fetch_schema_objects_for_a_document_type_in_the_default_schema()
        {
            var store1 = TestingDocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = "public";
                _.Schema.For <User>().Duplicate(x => x.UserName).Duplicate(x => x.Internal);
            });

            store1.Schema.EnsureStorageExists(typeof(User));


            var objects =
                store1.Schema.DbObjects.FindSchemaObjects(store1.Schema.MappingFor(typeof(User)).As <DocumentMapping>());


            objects.Table.Columns.OrderBy(x => x.Name).Select(x => x.Name)
            .ShouldHaveTheSameElementsAs("data", "id", "internal", DocumentMapping.DotNetTypeColumn,
                                         DocumentMapping.LastModifiedColumn, DocumentMapping.VersionColumn, "user_name");

            objects.Function.Body.ShouldContain("CREATE OR REPLACE FUNCTION public.mt_upsert_user");


            objects.ActualIndices.Select(x => x.Value).OrderBy(x => x.Name).Select(x => x.Name)
            .ShouldHaveTheSameElementsAs("mt_doc_user_idx_internal", "mt_doc_user_idx_user_name");
        }
Exemplo n.º 2
0
        public void can_generate_the_patch_with_camel_casing()
        {
            using (var store1 = TestingDocumentStore.For(_ =>
            {
                _.UseDefaultSerialization(EnumStorage.AsString, Casing.CamelCase);
            }))
            {
                store1.BulkInsert(new User[] { new User {
                                                   UserName = "******"
                                               }, new User {
                                                   UserName = "******"
                                               } });
            }

            using (var store2 = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.Schema.For <User>().SoftDeleted();
                _.UseDefaultSerialization(EnumStorage.AsString, Casing.CamelCase);
            }))
            {
                // 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.Tenancy.Default.DbObjects.ExistingTableFor(typeof(User));

                table.HasColumn(DocumentMapping.DeletedColumn).ShouldBeTrue();
                table.HasColumn(DocumentMapping.DeletedAtColumn).ShouldBeTrue();
            }
        }
Exemplo n.º 3
0
        public void detect_change_in_upsert_function_95_style()
        {
            var store1 = TestingDocumentStore.For(_ =>
            {
                _.UpsertType         = PostgresUpsertType.Standard;
                _.DatabaseSchemaName = Marten.StoreOptions.DefaultDatabaseSchemaName;
                //_.Schema.For<User>().Searchable(x => x.UserName).Searchable(x => x.Internal);
            });

            store1.Schema.EnsureStorageExists(typeof(User));


            // Don't use TestingDocumentStore because it cleans everything upfront.
            var store2 = DocumentStore.For(_ =>
            {
                _.UpsertType = PostgresUpsertType.Standard;
                _.Connection(ConnectionSource.ConnectionString);
                _.DatabaseSchemaName = Marten.StoreOptions.DefaultDatabaseSchemaName;
                _.Schema.For <User>().Searchable(x => x.UserName).Searchable(x => x.Internal);
            });

            var mapping = store2.Schema.MappingFor(typeof(User)).As <DocumentMapping>();
            var diff    = mapping.SchemaObjects.As <DocumentSchemaObjects>().CreateSchemaDiff(store2.Schema);

            diff.AllMissing.ShouldBeFalse();

            diff.HasFunctionChanged().ShouldBeTrue();
        }
Exemplo n.º 4
0
        public AsyncDaemonFixture()
        {
            _store = TestingDocumentStore.For(_ =>
            {
                _.DatabaseSchemaName        = "expected";
                _.Events.DatabaseSchemaName = "expected";

                _.Events.InlineProjections.AggregateStreamsWith <ActiveProject>();
                _.Events.InlineProjections.TransformEvents(new CommitViewTransform());
            });

            var folder = ".".ToFullPath().ParentDirectory().ParentDirectory()
                         .AppendPath("CodeTracker");

            var files = new FileSystem().FindFiles(folder, FileSet.Shallow("*.json"));

            AllProjects = new Dictionary <Guid, GithubProject>();
            foreach (var file in files)
            {
                var project = GithubProject.LoadFrom(file);
                AllProjects.Add(project.Id, project);

                Console.WriteLine($"Loaded {project.OrganizationName}{project.ProjectName} from JSON");
            }

            PublishAllProjectEvents(_store);
        }
Exemplo n.º 5
0
        public void will_build_the_new_table_if_the_configured_table_does_not_match_the_existing_table_on_other_schema()
        {
            DocumentTable table1;
            DocumentTable table2;

            using (var store = TestingDocumentStore.For(_ => _.DatabaseSchemaName = "other"))
            {
                store.Tenancy.Default.EnsureStorageExists(typeof(User));

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

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

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

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

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

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


            table2.ShouldNotBe(table1);

            table2.Column("user_name").ShouldNotBeNull();
        }
        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();
            }
        }
        public void no_changes_in_upsert_function_95_style()
        {
            var store1 = TestingDocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = Marten.StoreOptions.DefaultDatabaseSchemaName;
                _.Schema.For <User>().Duplicate(x => x.UserName).Duplicate(x => x.Internal);
            });

            store1.Advanced.Clean.CompletelyRemoveAll();

            store1.Schema.EnsureStorageExists(typeof(User));


            // Don't use TestingDocumentStore because it cleans everything upfront.
            var store2 = DocumentStore.For(_ =>
            {
                _.Connection(ConnectionSource.ConnectionString);
                _.DatabaseSchemaName = Marten.StoreOptions.DefaultDatabaseSchemaName;
                _.Schema.For <User>().Duplicate(x => x.UserName).Duplicate(x => x.Internal);
            });

            var mapping = store2.Schema.MappingFor(typeof(User)).As <DocumentMapping>();
            var diff    = mapping.SchemaObjects.As <DocumentSchemaObjects>().CreateSchemaDiff(store2.Schema);

            diff.AllMissing.ShouldBeFalse();

            diff.FunctionDiff.HasChanged.ShouldBeFalse();

            diff.HasDifferences().ShouldBeFalse();
        }
Exemplo n.º 8
0
        public void can_fetch_indexes_for_a_table_in_public()
        {
            var store1 = TestingDocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = "other";
                _.Schema.For <User>().Duplicate(x => x.UserName).Duplicate(x => x.Internal);
            }).As <DocumentStore>();

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

            var store2 = TestingDocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = Marten.StoreOptions.DefaultDatabaseSchemaName;
                _.Schema.For <User>().Duplicate(x => x.UserName).Duplicate(x => x.FirstName);
            }).As <DocumentStore>();

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

            var indices = store2.Tenancy.Default.DbObjects.AllIndexes();

            indices.Any(x => Equals(x.Table, store1.Storage.MappingFor(typeof(User)).ToQueryableDocument().Table))
            .ShouldBeFalse();

            indices.Any(x => Equals(x.Table, store2.Storage.MappingFor(typeof(User)).ToQueryableDocument().Table))
            .ShouldBeTrue();
        }
Exemplo n.º 9
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\"}");
                }
            }
        }
Exemplo n.º 10
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);
                }
            }
        }
Exemplo n.º 11
0
 public void should_allow_self_reference()
 {
     TestingDocumentStore.Basic().Storage.MappingFor(typeof(Employee))
     .As <DocumentMapping>()
     .ForeignKeys
     .ShouldContain(x => x.ColumnName == "manager_id");
 }
Exemplo n.º 12
0
 public void should_get_foreign_key_from_attribute()
 {
     TestingDocumentStore.Basic().Storage.MappingFor(typeof(Issue))
     .As <DocumentMapping>()
     .ForeignKeys
     .ShouldContain(x => x.ColumnName == "user_id");
 }
Exemplo n.º 13
0
        public override void SetUp()
        {
            _streams.ClearAll();

            _store = TestingDocumentStore.Basic();

            Context.State.Store(_store);
        }
Exemplo n.º 14
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>());
        }
Exemplo n.º 15
0
        public override void SetUp()
        {
            IdToName.ClearAll();

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

            Session = Store.OpenSession();
        }
        public void can_override_with_MartenRegistry()
        {
            var store = TestingDocumentStore.For(_ =>
            {
                _.Schema.For <Organization>().Duplicate(x => x.Time2, pgType: "timestamp");
            });

            store.Storage.MappingFor(typeof(Organization)).As <DocumentMapping>().DuplicatedFields.Single(x => x.MemberName == "Time2")
            .PgType.ShouldBe("timestamp");
        }
 public void can_configure_deletion_style_by_fluent_interface()
 {
     using (var store = TestingDocumentStore.For(_ =>
     {
         _.Schema.For <User>().SoftDeleted();
     }))
     {
         store.Schema.MappingFor(typeof(User)).As <DocumentMapping>()
         .DeleteStyle.ShouldBe(DeleteStyle.SoftDelete);
     }
 }
Exemplo n.º 18
0
        public AsyncDaemonTestHelper()
        {
            _store = TestingDocumentStore.For(_ =>
            {
                _.DatabaseSchemaName        = "expected";
                _.Events.DatabaseSchemaName = "expected";

                _.Events.InlineProjections.AggregateStreamsWith <ActiveProject>();
                _.Events.InlineProjections.TransformEvents(new CommitViewTransform());
            });
        }
Exemplo n.º 19
0
 public void set_the_version_member_through_the_fluent_interface()
 {
     using (var store = TestingDocumentStore.For(_ =>
     {
         _.Schema.For <DocThatCouldBeVersioned>().VersionedWith(x => x.Revision);
     }))
     {
         store.Storage.MappingFor(typeof(DocThatCouldBeVersioned))
         .VersionMember.Name.ShouldBe(nameof(DocThatCouldBeVersioned.Revision));
     }
 }
Exemplo n.º 20
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);
            }
        }
Exemplo n.º 21
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));
                });
            }
        }
Exemplo n.º 22
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());
        }
Exemplo n.º 23
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");
        }
Exemplo n.º 24
0
        public void fetch_schema_objects_for_a_document_type_that_has_not_been_created_yet()
        {
            var store1 = TestingDocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = "public";
                _.Schema.For <User>().Searchable(x => x.UserName).Searchable(x => x.Internal);
            });


            var objects = store1.Schema.DbObjects.FindSchemaObjects(store1.Schema.MappingFor(typeof(User)).As <DocumentMapping>());

            objects.HasNone().ShouldBeTrue();
            objects.Table.ShouldBeNull();
            objects.ActualIndices.Any().ShouldBeFalse();
            objects.UpsertFunction.ShouldBeNull();
        }
Exemplo n.º 25
0
        public void can_fetch_the_function_ddl()
        {
            var store1 = TestingDocumentStore.For(_ =>
            {
                _.DatabaseSchemaName = "other";
                _.Schema.For <User>().Duplicate(x => x.UserName).Duplicate(x => x.Internal);
            });

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

            var upsert = store1.Storage.MappingFor(typeof(User)).As <DocumentMapping>().UpsertFunction;

            var functionBody = store1.Tenancy.Default.DbObjects.DefinitionForFunction(upsert);

            functionBody.Body.ShouldContain("mt_doc_user");
        }
Exemplo n.º 26
0
        public void should_get_foreign_key_from_registry()
        {
            var storeOptions = new StoreOptions();

            storeOptions.Schema.For <Issue>().ForeignKey <User>(i => i.OtherUserId);

            var store = TestingDocumentStore.For(_ =>
            {
                _.Schema.For <Issue>().ForeignKey <User>(i => i.OtherUserId);
            });

            store.Storage.MappingFor(typeof(Issue))
            .As <DocumentMapping>()
            .ForeignKeys
            .ShouldContain(x => x.ColumnName == "other_user_id");
        }
Exemplo n.º 27
0
        public void check_camel_case_serialized_property()
        {
            var store = TestingDocumentStore.For(_ =>
            {
                _.UseDefaultSerialization(casing: Casing.CamelCase);
            });

            var expressionWithSimpleProperty = new PatchExpression <Target>(null, _schema, new UnitOfWork(store, store.Tenancy.Default), store.Serializer);

            expressionWithSimpleProperty.Set(x => x.Color, Colors.Blue);
            expressionWithSimpleProperty.Patch["path"].ShouldBe("color");

            var expressionWithNestedProperty = new PatchExpression <Target>(null, _schema, new UnitOfWork(store, store.Tenancy.Default), store.Serializer);

            expressionWithNestedProperty.Delete(x => x.Inner.AnotherString);
            expressionWithNestedProperty.Patch["path"].ShouldBe("inner.anotherString");
        }
Exemplo n.º 28
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();
            }
        }
Exemplo n.º 29
0
        public void should_allow_foreign_key_on_id_field()
        {
            var storeOptions = new StoreOptions();


            var store = TestingDocumentStore.For(_ =>
            {
                _.Schema.For <Foo>()
                .Identity(x => x.FooId);
                _.Schema.For <FooExtra>()
                .Identity(x => x.FooId)
                .ForeignKey <Foo>(x => x.FooId);
            });

            store.Storage.MappingFor(typeof(FooExtra))
            .As <DocumentMapping>()
            .ForeignKeys
            .ShouldContain(x => x.ColumnName == "foo_id");
        }
Exemplo n.º 30
0
        public void can_build_the_mt_stream_schema_objects_in_different_database_schema()
        {
            var store = TestingDocumentStore.For(_ =>
            {
                _.Events.DatabaseSchemaName = "other";
            });

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

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

            schemaDbObjectNames.ShouldContain("other.mt_append_event");

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

            schemaTableNames.ShouldContain("other.mt_streams");
            schemaTableNames.ShouldContain("other.mt_events");
            schemaTableNames.ShouldContain("other.mt_event_progression");
        }