ソースを参照

Test cases for Nullable types

Brad Robinson 11 年 前
コミット
1d1cc5b441
2 ファイル変更53 行追加1 行削除
  1. 2 1
      TestCases/TestCases.csproj
  2. 51 0
      TestCases/TestNullableTypes.cs

+ 2 - 1
TestCases/TestCases.csproj

@@ -20,7 +20,7 @@
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
     <OutputPath>bin\Debug\</OutputPath>
-    <DefineConstants>TRACE;DEBUG;PETAJSON_NO_EMIT</DefineConstants>
+    <DefineConstants>TRACE;DEBUG</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
@@ -52,6 +52,7 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="TestAbstractTypes.cs" />
     <Compile Include="TestCustomFormat.cs" />
+    <Compile Include="TestNullableTypes.cs" />
     <Compile Include="TestOptions.cs" />
     <Compile Include="TestPrimitiveTypes.cs" />
     <Compile Include="TestsEvents.cs" />

+ 51 - 0
TestCases/TestNullableTypes.cs

@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using PetaTest;
+using PetaJson;
+
+namespace TestCases
+{
+    class NullableContainer
+    {
+        public int? Field;
+        public int? Prop { get; set; }
+    }
+
+    [TestFixture]
+    public class TestNullableTypes
+    {
+        [Test]
+        public void TestNull()
+        {
+            var nc = new NullableContainer();
+
+            var json = Json.Format(nc);
+            Console.WriteLine(json);
+            Assert.Contains(json, "null");
+
+            var nc2 = Json.Parse<NullableContainer>(json);
+            Assert.IsNull(nc2.Field);
+            Assert.IsNull(nc2.Prop);
+        }
+
+        [Test]
+        public void TestNotNull()
+        {
+            var nc = new NullableContainer()
+            {
+                Field = 23,
+                Prop = 24,
+            };
+
+            var json = Json.Format(nc);
+            Console.WriteLine(json);
+            Assert.DoesNotContain(json, "null");
+
+            var nc2 = Json.Parse<NullableContainer>(json);
+            Assert.AreEqual(nc2.Field.Value, 23);
+            Assert.AreEqual(nc2.Prop.Value, 24);
+        }
+    }
+}