Пример #1
0
        public void TestNullableInt64()
        {
            NullableClass clazz = new NullableClass();

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(clazz.Id, 1);
            Assert.IsNull(clazz.TestInt64);
        }
Пример #2
0
        public void TestNullableTimeSpan()
        {
            NullableClass clazz = new NullableClass();

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.IsNull(clazz.TestTimeSpan);
        }
Пример #3
0
        public void TestNotNullableChar()
        {
            NullableClass clazz = new NullableClass();
            clazz.TestChar = 'a';

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual('a', clazz.TestChar);
        }
Пример #4
0
        public void TestNotNullableByte()
        {
            NullableClass clazz = new NullableClass();
            clazz.TestByte = 155;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(155, clazz.TestByte);
        }
Пример #5
0
        public void TestNotNullableBool()
        {
            NullableClass clazz = new NullableClass();
            clazz.TestBool = false;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(false, clazz.TestBool);
        }
Пример #6
0
        public void TestNotNullableBool()
        {
            NullableClass clazz = new NullableClass();

            clazz.TestBool = false;

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(false, clazz.TestBool);
        }
Пример #7
0
        public void TestNotNullableChar()
        {
            NullableClass clazz = new NullableClass();

            clazz.TestChar = 'a';

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual('a', clazz.TestChar);
        }
Пример #8
0
        public void TestNotNullableDouble()
        {
            NullableClass clazz = new NullableClass();

            clazz.TestDouble = 99.5125;

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(99.5125, clazz.TestDouble);
        }
Пример #9
0
        public void TestNotNullableInt16()
        {
            NullableClass clazz = new NullableClass();

            clazz.TestInt16 = 45;

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(45, clazz.TestInt16);
        }
Пример #10
0
        public void TestNotNullableInt64()
        {
            NullableClass clazz = new NullableClass();

            clazz.TestInt64 = 1234567890123456789;

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(1234567890123456789, clazz.TestInt64);
        }
Пример #11
0
        public void TestNotNullableSingle()
        {
            NullableClass clazz = new NullableClass();

            clazz.TestSingle = 4578.46445454112f;

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(4578.46445454112f, clazz.TestSingle);
        }
Пример #12
0
        public void TestNotNullableDecimal()
        {
            NullableClass clazz = new NullableClass();

            clazz.TestDecimal = 99.53M;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(99.53M, clazz.TestDecimal);
        }
Пример #13
0
        public void TestNotNullableByte()
        {
            NullableClass clazz = new NullableClass();

            clazz.TestByte = 155;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(155, clazz.TestByte);
        }
Пример #14
0
        public void TestNotNullableDateTime()
        {
            NullableClass clazz = new NullableClass();
            DateTime?     date  = new DateTime?(DateTime.Now);

            clazz.TestDateTime = date;

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(date.Value.ToString(), clazz.TestDateTime.Value.ToString());
        }
Пример #15
0
        public void TestNotNullableGuid()
        {
            NullableClass clazz = new NullableClass();
            Guid?         guid  = new Guid?(Guid.NewGuid());

            clazz.TestGuid = guid;

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(guid, clazz.TestGuid);
        }
Пример #16
0
        public void TestNotNullableTimeSpan()
        {
            NullableClass clazz = new NullableClass();
            TimeSpan?     span  = new TimeSpan?(new TimeSpan(1, 2, 3, 4, 5));

            clazz.TestTimeSpan = span;

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(span.Value.ToString(), clazz.TestTimeSpan.Value.ToString());
        }
Пример #17
0
        public void ConvertEntityToXml_NullableTest()
        {
            var nullableTestXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<xml>
  <Id><![CDATA[10]]></Id>
  <Name><![CDATA[Jeffrey Su]]></Name>
  <AgentId></AgentId>
  <MchId>123</MchId>
</xml>";
            var doc             = XDocument.Parse(nullableTestXml);
            var entity          = new NullableClass();

            EntityHelper.FillEntityWithXml(entity as RequestMessageBase, doc);

            Assert.AreEqual(10, entity.Id);
            Assert.AreEqual("Jeffrey Su", entity.Name);
            Assert.AreEqual(null, entity.AgentId);
            Assert.AreEqual(123, entity.MchId);
        }
Пример #18
0
        public void ConvertEntityToXml_NullableTest()
        {


            var nullableTestXml = @"<?xml version=""1.0"" encoding=""utf-8""?>
<xml>
  <Id><![CDATA[10]]></Id>
  <Name><![CDATA[Jeffrey Su]]></Name>
  <AgentId></AgentId>
  <MchId>123</MchId>
</xml>";
            var doc = XDocument.Parse(nullableTestXml);
            var entity = new NullableClass();
            EntityHelper.FillEntityWithXml(entity as RequestMessageBase, doc);

            Assert.AreEqual(10, entity.Id);
            Assert.AreEqual("Jeffrey Su", entity.Name);
            Assert.AreEqual(null, entity.AgentId);
            Assert.AreEqual(123, entity.MchId);
        }
Пример #19
0
    public static void ConditionalNull()
    {
        NullableClass variable = null;
        int?          k        = variable?.K;

        NullableClass[] array = null;
        k = array?[0].K;
        k = array?[0]?.K;

        NullableClass[] notnullarray = new NullableClass[] { new() };
        try
        {
            // vérifiez toujours que l'index est bien dans les limites du tableau
            k = notnullarray?[1]?.K;
        }
        catch (IndexOutOfRangeException e)
        {
            Console.WriteLine("L'index n'existe pas dans le tableau");
        }
    }
Пример #20
0
        public void TestNullableViaResultClass()
        {
            NullableClass clazz = new NullableClass();

            dataMapper.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetClassNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.IsNull(clazz.TestBool);
            Assert.IsNull(clazz.TestByte);
            Assert.IsNull(clazz.TestChar);
            Assert.IsNull(clazz.TestDateTime);
            Assert.IsNull(clazz.TestDecimal);
            Assert.IsNull(clazz.TestDouble);
            Assert.IsNull(clazz.TestGuid);
            Assert.IsNull(clazz.TestInt16);
            Assert.IsNull(clazz.TestInt32);
            Assert.IsNull(clazz.TestInt64);
            Assert.IsNull(clazz.TestSingle);
        }
Пример #21
0
        public void TestNullableArgument()
        {
            NullableClass clazz = new NullableClass();

            clazz.TestBool = true;
            clazz.TestByte = 155;
            clazz.TestChar = 'a';
            DateTime?date = new DateTime?(DateTime.Now);

            clazz.TestDateTime = date;
            clazz.TestDecimal  = 99.53M;
            clazz.TestDouble   = 99.5125;
            Guid?guid = new Guid?(Guid.NewGuid());

            clazz.TestGuid   = guid;
            clazz.TestInt16  = 45;
            clazz.TestInt32  = null;
            clazz.TestInt64  = 1234567890123456789;
            clazz.TestSingle = 4578.46445454112f;

            dataMapper.Insert("InsertNullable", clazz);

            clazz = null;
            clazz = dataMapper.QueryForObject <NullableClass>("GetNullableConstructor", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.IsTrue(clazz.TestBool.Value);
            Assert.AreEqual(155, clazz.TestByte);
            Assert.AreEqual('a', clazz.TestChar);
            Assert.AreEqual(date.Value.ToString(), clazz.TestDateTime.Value.ToString());
            Assert.AreEqual(99.53M, clazz.TestDecimal);
            Assert.AreEqual(99.5125, clazz.TestDouble);
            Assert.AreEqual(guid, clazz.TestGuid);
            Assert.AreEqual(45, clazz.TestInt16);
            Assert.IsNull(clazz.TestInt32);
            Assert.AreEqual(1234567890123456789, clazz.TestInt64);
            Assert.AreEqual(4578.46445454112f, clazz.TestSingle);
        }
Пример #22
0
        public void SaveSheetUseFormatForNullable()
        {
            // Arrange
            var exporter   = new Mapper();
            var sheetName  = "newSheet";
            var dateFormat = "yyyy.MM.dd hh.mm.ss";
            var obj1       = new NullableClass {
                NullableDateTime = null, DummyString = "dummy"
            };
            var obj2 = new NullableClass {
                NullableDateTime = DateTime.Now
            };

            if (File.Exists(FileName))
            {
                File.Delete(FileName);
            }

            // Act
            exporter.UseFormat(typeof(DateTime?), dateFormat);

            // Issue #5, if the first data row has null value, then next rows will not be formated
            // So here we make the first date row has a null value for DateTime? property.
            exporter.Save(FileName, new[] { obj1, obj2 }, sheetName);

            var items    = exporter.Take <NullableClass>(sheetName).ToList();
            var dateCell = exporter.Workbook.GetSheetAt(0).GetRow(2).GetCell(0);

            // Assert
            Assert.AreEqual(3, exporter.Workbook.GetSheet(sheetName).PhysicalNumberOfRows);
            Assert.AreEqual(obj1.DummyString, items.First().Value.DummyString);
            Assert.AreEqual(obj2.NullableDateTime.Value.ToLongDateString(), items.Skip(1).First().Value.NullableDateTime.Value.ToLongDateString());
            Assert.IsTrue(DateUtil.IsCellDateFormatted(dateCell));
            Assert.AreEqual(obj2.NullableDateTime.Value.ToLongDateString(), items.Skip(1).First().Value.NullableDateTime.Value.ToLongDateString());
            Assert.IsFalse(exporter.Take <NullableClass>(sheetName).First().Value.NullableDateTime.HasValue);
        }
Пример #23
0
        public void TestNotNullableDateTime()
        {
            NullableClass clazz = new NullableClass();
            DateTime? date = new DateTime?(DateTime.Now);
            clazz.TestDateTime = date;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(date.Value.ToString(), clazz.TestDateTime.Value.ToString());
        }
Пример #24
0
        public void TestNotNullableDouble()
        {
            NullableClass clazz = new NullableClass();
            clazz.TestDouble = 99.5125;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(99.5125, clazz.TestDouble);
        }
Пример #25
0
        public void TestNotNullableGuid()
        {
            NullableClass clazz = new NullableClass();
            Guid? guid = new Guid?(Guid.NewGuid());
            clazz.TestGuid = guid;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(guid, clazz.TestGuid);
        }
Пример #26
0
        public void TestNotNullableInt16()
        {
            NullableClass clazz = new NullableClass();
            clazz.TestInt16 = 45;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(45, clazz.TestInt16);
        }
Пример #27
0
        public void TestNotNullableInt64()
        {
            NullableClass clazz = new NullableClass();
            clazz.TestInt64 = 1234567890123456789;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(1234567890123456789, clazz.TestInt64);
        }
Пример #28
0
        public void TestNotNullableTimeSpan()
        {
            NullableClass clazz = new NullableClass();
            TimeSpan? span = new TimeSpan?(new TimeSpan(1, 2, 3, 4, 5));
            clazz.TestTimeSpan = span;

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.AreEqual(span.Value.ToString(), clazz.TestTimeSpan.Value.ToString());
        }
Пример #29
0
        public void TestNullableSingle()
        {
            NullableClass clazz = new NullableClass();

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(clazz.Id, 1);
            Assert.IsNull(clazz.TestSingle);
        }
Пример #30
0
        public void TestNullableTimeSpan()
        {
            NullableClass clazz = new NullableClass();
            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.IsNull(clazz.TestTimeSpan);
        }
Пример #31
0
        public void TestNullableViaResultClass()
        {
            NullableClass clazz = new NullableClass();

            sqlMap.Insert("InsertNullable", clazz);
            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetClassNullable", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.IsNull(clazz.TestBool);
            Assert.IsNull(clazz.TestByte);
            Assert.IsNull(clazz.TestChar);
            Assert.IsNull(clazz.TestDateTime);
            Assert.IsNull(clazz.TestDecimal);
            Assert.IsNull(clazz.TestDouble);
            Assert.IsNull(clazz.TestGuid);
            Assert.IsNull(clazz.TestInt16);
            Assert.IsNull(clazz.TestInt32);
            Assert.IsNull(clazz.TestInt64);
            Assert.IsNull(clazz.TestSingle);
        }
Пример #32
0
        public void DesNullableTest()
        {
            object obj = NullableClass.GetSampleInstance();

            PerformTest(obj);
        }
Пример #33
0
        public void TestNullableArgument()
        {
            NullableClass clazz = new NullableClass();
            clazz.TestBool = true;
            clazz.TestByte = 155;
            clazz.TestChar = 'a';
            DateTime? date = new DateTime?(DateTime.Now);
            clazz.TestDateTime = date;
            clazz.TestDecimal = 99.53M;
            clazz.TestDouble = 99.5125;
            Guid? guid = new Guid?(Guid.NewGuid());
            clazz.TestGuid = guid;
            clazz.TestInt16 = 45;
            clazz.TestInt32 = null;
            clazz.TestInt64 = 1234567890123456789;
            clazz.TestSingle = 4578.46445454112f;

            sqlMap.Insert("InsertNullable", clazz);

            clazz = null;
            clazz = sqlMap.QueryForObject<NullableClass>("GetNullableConstructor", 1);

            Assert.IsNotNull(clazz);
            Assert.AreEqual(1, clazz.Id);
            Assert.IsTrue(clazz.TestBool.Value);
            Assert.AreEqual(155, clazz.TestByte);
            Assert.AreEqual('a', clazz.TestChar);
            Assert.AreEqual(date.Value.ToString(), clazz.TestDateTime.Value.ToString());
            Assert.AreEqual(99.53M, clazz.TestDecimal);
            Assert.AreEqual(99.5125, clazz.TestDouble);
            Assert.AreEqual(guid, clazz.TestGuid);
            Assert.AreEqual(45, clazz.TestInt16);
            Assert.IsNull(clazz.TestInt32);
            Assert.AreEqual(1234567890123456789, clazz.TestInt64);
            Assert.AreEqual(4578.46445454112f, clazz.TestSingle);
        }