public void ResXFile2ResourceSetTest() { var actual = new ResourceSet(ResourceSet.NeutralCulture); ResXResourceBundleAdapter_Accessor.Resx2ResourceSet(actual, "ResXResourceBundleAdapterTest.Sample.resx", null); Assert.AreEqual(15, actual.Values.Count); Assert.IsTrue(actual.ContainsKey("Ampersands")); Assert.IsTrue(actual.ContainsKey("MaxLengthString")); Assert.IsTrue(actual.ContainsKey("ReadOnlyString")); Assert.IsTrue(actual.ContainsKey("Set1_Placeholder1")); Assert.IsTrue(actual.ContainsKey("Set1_Placeholder2")); Assert.IsTrue(actual.ContainsKey("Set2")); Assert.IsTrue(actual.ContainsKey("Set2_SubString1")); Assert.IsTrue(actual.ContainsKey("Set2_SubString2")); Assert.IsTrue(actual.ContainsKey("String2Multiline")); Assert.IsTrue(actual.ContainsKey(">>FrameworkLocked")); Assert.IsTrue(actual.ContainsKey("Exclude1")); Assert.IsTrue(actual.ContainsKey("StringWithExclusions")); Assert.IsTrue(actual.ContainsKey("ItemWithoutValue")); Assert.AreEqual(4, actual.CountLocked()); Assert.AreEqual(13, actual.CountStringItems(false)); Assert.AreEqual(14, actual.CountStringItems(true)); Assert.AreEqual(52, actual.CountWords()); Assert.IsInstanceOfType(actual["MaxLengthString"], typeof(ResourceStringItem)); var item = (ResourceStringItem)actual["MaxLengthString"]; Assert.AreEqual(10, item.MaxLength); Assert.IsTrue(actual["ReadOnlyString"].Locked); Assert.AreEqual(LockedReason.DeveloperLock, actual["ReadOnlyString"].LockedReason); Assert.IsTrue(actual[">>FrameworkLocked"].Locked); Assert.AreEqual(LockedReason.FrameworkLock, actual[">>FrameworkLocked"].LockedReason); Assert.IsTrue(actual["Exclude1"].Locked); Assert.AreEqual(LockedReason.ResexMetadata, actual["Exclude1"].LockedReason); // exclusions var exclusions = actual.Exclusions; Assert.AreEqual(3, exclusions.Count); Assert.AreEqual(@"\{.*}", exclusions[1].Pattern); Assert.AreEqual(@"{Text}", exclusions[1].Sample); Assert.AreEqual(@"Windows", exclusions[2].Pattern); }
public void ResourceSet2XmlTest() { // create a sample resource set var resourceSet = new ResourceSet("el-GR") { { "key1", new ResourceItem { Name = "key1", Value = "value1" } }, { "key2", new ResourceItem { Name = "key2", Value = "value2" } }, { "key3", new ResourceItem { Name = "key3", Value = "value3" } }, { "key4", new ResourceItem { Name = "key4", Value = "value4" } }, { "key5", new ResourceItem { Name = "key5", Value = "value5" } } }; // do the actual job (convertion from resource set to xml memory stream) var stream = new MemoryStream(); ResXResourceBundleAdapter_Accessor.ResourceSet2Resx(resourceSet, stream, "ResxConvertFrom.xslt"); stream.Position = 0; // move position of stream to beginning to be ready for reading later // write to temporary file for debugging Console.WriteLine(Encoding.Default.GetString(stream.ToArray())); // convert the xml memory stream into xml document to help assertion of the result var xmlDoc = new XmlDocument(); xmlDoc.Load(stream); // assert the result var rootNode = xmlDoc.SelectSingleNode("//VIPTunnel/strings"); Assert.IsNotNull(rootNode); Assert.AreEqual(5, rootNode.ChildNodes.Count); Assert.IsNotNull(rootNode.SelectSingleNode("key1")); Assert.IsNotNull(rootNode.SelectSingleNode("key1").Attributes.GetNamedItem("text")); Assert.AreEqual("value1", rootNode.SelectSingleNode("key1").Attributes.GetNamedItem("text").Value); }