NOODB: Arrays Work – Mostly

Arrays mostly worked due to the collection support. But, not quite. While arrays are IList objects, they are of fixed size. Calling ADD on an array is invalid. Boom! As part of my anti-boom campaign, I figured I should fix this.

I had to code specifically for the array. If it’s an array, then it initializes the array to the correct size at instantiation. As it loops through the items, it populates the specific element and increments an index.

The arrays work as long as they’re a property of an object. It also works if you save an array of a particular type. But, saving an array of mixed types, by itself, does not work. The work on Collections and Arrays have revealed a design flaw with the database. Correcting this design flaw will probably be a significant task, but necessary. It will allow me to simplify the save operations. In essence, it needs to treat everything as an object rather than as object and properties. Most of the work (possibly all) is the database and database code.

I’m not sure when I’m going to tackle that. I’ll have to decide if I want to keep adding features or address this now. Adding new features won’t increase the complexity, so it’ll just come down to what I feel like doing. But, if I know me, I’ll probably start it tomorrow.

Enough about that. Here are the working array tests. All of the samples to date have shown the save and verification process. I’m going to reduce that to just the code that does the save. Trust that I have the asserts to confirm that it comes out the same way it went in. If you feel that more code would be helpful, let me know.

Working Tests

                int[] x = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

                ArrayTester array = new ArrayTester
                    FavoriteNumber = 93,
                    Items = new ArrayItem[] 
                         new ArrayItem {ItemName = "1"},
                         new ArrayItem {ItemName = "2"}

                ThisWillBeAPain[] pains = new ThisWillBeAPain[]
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = false, Ouchy = "1"},
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = true, Ouchy = "2"},
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = false, Ouchy = "3"},
                    new ThisWillBeAPain {Id = Guid.NewGuid(), ItHurts = false, Ouchy = "3"}

Broken Test

                object[] objects = new object[] { 3, false, "swell", new ArrayItem { ItemName = "item" } };

                object[] fromDb = client.GetObjects<object[]>()[0];
                Assert.AreEqual(4, fromDb.Length);
                Assert.AreEqual(3, fromDb[0]);
                Assert.AreEqual(false, fromDb[1]);
                Assert.AreEqual("swell", fromDb[2]);
                Assert.IsInstanceOfType(fromDb[3], typeof(ArrayItem));

The first assert works, but that’s it. The values all come back as null because values are stored at the property level, and there aren’t any properties.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: