Ejemplo n.º 1
0
        public async Task VerifyStatementsForCreateColumnWithForeignKey()
        {
            var mockContext = GetMockContext();
            var repo        = new NpgsqlRepository(mockContext.Object, _insertBatchSize);

            repo.RegisterType <TestModel>(null);
            repo.RegisterType <TestForForeignKeyModel>(null);
            const string dummyTargetColumnName = "dummy_id";
            await repo.CreateColumnWithForeignKeyIfNotExist <TestModel, TestForForeignKeyModel>(_dummyColumnName, dummyTargetColumnName);

            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"ALTER TABLE ""{_expectedSchema}"".""{nameof(TestModel)}""
                ADD COLUMN ""{_dummyColumnName}"" INTEGER
                REFERENCES ""{_expectedSchema}"".""{nameof(TestForForeignKeyModel)}""(""{dummyTargetColumnName}"");");
        }
Ejemplo n.º 2
0
        public async Task VerifyStatementsForCreateTable()
        {
            var mockContext = GetMockContext();
            var repo        = new NpgsqlRepository(mockContext.Object, _insertBatchSize);

            repo.RegisterType <TestModel>(null);
            await repo.CreateTableIfNotExist <TestModel>();

            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"CREATE TABLE IF NOT EXISTS ""{_expectedSchema}"".""{nameof(TestModel)}""();");
        }
Ejemplo n.º 3
0
        public async Task VerifyStatementsForCreateColumnWithPrimaryKey()
        {
            var mockContext = GetMockContext();
            var repo        = new NpgsqlRepository(mockContext.Object, _insertBatchSize);

            repo.RegisterType <TestModel>(null);
            await repo.CreateColumnWithPrimaryKeyIfNotExist <TestModel>(_dummyColumnName);

            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"ALTER TABLE ""{_expectedSchema}"".""{nameof(TestModel)}""
                ADD COLUMN ""{_dummyColumnName}"" SERIAL PRIMARY KEY;");
        }
Ejemplo n.º 4
0
        public async Task VerifyStatementsForInsertRowWithReturnValue()
        {
            var mockContext = GetMockContext();
            var repo        = new NpgsqlRepository(mockContext.Object, _insertBatchSize);

            repo.RegisterType <TestModel>(null);
            const string fakeColumnName = "FakeColumnNameToReturn";

            var dummyReturnValue = await repo.InsertRowWithReturnValue <TestModel, int>(
                new TestModel()
            {
                Birthday         = new DateTime(2020, 1, 1),
                MoleCount        = 10,
                Name             = "Bob",
                Points           = 20,
                Registered       = true,
                SubpixelPosition = 30.5m,
                Weight           = 40
            },
                fakeColumnName,
                new Dictionary <string, object>() { { "DummyColumn", "DummyValue" } });

            await repo.Flush();

            VerifyInvocationOfExecuteScalarWithParams <int>(mockContext,
                                                            $@"INSERT INTO ""{_expectedSchema}"".""{nameof(TestModel)}"" 
                (""Birthday"", ""MoleCount"", ""Name"", ""Points"", ""Registered"", ""SubpixelPosition"", ""Weight"", ""DummyColumn"") 
                VALUES (@Birthday, @MoleCount, @Name, @Points, @Registered, @SubpixelPosition, @Weight, @DummyColumn)
                RETURNING ""{fakeColumnName}"";",
                                                            new Dictionary <string, object>()
            {
                { "Birthday", new DateTime(2020, 1, 1) },
                { "MoleCount", 10 },
                { "Name", "Bob" },
                { "Points", 20 },
                { "Registered", true },
                { "SubpixelPosition", 30.5m },
                { "Weight", 40 },
                { "DummyColumn", "DummyValue" }
            });
        }
Ejemplo n.º 5
0
        public async Task VerifyStatementsForCreateColumns()
        {
            var mockContext = GetMockContext();
            var repo        = new NpgsqlRepository(mockContext.Object, _insertBatchSize);

            repo.RegisterType <TestModel>(null);
            await repo.CreateColumnsForTypeIfNotExist <TestModel>();

            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"ALTER TABLE ""{_expectedSchema}"".""{nameof(TestModel)}""
                ADD COLUMN ""Birthday"" timestamp;");
            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"ALTER TABLE ""{_expectedSchema}"".""{nameof(TestModel)}""
                ADD COLUMN ""MoleCount"" bigint;");
            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"ALTER TABLE ""{_expectedSchema}"".""{nameof(TestModel)}""
                ADD COLUMN ""Name"" text;");
            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"ALTER TABLE ""{_expectedSchema}"".""{nameof(TestModel)}""
                ADD COLUMN ""Points"" integer;");
            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"ALTER TABLE ""{_expectedSchema}"".""{nameof(TestModel)}""
                ADD COLUMN ""Registered"" boolean;");
            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"ALTER TABLE ""{_expectedSchema}"".""{nameof(TestModel)}""
                ADD COLUMN ""SubpixelPosition"" numeric;");
            VerifyInvocationOfExecuteNonQuery(
                mockContext,
                $@"ALTER TABLE ""{_expectedSchema}"".""{nameof(TestModel)}""
                ADD COLUMN ""Weight"" double precision;");
        }