示例#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");
        }
示例#2
0
        public void TestDatapackListener()
        {
            BaseDatapack disposedpack = new DatapackTestClass("path", "disposedpack");

            disposedpack.Dispose();

            bool packCalled      = false;
            bool otherPackCalled = false;
            bool running         = true;

            using (BaseDatapack pack = new DatapackTestClass("path", "pack"))
            {
                BaseDatapack.AddDatapackListener((p) =>
                {
                    if (running)
                    {
                        if (p.Name == "pack")
                        {
                            packCalled = true;
                        }
                        else if (p.Name == "otherpack")
                        {
                            otherPackCalled = true;
                        }
                        else if (p.Name == "disposedpack")
                        {
                            Assert.Fail("disposed pack called datapack listeners (From " + nameof(TestDatapackListener) + ")");
                        }
                    }
                });
                Assert.IsTrue(packCalled, "pack didn't call datapack listener");
            }

            using (BaseDatapack pack = new DatapackTestClass("path", "otherpack"))
            {
                Assert.IsTrue(otherPackCalled, "new pack didn't call datapack listener");
            }
            running = false;
        }