Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public DuplicatedFieldTests()
        {
            var storeOptions = new StoreOptions {
            };

            storeOptions.Advanced.DuplicatedFieldEnumStorage = EnumStorage.AsInteger;

            theField =
                DuplicatedField.For <User>(storeOptions, x => x.FirstName);
        }
Exemplo n.º 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());
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
 public DuplicatedFieldColumn(DuplicatedField field) : base(field.ColumnName, field.PgType, field.NotNull ? NotNullConstraint : NullConstraint)
 {
     CanAdd = true;
     _field = field;
 }
Exemplo n.º 12
0
 public DuplicatedFieldColumn(DuplicatedField field) : base(field.ColumnName, field.PgType)
 {
     CanAdd = true;
     _field = field;
 }
Exemplo n.º 13
0
 public static DuplicatedField <TModel> SimpleField(Expression <Func <TModel, object> > FieldExp)
 {
     return(DuplicatedField <TModel> .SimpleField(FieldExp));
 }
Exemplo n.º 14
0
        public DuplicatedFieldColumn(DuplicatedField field) : base(field.ColumnName, field.PgType)
        {
            AllowNulls = !field.NotNull;

            _field = field;
        }
Exemplo n.º 15
0
        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);
        }