Ejemplo n.º 1
0
        public void TestItems()
        {
            //setup
            using DatapackTestClass pack = new DatapackTestClass("path", "pack");
            NamespaceTestClass packNamespace = new NamespaceTestClass(pack, "namespace");

            //test
            TestGroupClass.WriterToUse = new StringWriter();
            TestGroupClass group = new TestGroupClass(packNamespace, "name1", new List <GroupItemClass> {
                new GroupItemClass("test")
            }, false, BaseFile.WriteSetting.LockedOnDispose);

            Assert.ThrowsException <ArgumentNullException>(() => group.Items = null !, "Items should not be able to be null");
            group.Items = new List <GroupItemClass>()
            {
            };
            group.Dispose();

            TestGroupClass.WriterToUse = new StringWriter();
            group = new TestGroupClass(packNamespace, "name2", new List <GroupItemClass> {
                new GroupItemClass("test")
            }, false, BaseFile.WriteSetting.LockedAuto);
            Assert.ThrowsException <InvalidOperationException>(() => group.Items = new List <GroupItemClass>()
            {
            }, "Items should not be changeable because the file is auto");
        }
Ejemplo n.º 2
0
        public void TestWriting()
        {
            //setup
            using DatapackTestClass pack = new DatapackTestClass("path", "pack");
            NamespaceTestClass packNamespace = new NamespaceTestClass(pack, "namespace");

            //test
            TestGroupClass.WriterToUse = new StringWriter();
            TestGroupClass group = new TestGroupClass(packNamespace, "name1", new List <GroupItemClass> {
                new GroupItemClass("test")
            }, true, BaseFile.WriteSetting.LockedOnDispose);

            group.Items.Add(new GroupItemClass("test2"));
            group.Items.Add(new GroupItemClass("test3"));
            Assert.AreEqual("", ((StringWriter)TestGroupClass.WriterToUse).GetStringBuilder().ToString(), "Group shouldn't have been written yet");
            group.Dispose();
            Assert.AreEqual("{\"values\":[\"test\",\"test2\",\"test3\"]}", ((StringWriter)TestGroupClass.WriterToUse).GetStringBuilder().ToString(), "Group wasn't written correctly");

            TestGroupClass.WriterToUse = new StringWriter();
            group = new TestGroupClass(packNamespace, "name2", new List <GroupItemClass> {
                new GroupItemClass("test")
            }, false, BaseFile.WriteSetting.LockedAuto);
            group.Dispose();
            Assert.IsTrue(group.Disposed);
            Assert.AreEqual("{\"replace\":true,\"values\":[\"test\"]}", ((StringWriter)TestGroupClass.WriterToUse).GetStringBuilder().ToString(), "Group didn't write AppendFile correctly");
            Assert.IsNull(group.Items, "Items wasn't cleared");
        }
Ejemplo n.º 3
0
        public void TestBasePackNamespace()
        {
            //setup
            BaseDatapack      datapack = new DatapackTestClass("a folder path", "pack");
            BasePackNamespace space    = new NamespaceTestClass(datapack, "namespace");

            //test
            Assert.IsTrue(space.IsSetup);
            Assert.AreEqual(datapack, space.Datapack, "datapack is not getting set by the constructor");
            Assert.AreEqual("namespace", space.Name, "name is not getting set by the constructor");
            new BaseFileTestClass1(space, "file3", BaseFile.WriteSetting.Auto).Dispose();
            space.Dispose();

            //test none setup pack
            space = new NamespaceTestClass();
            //test
            Assert.IsFalse(space.IsSetup, "Empty constructor was called so it shouldn't have been setup already");
            Assert.ThrowsException <InvalidOperationException>(() => _ = space.Name, "Name didn't throw exception even though it isn't setup");
            Assert.ThrowsException <InvalidOperationException>(() => _ = space.Datapack, "Datapack didn't throw exception even though it isn't setup");

            space.Setup(datapack, "namespace2");
            Assert.IsTrue(space.IsSetup, "Setup has been called so it should have been setup");
            Assert.AreEqual(datapack, space.Datapack, "datapack is not getting set by bysetup");
            Assert.AreEqual("namespace2", space.Name, "name is not getting set by setup");
            space.Dispose();
        }
Ejemplo n.º 4
0
 public void TestBaseDatapack()
 {
     //setup
     using BaseDatapack pack = new DatapackTestClass("a path", "nAme");
     //test
     Assert.AreEqual("a path", pack.Path, "Path is not getting set by the constructor");
     Assert.AreEqual("name", pack.Name, "Name is not getting set by the constructor");
 }
Ejemplo n.º 5
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");
        }
Ejemplo n.º 6
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");
        }
Ejemplo n.º 7
0
        public void TestGroup()
        {
            //setup
            TestGroupClass.WriterToUse   = new StringWriter();
            using DatapackTestClass pack = new DatapackTestClass("path", "pack");
            NamespaceTestClass    packNamespace = new NamespaceTestClass(pack, "namespace");
            List <GroupItemClass> items         = new List <GroupItemClass>
            {
                new GroupItemClass("test"),
                new GroupItemClass("test"),
                new GroupItemClass("test2")
            };
            bool append = true;

            //test
            TestGroupClass group = new TestGroupClass(packNamespace, "name", items, append, BaseFile.WriteSetting.LockedOnDispose);

            Assert.AreEqual(items, group.Items, "Items were not set correctly by the constructor");
            Assert.AreEqual(append, group.AppendGroup, "AppendGroup was not set correctly by the constructor");
        }
Ejemplo n.º 8
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;
        }