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(); }
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(); }
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(); }
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(); }