public void SaveTest() { // arrange NbtDocument expected; NbtDocument target; string fileName; fileName = this.GetWorkFile(); expected = new NbtDocument(this.CreateComplexData()); expected.FileName = fileName; // act try { expected.Save(); target = NbtDocument.LoadDocument(fileName); } finally { this.DeleteFile(fileName); } // assert NbtAssert.AreEqual(expected, target); }
public void Save_updates_filename_property() { // arrange NbtDocument target; string expected; string actual; expected = this.GetWorkFile(); target = new NbtDocument(this.CreateComplexData()); // act try { target.Save(expected); } finally { this.DeleteFile(expected); } // assert actual = target.FileName; Assert.AreEqual(expected, actual); }
public void EmptyListXmlTest() { // arrange NbtDocument reloaded; var fileName = GetWorkFile(); var target = new NbtDocument { Format = NbtFormat.Xml }; target.DocumentRoot.Name = "Test"; target.DocumentRoot.Value.Add("EmptyList", TagType.List, TagType.Compound); // act try { target.Save(fileName); reloaded = NbtDocument.LoadDocument(fileName); } finally { DeleteFile(fileName); } // assert // this test is essentially ensuring that an infinite loop when reloading an XML document is no longer present NbtAssert.Equal(target.DocumentRoot, reloaded.DocumentRoot); }
public void WriteEmptyByteArrayTest() { // arrange ITagWriter target; NbtDocument expected; MemoryStream stream; ITagReader reader; expected = new NbtDocument(); expected.DocumentRoot.Name = "WriteEmptyByteArrayTest"; expected.DocumentRoot.Value.Add("ByteArray", new byte[0]); expected.DocumentRoot.Value.Add("Byte", 255); stream = new MemoryStream(); target = new BinaryTagWriter(stream); // act target.WriteTag(expected.DocumentRoot, WriteTagOptions.None); // assert stream.Seek(0, SeekOrigin.Begin); reader = new BinaryTagReader(stream); this.CompareTags(expected.DocumentRoot, reader.ReadTag()); }
public void SaveTest() { // arrange NbtDocument target; var fileName = GetWorkFile(); var expected = new NbtDocument(CreateComplexData()) { FileName = fileName }; // act try { expected.Save(); target = NbtDocument.LoadDocument(fileName); } finally { DeleteFile(fileName); } // assert NbtAssert.Equal(expected, target); }
public void EmptyListXmlTest() { // arrange NbtDocument target; NbtDocument reloaded; string fileName; fileName = this.GetWorkFile(); target = new NbtDocument { Format = NbtFormat.Xml }; target.DocumentRoot.Name = "Test"; target.DocumentRoot.Value.Add("EmptyList", TagType.List, TagType.Compound); // act try { target.Save(fileName); reloaded = NbtDocument.LoadDocument(fileName); } finally { this.DeleteFile(fileName); } // assert // this test is essentially ensuring that an infinite loop when reloading an XML document is no longer present this.CompareTags(target.DocumentRoot, reloaded.DocumentRoot); }
public ICollection <string> Load(WorldInfo world) { var playerDataPath = Path.Combine(world.Path, PlayerDataFolder); var dataDir = new DirectoryInfo(playerDataPath); var endScreens = new List <string>(); if (!dataDir.Exists) { return(endScreens); } var playerFiles = dataDir.GetFiles("*.dat"); foreach (var file in playerFiles) { var playerId = file.Name.Replace(".dat", string.Empty); var nbtDoc = NbtDocument.LoadDocument(file.FullName); var seenCreditsValue = (byte)nbtDoc.Query("seenCredits").GetValue(); if (seenCreditsValue == 1) { endScreens.Add(playerId); } } return(endScreens); }
public void Constructor_throws_exception_if_compound_is_null() { // arrange NbtDocument target; // act target = new NbtDocument(null); }
public void GetDocumentFormat_should_throw_exception_if_file_not_found() { // arrange var fileName = Guid.NewGuid().ToString(); // act Assert.Throws <FileNotFoundException>(() => NbtDocument.GetDocumentFormat(fileName)); }
public void Load_should_throw_exception_for_null_stream() { // arrange var target = new NbtDocument(); // act Assert.Throws <ArgumentNullException>(() => target.Load((Stream)null)); }
public void IsNbtDocument_should_throw_exception_for_null_stream() { // arrange // act NbtDocument.IsNbtDocument((string)null); // assert }
public void GetDocumentFormat_should_throw_exception_with_null_filename() { // arrange // act NbtDocument.GetDocumentFormat((string)null); // assert }
public void GetDocumentFormat_should_throw_exception_with_null_stream() { // arrange // act NbtDocument.GetDocumentFormat((Stream)null); // assert }
public void GetDocumentName_should_throw_exception_if_filename_is_null() { // arrange // act NbtDocument.GetDocumentName(null); // assert }
public void GetDocumentName_should_throw_exception_if_filename_is_empty() { // arrange // act NbtDocument.GetDocumentName(string.Empty); // assert }
public void GetDocumentFormat_should_throw_exception_with_null_stream() { // arrange // act Assert.Throws <ArgumentNullException>(() => NbtDocument.GetDocumentFormat((Stream)null)); // assert }
public void GetDocumentName_should_throw_exception_if_filename_is_null() { // arrange // act Assert.Throws <ArgumentNullException>(() => NbtDocument.GetDocumentName(null)); // assert }
public void IsNbtDocument_should_throw_exception_for_null_stream() { // arrange // act Assert.Throws <ArgumentNullException>(() => NbtDocument.IsNbtDocument((string)null)); // assert }
public void GetDocumentFormat_throws_exception_for_non_seekable_streams() { // arrange Stream stream; stream = new DeflateStream(Stream.Null, CompressionMode.Decompress); // act NbtDocument.GetDocumentFormat(stream); }
public void Save_throws_exception_if_stream_is_null() { // arrange NbtDocument target; target = new NbtDocument(); // act target.Save((Stream)null); }
public void Save_throws_exception_if_filename_is_null() { // arrange var target = new NbtDocument(); // act var e = Assert.Throws <ArgumentNullException>(() => target.Save((string)null)); Assert.Equal($"Value cannot be null.{Environment.NewLine}Parameter name: fileName", e.Message); }
public void Constructor_should_have_have_empty_root() { // arrange // act var target = new NbtDocument(); // assert Assert.NotNull(target.DocumentRoot); }
public void Save_throws_exception_if_filename_is_null() { // arrange NbtDocument target; target = new NbtDocument(); // act target.Save((string)null); }
public void InvalidFormatTest() { // arrange var target = new NbtDocument(); // act Assert.Throws <ArgumentOutOfRangeException>(() => target.Format = (NbtFormat)(-1)); // assert }
public void Load_should_throw_exception_for_null_stream() { // arrange NbtDocument target; target = new NbtDocument(); // act target.Load((Stream)null); }
public void Save_throws_exception_if_filename_is_empty() { // arrange NbtDocument target; target = new NbtDocument(); // act target.Save(string.Empty); }
public void Load_should_throw_exception_for_null_filename() { // arrange NbtDocument target; target = new NbtDocument(); // act target.Load((string)null); }
public void IsNbtDocument_should_throw_exception_if_file_is_missing() { // arrange var fileName = Guid.NewGuid().ToString(); // act Assert.Throws <FileNotFoundException>(() => NbtDocument.IsNbtDocument(fileName)); // assert }
public void Load_should_throw_exception_for_invalid_file() { // arrange var fileName = BadFileName; var target = new NbtDocument(); // act Assert.Throws <InvalidDataException>(() => target.Load(fileName)); }
public void GetDocumentFormat_throws_exception_for_non_seekable_streams() { // arrange Stream stream = new DeflateStream(Stream.Null, CompressionMode.Decompress); // act var e = Assert.Throws <ArgumentException>(() => NbtDocument.GetDocumentFormat(stream)); Assert.Equal($"Stream is not seekable.{Environment.NewLine}Parameter name: stream", e.Message); }
public void Load_should_throw_exception_for_missing_file() { // arrange var fileName = Guid.NewGuid().ToString("N"); var target = new NbtDocument(); // act Assert.Throws <FileNotFoundException>(() => target.Load(fileName)); }
public void Constructor_should_have_have_empty_root() { // arrange NbtDocument target; // act target = new NbtDocument(); // assert Assert.IsNotNull(target.DocumentRoot); }
public void IsNbtDocument_should_return_true_for_xml_file() { // arrange var fileName = ComplexXmlDataFileName; // act var actual = NbtDocument.IsNbtDocument(fileName); // assert Assert.True(actual); }
public void ConstructorWithXmlFormatTest() { // arrange NbtDocument target; // act target = new NbtDocument(NbtFormat.Xml); // assert Assert.AreEqual(typeof(XmlTagReader), target.ReaderType); Assert.AreEqual(typeof(XmlTagWriter), target.WriterType); }
public void ConstructorWithCustomFormatTest() { // arrange NbtDocument target; // act target = new NbtDocument(NbtFormat.Custom); // assert Assert.IsNull(target.ReaderType); Assert.IsNull(target.WriterType); }
public void ConstructorTest() { // arrange NbtDocument target; // act target = new NbtDocument(); // assert Assert.IsNotNull(target.DocumentRoot); Assert.IsNotNull(target.WriterType); Assert.IsNotNull(target.ReaderType); }
public void Constructor_should_have_default_format() { // arrange NbtDocument target; NbtFormat expected; expected = NbtFormat.Binary; // act target = new NbtDocument(); // assert Assert.AreEqual(expected, target.Format); }
public void InvalidFormatTest() { // arrange NbtDocument target; target = new NbtDocument(); // act target.Format = (NbtFormat)(-1); // assert }
public void SetXmlFormatTest() { // arrange NbtDocument target; target = new NbtDocument(NbtFormat.Binary); // act target.Format = NbtFormat.Xml; // assert Assert.AreEqual(typeof(XmlTagReader), target.ReaderType); Assert.AreEqual(typeof(XmlTagWriter), target.WriterType); }
public void GetFormatTest() { // arrange NbtDocument target; NbtFormat expected1; NbtFormat expected2; NbtFormat expected3; NbtFormat expected4; NbtFormat expected5; NbtFormat actual1; NbtFormat actual2; NbtFormat actual3; NbtFormat actual4; NbtFormat actual5; target = new NbtDocument(); expected1 = NbtFormat.Binary; expected2 = NbtFormat.Binary; expected3 = NbtFormat.Binary; expected4 = NbtFormat.Xml; expected5 = NbtFormat.Custom; // act actual1 = target.GetFormat(this.ComplexDataFileName); // gzip compressed binary actual2 = target.GetFormat(this.DeflateComplexDataFileName); // deflate compressed binary actual3 = target.GetFormat(this.UncompressedComplexDataFileName); // raw binary actual4 = target.GetFormat(this.ComplexXmlDataFileName); // xml actual5 = target.GetFormat(this.BadFileName); // invalid // assert Assert.AreEqual(expected1, actual1); Assert.AreEqual(expected2, actual2); Assert.AreEqual(expected3, actual3); Assert.AreEqual(expected4, actual4); Assert.AreEqual(expected5, actual5); }
public void SetCustomFormatTest() { // arrange NbtDocument target; target = new NbtDocument(NbtFormat.Binary); // act target.Format = NbtFormat.Custom; // assert Assert.IsNull(target.ReaderType); Assert.IsNull(target.WriterType); }
public void Load_should_throw_exception_for_missing_file() { // arrange NbtDocument target; string fileName; fileName = Guid.NewGuid(). ToString("N"); target = new NbtDocument(); // act target.Load(fileName); }
public void SaveWithFileTest() { // arrange NbtDocument target1; NbtDocument target2; string fileName; fileName = this.GetWorkFile(); target1 = new NbtDocument(this.CreateComplexData()); // act try { target1.Save(fileName); target2 = NbtDocument.LoadDocument(fileName); } finally { this.DeleteFile(fileName); } // assert this.CompareTags(target1.DocumentRoot, target2.DocumentRoot); }
public void LoadWithFileTest() { // arrange NbtDocument target1; NbtDocument target2; string fileName; fileName = this.ComplexDataFileName; target1 = new NbtDocument(this.CreateComplexData()); target2 = new NbtDocument(); // act target2.Load(fileName); // assert this.CompareTags(target1.DocumentRoot, target2.DocumentRoot); }
public void FormatTest() { // arrange NbtDocument source; NbtDocument target1; NbtDocument target2; string fileName1; string fileName2; bool file1IsBinary; bool file2IsXml; fileName1 = this.GetWorkFile(); fileName2 = this.GetWorkFile(); source = new NbtDocument(this.CreateComplexData()); // act try { source.Format = NbtFormat.Binary; source.Save(fileName1); source.Format = NbtFormat.Xml; source.Save(fileName2); target1 = NbtDocument.LoadDocument(fileName1); target2 = NbtDocument.LoadDocument(fileName2); file1IsBinary = (target1.Format == NbtFormat.Binary); file2IsXml = (target2.Format == NbtFormat.Xml); } finally { this.DeleteFile(fileName1); this.DeleteFile(fileName2); } // assert Assert.IsTrue(file1IsBinary); Assert.IsTrue(file2IsXml); this.CompareTags(target1.DocumentRoot, target2.DocumentRoot); }
public void SaveBinaryTest() { // arrange TagCompound target; TagWriter writer; string fileName; byte[] source; byte[] destination; fileName = this.ComplexDataFileName; target = new NbtDocument(fileName).DocumentRoot; using (FileStream file = File.OpenRead(fileName)) source = this.Decompress(file); // act using (MemoryStream stream = new MemoryStream()) { writer = new BinaryTagWriter(stream, NbtOptions.Header); writer.Write(target); destination = stream.ToArray(); } File.WriteAllBytes(this.OutputFileName, destination); // assert CollectionAssert.AreEqual(source, destination); new NbtDocument(this.OutputFileName); }
public void Load_should_throw_exception_for_invalid_file() { // arrange NbtDocument target; string fileName; fileName = this.BadFileName; target = new NbtDocument(); // act target.Load(fileName); }