public void GetBackMemoryYummyYummy() { Workshare.Policy.Engine.ContentItem ci = new Workshare.Policy.Engine.ContentItem(); ci.DisplayName = "foobar"; ci.Properties["hello"] = "world"; ci.Properties["cityofisabel"] = "4"; ci.Properties["light and shadow"] = "5"; ci.PolicySetCollection = new System.Collections.ObjectModel.Collection<Workshare.Policy.Engine.Response.IPolicySetResponse>(); ci.File = new Workshare.Policy.Engine.File(new MemoryStream(someRandomTestStringAsBytes), "EnvironmentVarsInUnicode"); ContentItem ciOut = ContentItemAdaptor.GetContentItem(ci, true); Assert.IsNotNull(ciOut.Content, "Expecting bytes, yes!! bytes"); CustomProperty[] cps = Array.FindAll<CustomProperty>(ciOut.Properties, delegate(CustomProperty toTest) { return toTest.Name == ContentItemAdaptor.ContentDataSourceKey; }); Assert.AreEqual(0, cps.Length, "Expecting no filename property"); Assert.AreEqual(someRandomTestStringAsBytes.Length, ciOut.Content.Length, "content item bytes are not equal to template"); for (int i = 0; i < someRandomTestStringAsBytes.Length; i++) { Assert.AreEqual(someRandomTestStringAsBytes[i], ciOut.Content[i], "Byte at pos {0} doesnt compute", i); } }
public void GetBackAFile() { string someRandomFile = Path.GetTempFileName(); try { Workshare.Policy.Engine.ContentItem ci = new Workshare.Policy.Engine.ContentItem(); File.WriteAllBytes(someRandomFile, someRandomTestStringAsBytes); ci.File = new Workshare.Policy.Engine.File(someRandomFile, "EnvironmentVarsInUnicode"); ci.DisplayName = "foobar"; ci.Properties["hello"] = "world"; ci.Properties["cityofisabel"] = "4"; ci.Properties["light and shadow"] = "5"; ci.Properties[ContentItemAdaptor.ContentDataSourceKey] = someRandomFile; ci.PolicySetCollection = new System.Collections.ObjectModel.Collection<Workshare.Policy.Engine.Response.IPolicySetResponse>(); ContentItem ciOut = ContentItemAdaptor.GetContentItem(ci, true); Assert.IsNull(ciOut.Content, "Expecting bytes to be null"); CustomProperty[] cps = Array.FindAll<CustomProperty>(ciOut.Properties, delegate(CustomProperty toTest) { return toTest.Name == ContentItemAdaptor.ContentDataSourceKey; }); Assert.AreEqual(someRandomFile, cps[0].Value, "Incorrect file returned, expected same file as input"); Assert.AreEqual(1, cps.Length, "Expecting exactly one filename"); Assert.IsTrue(File.Exists(cps[0].Value), "File source doesnt exist"); /// verified the file wasnt touched, though irrelevant byte[] fileContents = File.ReadAllBytes(cps[0].Value); Assert.AreEqual(someRandomTestStringAsBytes.Length, fileContents.Length, "file contents are not equal to template"); for (int i = 0; i < someRandomTestStringAsBytes.Length; i++) { Assert.AreEqual(someRandomTestStringAsBytes[i], fileContents[i], "Byte at pos {0} doesnt compute", i); } } finally { File.Delete(someRandomFile); } }