예제 #1
0
        public void TestRequireFalse()
        {
            AssertPlus.ExceptionThrown <Exception>(() => Contract.Requires(false));
            var ex = AssertPlus.ExceptionThrown <Exception>(() => Contract.Requires(false, "foo"));

            Assert.AreEqual(ex.Message, "foo");

            AssertPlus.ExceptionThrown <ArgumentException>(() => Contract.Requires <ArgumentException>(false));
            var ax = AssertPlus.ExceptionThrown <ArgumentException>(() => Contract.Requires <ArgumentException>(false, "bar"));

            Assert.AreEqual(ax.Message, "bar");
        }
예제 #2
0
        public void TestWatch()
        {
            var changed = false;

            var testInstance = new TestChangeable();

            var watcher = testInstance.AddWatcher("Foo", () => changed = true);

            Assert.IsTrue(watcher.IsWatching("Foo"));

            Assert.IsFalse(changed);
            testInstance.Foo = 1;
            Assert.IsTrue(changed);

            // test dupe watcher not allowed...
            AssertPlus.ExceptionThrown <ArgumentException>(() =>
            {
                watcher.AddWatcher("Foo", () => { });
            });

            // Clear out the foo watch and try again
            watcher.StopWatching("Foo");

            changed = false;
            watcher.AddWatcher("Foo", () => changed = true);
            testInstance.Foo = 5;

            Assert.IsTrue(changed);

            watcher.StopWatchingAll();

            Assert.IsFalse(watcher.IsWatching("Foo"));

            int changeCount = 0;

            watcher.AddWatcher(new[] { "Foo", "Bar", "Baz" }, () => { changeCount++; });
            Assert.IsTrue(watcher.IsWatching("Foo"));
            Assert.IsTrue(watcher.IsWatching("Bar"));
            Assert.IsTrue(watcher.IsWatching("Baz"));

            testInstance.Foo = 10;
            testInstance.Bar = 11;
            testInstance.Baz = 12;

            Assert.AreEqual(3, changeCount);

            watcher.StopWatchingAll();

            Assert.IsFalse(watcher.IsWatching("Foo"));
            Assert.IsFalse(watcher.IsWatching("Bar"));
            Assert.IsFalse(watcher.IsWatching("Baz"));
        }
예제 #3
0
        public void TestMissingProperty()
        {
            var intValue = Util.Rnd.Next(500);
            var uriValue = new Uri("http://testCrazy");

            var values = new Dictionary <string, object>()
            {
                { "IntProperty", intValue },
                { "UriProperty", uriValue }
            };

            var argEx = AssertPlus.ExceptionThrown <ArgumentException>(() => _factory.CreateInstance(values));

            Assert.IsTrue(argEx.Message.StartsWith("missing required key StringProperty"));
        }
예제 #4
0
        public void TestListItemMover()
        {
            IList <int> result;

            int[] indicies = new int[] { };

            Assert.IsFalse(ListReorderUtil.CanReorder(indicies, 0, ReorderDirection.Beginning));
            Assert.IsFalse(ListReorderUtil.CanReorder(indicies, 0, ReorderDirection.Beginning));
            Assert.IsFalse(ListReorderUtil.CanReorder(indicies, 10, ReorderDirection.End));
            Assert.IsFalse(ListReorderUtil.CanReorder(indicies, 10, ReorderDirection.Beginning));

            // last item in a list 6 long, move it all the way to the beginning
            result = indicies = new int[] { 5 };
            AssertPlus.ExceptionThrown <Exception>(() => ListReorderUtil.CanReorder(indicies, 5, ReorderDirection.Beginning));
            for (int i = 0; i < 5; i++)
            {
                Assert.IsTrue(ListReorderUtil.CanReorder(result, 6, ReorderDirection.Beginning));
                result = ListReorderUtil.Reorder(result, 6, ReorderDirection.Beginning);
                Assert.AreEqual(4 - i, result[0]);
            }
            Assert.AreEqual(0, result[0]);
            Assert.IsFalse(ListReorderUtil.CanReorder(result, 6, ReorderDirection.Beginning));

            // now move it all the way back to the end
            for (int i = 0; i < 5; i++)
            {
                Assert.IsTrue(ListReorderUtil.CanReorder(result, 6, ReorderDirection.End));
                result = ListReorderUtil.Reorder(result, 6, ReorderDirection.End);
                Assert.AreEqual(1 + i, result[0]);
            }
            Assert.AreEqual(5, result[0]);
            Assert.IsFalse(ListReorderUtil.CanReorder(result, 6, ReorderDirection.End));

            indicies = new int[] { 1, 2 };
            Assert.IsTrue(ListReorderUtil.CanReorder(indicies, 3, ReorderDirection.Beginning));
            Assert.IsFalse(ListReorderUtil.CanReorder(indicies, 3, ReorderDirection.End));

            for (int i = 3; i < 5; i++)
            {
                result = ListReorderUtil.Reorder(indicies, i, ReorderDirection.Beginning);
                Assert.AreEqual(result[0], 0);
                Assert.AreEqual(result[1], 1);
            }

            result = ListReorderUtil.Reorder(indicies, 4, ReorderDirection.End);
            Assert.AreEqual(result[0], 2);
            Assert.AreEqual(result[1], 3);
        }