NOODB: Nullable Types Work

The SAVE part of NullableTypes went in with almost no work.

The retrieve, though… that got hairy. It required serializer changes and server changes.

The CRAZY object has a a few nullable type properites. The first test sets them all to null and shows that they come bgck as null. The second test gives them each a value and confirms that the value comes back.

 

        [TestMethod]
        public void TestNull()
        {
            TestUtility.DeleteTestData();
            try
            {
                NoodbClient client = new NoodbClient(new Server(TestUtility.DefaultUnityContainer));
                client.RegisterType<Crazy>();

                Crazy crazy = new Crazy
                {
                    Id = Guid.NewGuid(),
                    NullableBool = null,
                    NullableDate = null,
                    NullableInt = null,
                    NullableGuid = null
                };

                client.Save(crazy);

                Crazy fromDb = client.GetObjects<Crazy>()[0];
                Assert.IsNull(fromDb.NullableBool);
                Assert.IsNull(fromDb.NullableDate);
                Assert.IsNull(fromDb.NullableInt);
                Assert.IsNull(fromDb.NullableGuid);
            }
            finally
            {
                // TestUtility.DeleteTestData();
            }
        }

        [TestMethod]
        public void TestNotNull()
        {
            TestUtility.DeleteTestData();
            try
            {
                NoodbClient client = new NoodbClient(new Server(TestUtility.DefaultUnityContainer));
                client.RegisterType<Crazy>();

                Crazy crazy = new Crazy
                {
                    Id = Guid.NewGuid(),
                    NullableBool = true,
                    NullableDate = DateTime.Parse("1/3/2010"),
                    NullableInt = 79,
                    NullableGuid = Guid.NewGuid()
                };

                client.Save(crazy);

                Crazy fromDb = client.GetObjects<Crazy>()[0];
                Assert.IsTrue(fromDb.NullableBool.Value);
                Assert.AreEqual(DateTime.Parse("1/3/2010"), fromDb.NullableDate);
                Assert.AreEqual(79, fromDb.NullableInt);
                Assert.IsNotNull(fromDb.NullableGuid);
            }
            finally
            {
                // TestUtility.DeleteTestData();
            }
        }

Nullable enums don’t work yet. I added that to the TO DO list.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: