コード例 #1
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();
        }
コード例 #2
0
ファイル: GroupTests.cs プロジェクト: Vilder50/SharpCraft
        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");
        }
コード例 #3
0
ファイル: GroupTests.cs プロジェクト: Vilder50/SharpCraft
        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");
        }
コード例 #4
0
        public void TestGetPath()
        {
            //setup
            BasePackNamespace pack = new NamespaceTestClass(new DatapackTestClass("a folder path", "pack"), "namespace");

            //test
            Assert.AreEqual("a folder path/pack/data/namespace/", pack.GetPath());
            pack.Dispose();
        }
コード例 #5
0
        public void TestIsSettingSet()
        {
            //setup
            BasePackNamespace pack = new NamespaceTestClass(new DatapackTestClass("a folder path", "pack"), "namespace");

            //test
            Assert.IsTrue(pack.IsSettingSet(NamespaceSettings.GetSettings().FunctionGroupedCommands()), "Failed to detect that the setting is set");
            Assert.IsFalse(pack.IsSettingSet(NamespaceSettings.GetSettings().GenerateNames()), "Failed to detect that the setting isn't set");
            pack.Dispose();
        }
コード例 #6
0
        public void TestDispose()
        {
            BasePackNamespace space = new NamespaceTestClass(new DatapackTestClass("a folder path", "pack"), "namespace");

            Assert.IsFalse(space.Disposed, "namespace shouldn't have been disposed yet");
            Assert.IsFalse(space.GetFile("test2", "file1") !.Disposed, "namespace isn't disposed yet and the file shouldn't be disposed yet");
            space.Dispose();
            Assert.IsTrue(((NamespaceTestClass)space).RandomValue, "AfterDispose didn't run");
            Assert.IsTrue(space.Disposed, "namespace should have been disposed");
            Assert.IsTrue(space.GetFile("test2", "file1") !.Disposed, "namespace is disposed and the file should be disposed");

            Assert.ThrowsException <InvalidOperationException>(() => new BaseFileTestClass1(space, "afile", BaseFile.WriteSetting.Auto), "Shouldn't be able to add more files since namespace is disposed");
        }
コード例 #7
0
        public void TestGetFile()
        {
            //setup
            BasePackNamespace pack = new NamespaceTestClass(new DatapackTestClass("a folder path", "pack"), "namespace");

            //test
            Assert.AreEqual("file1", pack.GetFile("test1", "file1") !.FileId, "GetFile failed to get the file with the correct name");
            Assert.AreEqual(BaseFile.WriteSetting.OnDispose, pack.GetFile("test1", "file1") !.Setting, "GetFile failed to get the file of the correct type");
            Assert.AreEqual("file2", pack.GetFile("test1", "file2") !.FileId, "GetFile failed to get the other file with the other name");
            Assert.AreEqual(BaseFile.WriteSetting.Auto, pack.GetFile("test2", "file1") !.Setting, "GetFile failed to get the file of the other type");

            //test exception on extra file with same name and same type
            Assert.ThrowsException <ArgumentException>(() => new BaseFileTestClass1(pack, "file1", BaseFile.WriteSetting.Auto), "Adding 2 files with the same name and same type should cast an exception");
            Assert.ThrowsException <InvalidOperationException>(() => pack.GetFile("test2", "file3"), "should not be able to get locked file");
            pack.Dispose();
        }
コード例 #8
0
ファイル: GroupTests.cs プロジェクト: Vilder50/SharpCraft
        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");
        }
コード例 #9
0
        public void TestBaseFile()
        {
            //setup
            BaseFileTestClass.WriterToUse = new StringWriter();
            NamespaceTestClass packNamespace = new NamespaceTestClass(new DatapackTestClass("pack", "path"), "namespace");
            BaseFile           file          = new BaseFileTestClass(packNamespace, "My/File", BaseFile.WriteSetting.Auto);

            //test
            Assert.AreEqual("my/file", file.FileId, "file name is not getting set by constructor");
            Assert.AreEqual(packNamespace, file.PackNamespace, "Packnamespace is not getting set by the constructor");
            Assert.AreEqual(file, packNamespace.GetFile("filetest", file.FileId), "Constructor is not adding the file to the namespace");
            file.Dispose();

            file = new BaseFileTestClass(packNamespace, null !, BaseFile.WriteSetting.Auto);
            Assert.AreEqual("1", file.FileId, "file name wasn't generated correctly");
            file.Dispose();

            packNamespace.AddSetting(NamespaceSettings.GetSettings().GenerateNames());
            file = new BaseFileTestClass(packNamespace, "folder\\ignored-name", BaseFile.WriteSetting.Auto);
            Assert.AreEqual("2", file.WritePath, "writepath wasn't forced to be generated");
            Assert.AreEqual("folder/ignored-name", file.FileId, "filename wasn't kept after forced path generation");
            file.Dispose();
        }