Пример #1
0
        public void TypicalEmbedInMyXmlDocument()
        {
            var system = new OlacSystem();
            var work   = new Work();

            work.Licenses.Add(License.CreativeCommons_Attribution_ShareAlike);
            work.Contributions.Add(new Contribution("Charlie Brown", system.GetRoleByCodeOrThrow("author")));
            work.Contributions.Add(new Contribution("Linus", system.GetRoleByCodeOrThrow("editor")));

            string metaData = system.GetXmlForWork(work);

            //Embed that data in our own file
            using (var f = new TempFile(@"<doc>
				<metadata>"                 + metaData + @"</metadata>
				<ourDocumentContents>blah blah<ourDocumentContents/></doc>"                ))
            {
                //Then when it comes time to read the file, we can extract out the work again
                var dom = new XmlDocument();
                dom.Load(f.Path);

                var node  = dom.SelectSingleNode("//metadata");
                var work2 = new Work();
                system.LoadWorkFromXml(work2, node.InnerXml);

                Assert.AreEqual(2, work2.Contributions.Count());
            }
        }
        public void SetContributors_TwoContributors_IncludedInMetsData()
        {
            var        contributors = new ContributionCollection();
            OlacSystem olacSystem   = new OlacSystem();

            contributors.Add(new Contribution("Erkel", olacSystem.GetRoleByCodeOrThrow("author")));
            contributors.Add(new Contribution("Sungfu", olacSystem.GetRoleByCodeOrThrow("recorder")));
            _helper.SetContributors(contributors);
            var data = _helper.GetMetadata();

            Assert.AreEqual("{\"dc.title\":\"Test Title\",\"" +
                            RampArchivingDlgViewModel.kContributor + "\":{\"0\":{\" \":\"Erkel\",\"role\":\"author\"},\"1\":{\" \":\"Sungfu\",\"role\":\"recorder\"}}}",
                            data);
        }
        public void SetContributors_SetTwice_ThrowsInvalidOperationException()
        {
            var        contributors = new ContributionCollection();
            OlacSystem olacSystem   = new OlacSystem();
            Role       role         = olacSystem.GetRoleByCodeOrThrow("author");
            var        contrib      = new Contribution("Erkel", role);

            contributors.Add(contrib);
            _helper.SetContributors(contributors);
            Assert.Throws <InvalidOperationException>(() => _helper.SetContributors(contributors));
        }
Пример #4
0
 public void GetRoleByCodeOrThrow_TryInvalidCode_ThrowsException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _system.GetRoleByCodeOrThrow("junk"));
 }