public async Task Can_update_DefaultValue_Async()
        {
            using var db = await OpenDbConnectionAsync();

            db.DropAndCreateTable <DefaultValue>();
            AssertDefaultValueFieldTypeDefaultValues();

            var orig = new DefaultValue {
                Id     = 1,
                Bool   = true,
                NBool  = false,
                Int    = 2,
                NInt   = 0,
                String = "A",
            };
            await db.InsertAsync(orig);

            var row = await db.SingleByIdAsync <DefaultValue>(1);

            AssertDefaultValues(row, orig);

            db.UpdateOnly <DefaultValue>(new Dictionary <string, object> {
                [nameof(DefaultValue.Id)]     = 1,
                [nameof(DefaultValue.Bool)]   = false,
                [nameof(DefaultValue.NBool)]  = null,
                [nameof(DefaultValue.Int)]    = 0,
                [nameof(DefaultValue.NInt)]   = null,
                [nameof(DefaultValue.String)] = null,
            });

            row = await db.SingleByIdAsync <DefaultValue>(1);

            AssertDefaultValues(row, new DefaultValue {
                Id     = 1,
                Bool   = false,
                NBool  = null,
                Int    = 0,
                NInt   = null,
                String = null,
            });

            await db.UpdateOnlyAsync <DefaultValue>(new Dictionary <string, object> {
                [nameof(DefaultValue.Id)]     = 1,
                [nameof(DefaultValue.Bool)]   = true,
                [nameof(DefaultValue.NBool)]  = false,
                [nameof(DefaultValue.Int)]    = 1,
                [nameof(DefaultValue.NInt)]   = 0,
                [nameof(DefaultValue.String)] = "",
            });

            row = db.SingleById <DefaultValue>(1);
            AssertDefaultValues(row, new DefaultValue {
                Id     = 1,
                Bool   = true,
                NBool  = false,
                Int    = 1,
                NInt   = 0,
                String = "",
            });
        }
Пример #2
0
 private void AssertDefaultValues(DefaultValue row, DefaultValue orig)
 {
     Assert.That(row.Id, Is.EqualTo(orig.Id));
     Assert.That(row.Bool, Is.EqualTo(orig.Bool));
     Assert.That(row.NBool, Is.EqualTo(orig.NBool));
     Assert.That(row.Int, Is.EqualTo(orig.Int));
     Assert.That(row.NInt, Is.EqualTo(orig.NInt));
     Assert.That(row.String, Is.EqualTo(orig.String));
 }