Exemplo n.º 1
0
        public void ObjectValueSource_Prop()
        {
            var test = new TestObject();

            Assert.AreEqual(StringValue, test.GetValue(GoodValueName));
            AssertPlus.Throws(() => { var dummy = test.GetValue(BadValueName); });
        }
Exemplo n.º 2
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");
        }
Exemplo n.º 3
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"));
        }
Exemplo n.º 4
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"));
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void AtomCollectionData_Named()
        {
            var named1  = MakeNamedAtom();
            var named2  = MakeNamedAtom();
            var unnamed = MakeUnnamedAtom();

            var data = new AtomCollectionData();

            data.AddAtom(named1);
            AssertPlus.Throws(() => { data.AddAtom(unnamed); });
            Assert.IsNull(data[named2.Name]);
            data.AddAtom(named2);
            Assert.AreEqual(named2, data[named2.Name]);

            Assert.AreEqual(2, data.Atoms.Count());
        }
Exemplo n.º 7
0
        public void AtomCollectionData_Unnamed()
        {
            var named    = MakeNamedAtom();
            var unnamed1 = MakeUnnamedAtom();
            var unnamed2 = MakeUnnamedAtom();

            var data = new AtomCollectionData();

            data.AddAtom(unnamed1);
            data.AddAtom(unnamed2);
            data.AddAtom(unnamed1);
            AssertPlus.Throws(() => { data.AddAtom(named); });
            AssertPlus.Throws(() => { var atom = data[named.Name]; });

            Assert.AreEqual(3, data.Atoms.Count());
            var atoms = data.Atoms.ToArray();

            Assert.AreEqual(unnamed1, atoms[2]);
            Assert.AreEqual(unnamed2, atoms[1]);
        }
Exemplo n.º 8
0
 public static T AreEqual <T>(IEnumerable <T> values)
 {
     return(AssertPlus.AreEqual(values.GetEnumerator()));
 }
Exemplo n.º 9
0
 public static T AreEqual <T>(IEnumerator <T> values)
 {
     (var first, var rest) = Utils.FirstRest(values);
     AssertPlus.AreEqual(first, rest);
     return(first);
 }
Exemplo n.º 10
0
 public static T AreEqual <T>(T first, IEnumerable <T> others)
 {
     return(AssertPlus.AreEqual(first, others.GetEnumerator()));
 }
Exemplo n.º 11
0
 public static T GetOnlyComponent <T>(this GameObject gameObject)
 {
     return(AssertPlus.OnlyOne(gameObject.GetComponents <T>()));
 }