public void WriteSimpleCopyrightFileWorks() { var copyrights = new SIL.ExtractCopyright.DebianControl(); var para = new SIL.ExtractCopyright.DebianParagraph(); copyrights.Paragraphs.Add(para); para.Fields.Add(new SIL.ExtractCopyright.DebianField("Format", "http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/")); para.Fields.Add(new SIL.ExtractCopyright.DebianField("Upstream-Name", "MyProgram")); para.Fields.Add(new SIL.ExtractCopyright.DebianField("Upstream-Contact", "*****@*****.**")); para.Fields.Add(new SIL.ExtractCopyright.DebianField("Source", "https://github.com/myopensourcepersona/MyProgram")); para = new SIL.ExtractCopyright.DebianParagraph(); copyrights.Paragraphs.Add(para); para.Fields.Add(new SIL.ExtractCopyright.DebianField("Files", "*")); para.Fields.Add(new SIL.ExtractCopyright.DebianField("Copyright", "2017 Me Myself")); var field = new SIL.ExtractCopyright.DebianField("License", "MIT"); para.Fields.Add(field); field.FullDescription.Add("Permission is hereby granted, free of charge, to any person obtaining a"); field.FullDescription.Add("copy of this software and associated documentation files (the \"Software\"),"); field.FullDescription.Add("to deal in the Software without restriction, including without limitation"); field.FullDescription.Add("the rights to use, copy, modify, merge, publish, distribute, sublicense,"); field.FullDescription.Add("and/or sell copies of the Software, and to permit persons to whom the"); field.FullDescription.Add("Software is furnished to do so, subject to the following conditions:"); field.FullDescription.Add(""); field.FullDescription.Add("The above copyright notice and this permission notice shall be included"); field.FullDescription.Add("in all copies or substantial portions of the Software."); field.FullDescription.Add("."); field.FullDescription.Add("THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS"); field.FullDescription.Add("OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF"); field.FullDescription.Add("ETC, ETC, ETC. ENOUGH FOR THIS TEST!"); var mem = new MemoryStream(4096); using (var writer = new StreamWriter(mem)) { copyrights.WriteDebianParagraphs(writer); } Assert.AreEqual(_writeTestData, Encoding.UTF8.GetString(mem.ToArray())); }
public void CreateCopyrightFileWorks() { var copyrights = SIL.ExtractCopyright.CopyrightFile.CreateNewCopyrightFile("Program", "*****@*****.**", "https://github.com/SteveWhomever/Program"); var ackDict = SIL.Acknowledgements.AcknowledgementsProvider.CollectAcknowledgements(); Assert.IsNotNull(ackDict); Assert.IsNotNull(ackDict.Keys); foreach (var key in ackDict.Keys) { copyrights.AddOrUpdateParagraphFromAcknowledgement(ackDict[key], ""); } // The Mono.Posix acknowledgement is intentionally ignored, so subtract it from acknowledgment count Assert.LessOrEqual(ackDict.Keys.Count - 1 + 3, copyrights.Paragraphs.Count, "We should have the two standard paragraphs, one paragraph per acknowledgement, and at least one license paragraph"); // Collect the license paragraphs, assert that the MIT license has a paragraph, and test its content. var licenseParas = new List <SIL.ExtractCopyright.DebianParagraph>(); SIL.ExtractCopyright.DebianParagraph mitLicensePara = null; foreach (var p in copyrights.Paragraphs) { if (p.Fields.Count == 1 && p.Fields[0].Tag == "License") { licenseParas.Add(p); if (p.Fields[0].Value == "MIT") { mitLicensePara = p; } } } Assert.LessOrEqual(1, licenseParas.Count); Assert.IsNotNull(mitLicensePara); Assert.AreEqual(SIL.ExtractCopyright.CopyrightFile.StandardMITLicense.Length, mitLicensePara.Fields[0].FullDescription.Count); for (int i = 0; i < SIL.ExtractCopyright.CopyrightFile.StandardMITLicense.Length; ++i) { Assert.AreEqual(SIL.ExtractCopyright.CopyrightFile.StandardMITLicense[i], mitLicensePara.Fields[0].FullDescription[i]); } }