Exemplo n.º 1
0
        public void TestDispose()
        {
            BaseDatapack      pack  = new DatapackTestClass("a path", "name");
            BasePackNamespace space = pack.Namespace <NamespaceTestClass>("namespace");

            Assert.IsFalse(pack.Disposed, "Pack wasn't disposed and shouldn't be disposed");
            Assert.IsFalse(space.Disposed, "namespace in pack wasn't disposed and shouldn't be disposed");

            pack.Dispose();
            Assert.IsTrue(((DatapackTestClass)pack).RandomValue, "AfterDispose didn't run");
            Assert.IsTrue(pack.Disposed, "Pack was disposed and should be disposed");
            Assert.IsTrue(space.Disposed, "namespace in pack was disposed and should be disposed since the pack is disposed");
            Assert.ThrowsException <InvalidOperationException>(() => pack.Namespace <NamespaceTestClass>("namespace"), "Shouldn't be able to get/create namespaces after pack has been disposed");
        }
Exemplo n.º 2
0
        public void TestNamespace()
        {
            //setup
            using BaseDatapack pack = new DatapackTestClass("a path", "name");
            //test
            BasePackNamespace space1 = pack.Namespace <NamespaceTestClass>("namespace");
            BasePackNamespace space2 = pack.Namespace <NamespaceTestClass>("namespace");
            BasePackNamespace space3 = pack.Namespace <NamespaceTestClass>("potato");

            Assert.IsTrue(space1.IsSetup, "namespace was not setup");
            Assert.AreEqual("namespace", space1.Name, "Namespace did not get correct name");
            Assert.AreEqual(space1, space2, "namespace failed to find and return existing namespace");
            Assert.AreEqual("potato", space3.Name, "Namespace failed to add extra namespace");
            Assert.AreNotEqual(space1, space3, "Namespace failed to output correct namespace");

            Assert.ThrowsException <ArgumentException>(() => new NamespaceTestClass(pack, "namespace"), "Cannot have 2 namespaces with the same name");
        }