Example #1
0
        public void TestInsert_NullablePropertiesWithValues()
        {
            Models.Nullable n = new Models.Nullable();
            n.Integer64Value      = 64;
            n.ByteValue           = 1;
            n.ByteArrayValue      = new byte[4];
            n.ByteArrayValue[0]   = 0;
            n.ByteArrayValue[1]   = 1;
            n.ByteArrayValue[2]   = 2;
            n.ByteArrayValue[3]   = 3;
            n.BoolValue           = true;
            n.CharValue           = "a";
            n.DateTimeValue       = Convert.ToDateTime("01/11/1984");
            n.DateTimeOffsetValue = DateTimeOffset.MaxValue;
            n.DecimalValue        = 1.11m;
            n.FloatValue          = 22;
            n.DoubleValue         = 33;
            n.Integer32Value      = 44;
            n.Single         = 55;
            n.Integer16Value = 16;
            n.GuidValue      = guid;
            n.StringValue    = "Something";

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                context.Insert(n);
                context.Commit();
            }

            Models.Nullable retrievedItem = null;

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                retrievedItem = context.QueryItems <Models.Nullable>("select * from Nullable where id = @id", new { id = n.Id }).FirstOrDefault();
            }

            Assert.IsTrue(n != null &&
                          n.Integer64Value == 64 &&
                          n.ByteValue == 1 &&
                          n.ByteArrayValue[0] == 0 &&
                          n.ByteArrayValue[1] == 1 &&
                          n.ByteArrayValue[2] == 2 &&
                          n.ByteArrayValue[3] == 3 &&
                          n.BoolValue == true &&
                          n.CharValue == "a" &&
                          n.DateTimeValue == Convert.ToDateTime("01/11/1984") &&
                          n.DateTimeOffsetValue == DateTimeOffset.MaxValue &&
                          n.DecimalValue == 1.11m &&
                          n.FloatValue == 22 &&
                          n.DoubleValue == 33 &&
                          n.Integer32Value == 44 &&
                          n.Single == 55 &&
                          n.Integer16Value == 16 &&
                          n.GuidValue == guid &&
                          n.StringValue == "Something",
                          "Insert of non-null values in nullable properties failed");
        }
Example #2
0
        public void TestInsert_NullablePropertiesWithNullValues()
        {
            Models.Nullable n = new Models.Nullable();
            n.Integer64Value      = null;
            n.ByteValue           = null;
            n.ByteArrayValue      = null;
            n.BoolValue           = null;
            n.CharValue           = null;
            n.DateTimeValue       = null;
            n.DateTimeOffsetValue = null;
            n.DecimalValue        = null;
            n.FloatValue          = null;
            n.DoubleValue         = null;
            n.Integer32Value      = null;
            n.Single         = null;
            n.Integer16Value = null;
            n.GuidValue      = null;
            n.StringValue    = null;

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                context.Insert(n);
                context.Commit();
            }

            Models.Nullable retrievedItem = null;

            using (ADOCRUDContext context = new ADOCRUDContext(connectionString))
            {
                retrievedItem = context.QueryItems <Models.Nullable>("select * from Nullable where id = @id", new { id = n.Id }).FirstOrDefault();
            }

            Assert.IsTrue(n != null &&
                          !n.Integer64Value.HasValue &&
                          !n.ByteValue.HasValue &&
                          n.ByteArrayValue == null &&
                          !n.BoolValue.HasValue &&
                          string.IsNullOrEmpty(n.CharValue) &&
                          !n.DateTimeValue.HasValue &&
                          !n.DateTimeOffsetValue.HasValue &&
                          !n.DecimalValue.HasValue &&
                          !n.FloatValue.HasValue &&
                          !n.DoubleValue.HasValue &&
                          !n.Integer32Value.HasValue &&
                          !n.Single.HasValue &&
                          !n.Integer16Value.HasValue &&
                          !n.GuidValue.HasValue &&
                          string.IsNullOrEmpty(n.StringValue),
                          "Insert of null values in nullable properties failed");
        }