예제 #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");
        }
예제 #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");
        }
예제 #3
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");
        }