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");
        }
        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();
        }
Example #3
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();
        }