void TestDeriverEffect <T>(AssembledStyles astyles, T defVal, T newVal, T otherVal, PropReader <T> reader, StyleDeriver <T> deriver, string label, HashSet <AssembledStyles> outputStyles) { Assert.AreEqual(defVal, reader(astyles), "default " + label + " should be normal"); AssembledStyles derivedStyles = deriver(astyles, newVal); int oldCount = outputStyles.Count; outputStyles.Add(derivedStyles); Assert.AreEqual(oldCount + 1, outputStyles.Count, "new derived styles should not be equal to any earlier one"); Assert.AreEqual(newVal, reader(derivedStyles), "derived AS should have " + label + " property set"); Assert.AreEqual(defVal, reader(astyles), "original AS should not be changed by With... - " + label); Assert.AreNotEqual(astyles, derivedStyles, "two different AS's should not be equal"); AssembledStyles derivedStyles2 = deriver(astyles, newVal); Assert.IsTrue(Object.ReferenceEquals(derivedStyles2, derivedStyles), "two astyles derived the same way should be the same object - " + label); AssembledStyles derivedStyles3 = deriver(derivedStyles2, otherVal); AssembledStyles derivedStyles4 = deriver(astyles, otherVal); Assert.IsTrue(Object.ReferenceEquals(derivedStyles3, derivedStyles4), "two equivalent astyles derived differently should be the same object - " + label); var rawDerived = new AssembledStyles(derivedStyles2); Assert.AreEqual(newVal, reader(rawDerived), "copy consructor should copy " + label + " property"); }
public static PixelArtDocument LoadFrom(Stream inputStream) { // ファイル マジック ナンバー using (var br = new BinaryReader(inputStream, Encoding.UTF8, true)) { var mnBuf = br.ReadBytes(_fileMn.Length); for (var i = 0; i < mnBuf.Length; i++) { if (_fileMn[i] != mnBuf[i]) { throw new Exception("File is not a valid document."); } } } // 読み取り Props props = null; using (var propReader = new PropReader(inputStream)) props = propReader.ReadAllProps(); // メタチェック var invalidFile = false; if (((String)props.Sections["mcpixart-file-meta"].Items["magic-number"].Value) != " MCPIXART ") { invalidFile = true; } if (((Int64)props.Sections["mcpixart-file-meta"].Items["file-version"].Value) != 1) { invalidFile = true; } if (invalidFile) { throw new Exception("File is not a valid document."); } // ドキュメント ロード var documentTitle = (String)props.Sections["mcpixart-file-doc"].Items["document-title"].Value; var documentAuthor = (String)props.Sections["mcpixart-file-doc"].Items["document-author"].Value; var documentDescription = (String)props.Sections["mcpixart-file-doc"].Items["document-description"].Value; var artSize = (PixelArtSize)props.Sections["mcpixart-file-doc"].Items["art-size"].Value; var itemPalette = ((String[])props.Sections["mcpixart-file-doc"].Items["art-palette"].Value).Select(itemId => MCItemUtils.GetItemById(itemId)).ToArray(); var pixels = ((Int16[])props.Sections["mcpixart-file-doc"].Items["art-pixels"].Value).Select(i => itemPalette[i]).ToArray(); return(new PixelArtDocument() { DocumentTitle = documentTitle, DocumentAuthor = documentAuthor, DocumentDescription = documentDescription, Size = artSize, Pixels = pixels, }); }
public void Test004() { using (var fs = File.OpenRead(".\\QuickTest-Test003.txt")) using (var pr = new PropReader(fs)) { var props = pr.ReadAllProps(); foreach (var sect in props.Sections) { this.TestContext.WriteLine("[{0}]", sect.Name); foreach (var propItem in sect.Items) { this.TestContext.WriteLine("{0}={1}:{2}", propItem.Name, propItem.Type, propItem.Value); } } } }