public void Add_new_object_returned_name_checked() { Animal expected = new Bear("Ben", 300); Animal actual = cr.Add(cr.Name, cr.Weight); Assert.AreEqual(expected.name, actual.name); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.GetEntry(opfFilePath); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (Stream zipStream = _EpubFile.GetInputStream(zipEntry)) { using (MemoryStream memoryStream = new MemoryStream()) { byte[] buffer = new byte[4096]; // 4K is optimum StreamUtils.Copy(zipStream, memoryStream, buffer); memoryStream.Position = 0; contentOpf = XElement.Load(memoryStream); } } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null ? contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; UUID = contentOpf.Elements(xNamespace + "metadata").Elements() .FirstOrDefault(e => e.Name.LocalName == "identifier" && e.HasAttributes && e.Attribute("id") != null && e.Attribute("id").Value == uniqueIdentifier ).Value; foreach ( var metadataElement in contentOpf.Element(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase)); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (MemoryStream memoryStream = new MemoryStream()) { zipEntry.Extract(memoryStream); // Fix buggy "<?xml verison="1.1"?> // See http://stackoverflow.com/questions/912440/xdocument-cant-load-xml-with-version-1-1-in-c-sharp-linq byte[] b = memoryStream.ToArray(); for (int i = 0; i < 50; i++) { // Check for version="1.1" and replace if found if (b[i] == 0x76 && b[i + 1] == 0x65 && b[i + 2] == 0x72 && b[i + 3] == 0x73 && b[i + 4] == 0x69 && b[i + 5] == 0x6F && b[i + 6] == 0x6E && b[i + 7] == 0x3D && b[i + 8] == 0x22 && b[i + 9] == 0x31 && b[i + 10] == 0x2E && b[i + 11] == 0x31) { b[i + 11] = 0x30; } } using (MemoryStream fixedStream = new MemoryStream(b)) { contentOpf = XElement.Load(fixedStream); } b = null; } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; try { UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attributes("id").FirstOrDefault() != null && e.Attribute("id").Value == uniqueIdentifier).Value; } catch { } foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase)); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (MemoryStream memoryStream = new MemoryStream()) { zipEntry.Extract(memoryStream); memoryStream.Position = 0; contentOpf = XElement.Load(memoryStream); } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; try { UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attribute("id").Value == uniqueIdentifier).Value; } catch { } foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
public void TestInitiialize() { Aviary = new Zoo("Aviary", 0); cr = new GiraffeCreator("Buch", 300); animal1 = cr.Add(cr.Name, cr.Weight); }
public void TestInitiialize() { Aviary = new Zoo("Aviary", 0); cr = new WolfCreator("Moon", 300); animal1 = cr.Add(cr.Name, cr.Weight); }