public void store_options_serializer_with_casing(Casing casing, string expectedUpdateFragment)
        {
            var storeOptions = new StoreOptions();

            storeOptions.UseDefaultSerialization(casing: casing);
            var field = DuplicatedField.For <DuplicateFieldCasingTestDoc>(storeOptions, x => x.OtherId);

            field.UpdateSqlFragment().ShouldBe(expectedUpdateFragment);
        }
        public DuplicatedFieldTests()
        {
            var storeOptions = new StoreOptions {
            };

            storeOptions.Advanced.DuplicatedFieldEnumStorage = EnumStorage.AsInteger;

            theField =
                DuplicatedField.For <User>(storeOptions, x => x.FirstName);
        }
Beispiel #3
0
        public void enum_field()
        {
            var field = DuplicatedField.For <Target>(EnumStorage.AsString, x => x.Color);

            field.UpsertArgument.DbType.ShouldBe(NpgsqlDbType.Varchar);
            field.UpsertArgument.PostgresType.ShouldBe("varchar");

            var constant = Expression.Constant((int)Colors.Blue);

            field.GetValue(constant).ShouldBe(Colors.Blue.ToString());
        }
        public void storage_is_set_when_passed_in(EnumStorage storageMode, string expectedUpdateFragment)
        {
            var storeOptions = new StoreOptions();

            storeOptions.Serializer(new JsonNetSerializer {
                EnumStorage = storageMode
            });

            var field = DuplicatedField.For <Target>(storeOptions, x => x.Color);

            field.UpdateSqlFragment().ShouldBe(expectedUpdateFragment);
        }
        public void store_options_schema_name_is_used_for_timestamptz(string schemaName, string expectedUpdateFragment)
        {
            var storeOptions = schemaName != null
                ? new StoreOptions {
                DatabaseSchemaName = schemaName
            }
                : new StoreOptions();

            var field = DuplicatedField.For <Target>(storeOptions, x => x.DateOffset);

            field.UpdateSqlFragment().ShouldBe(expectedUpdateFragment);
        }
        public void pg_type_is_used_for_string(string pgType, string expectedUpdateFragment)
        {
            var field = DuplicatedField.For <Target>(new StoreOptions(), x => x.String);

            field.PgType = pgType ?? field.PgType;

            field.UpdateSqlFragment().ShouldBe(expectedUpdateFragment);
            var expectedPgType = pgType ?? "varchar";

            field.PgType.ShouldBe(expectedPgType);
            field.UpsertArgument.PostgresType.ShouldBe(expectedPgType);
            field.DbType.ShouldBe(NpgsqlDbType.Text);
        }
Beispiel #7
0
        public void pg_type_is_used_for_guid(string pgType, string expectedUpdateFragment)
        {
            var field = DuplicatedField.For <Target>(EnumStorage.AsInteger, x => x.UserId);

            field.PgType = pgType ?? field.PgType;

            field.UpdateSqlFragment().ShouldBe(expectedUpdateFragment);
            var expectedPgType = pgType ?? "uuid";

            field.PgType.ShouldBe(expectedPgType);
            field.UpsertArgument.PostgresType.ShouldBe(expectedPgType);
            field.DbType.ShouldBe(NpgsqlDbType.Uuid);
        }
Beispiel #8
0
        public void pg_type_is_used_for_string_list(string pgType, string expectedUpdateFragment)
        {
            var field = DuplicatedField.For <ListTarget>(EnumStorage.AsInteger, x => x.TagsList);

            field.PgType = pgType ?? field.PgType;

            field.UpdateSqlFragment().ShouldBe(expectedUpdateFragment);
            var expectedPgType = pgType ?? "jsonb";

            field.PgType.ShouldBe(expectedPgType);
            field.UpsertArgument.PostgresType.ShouldBe(expectedPgType);
            field.DbType.ShouldBe(NpgsqlDbType.Array | NpgsqlDbType.Text);
        }
        public void enum_field()
        {
            var storeOptions = new StoreOptions();

            storeOptions.Serializer(new JsonNetSerializer {
                EnumStorage = EnumStorage.AsString
            });

            var field = DuplicatedField.For <Target>(storeOptions, x => x.Color);

            field.UpsertArgument.DbType.ShouldBe(NpgsqlDbType.Varchar);
            field.UpsertArgument.PostgresType.ShouldBe("varchar");

            var constant = Expression.Constant((int)Colors.Blue);

            field.GetValue(constant).ShouldBe(Colors.Blue.ToString());
        }
        public void enum_field_allows_null()
        {
            var options = new StoreOptions();

            options.Serializer(new JsonNetSerializer
            {
                EnumStorage = EnumStorage.AsString
            });

            var field = DuplicatedField.For <Target>(options, x => x.Color);

            field.UpsertArgument.DbType.ShouldBe(NpgsqlDbType.Varchar);
            field.UpsertArgument.PostgresType.ShouldBe("varchar");

            var constant = Expression.Constant(null);

            field.GetValueForCompiledQueryParameter(constant).ShouldBe(null);
        }
        public void storage_is_set_when_passed_in(EnumStorage storageMode, string expectedUpdateFragment)
        {
            var field = DuplicatedField.For <Target>(storageMode, x => x.Color);

            field.UpdateSqlFragment().ShouldBe(expectedUpdateFragment);
        }