/// <summary> /// Finds keys that are present in both 'a' and 'b' /// </summary> /// <param name="a">The first document</param> /// <param name="b">The second document</param> /// <returns>The keys that are present in both 'a' and 'b'</returns> public static IEnumerable <string> PresentKeys(ResxDocument a, ResxDocument b) { var aKeys = a.Data.Select(data => data.Name); var bKeys = b.Data.Select(data => data.Name); return(aKeys.Intersect(bKeys)); }
public void SetUp() { _test1 = new ResxDocument(TestUtils.LoadTest1()); _test2 = new ResxDocument(TestUtils.LoadTest2()); _test3 = new ResxDocument(TestUtils.LoadTest3()); _test4 = new ResxDocument(TestUtils.LoadTest4()); }
/// <summary> /// Finds keys present in 'a' that are missing in 'b' /// </summary> /// <param name="a">The base document</param> /// <param name="b">The document to check for missing keys</param> /// <returns>The keys present in 'a' that are missing in 'b'</returns> public static IEnumerable <string> MissingKeys(ResxDocument a, ResxDocument b) { var aKeys = a.Data.Select(data => data.Name); var bKeys = b.Data.Select(data => data.Name); return(aKeys.Except(bKeys)); }
public void ResxDocumentToXmlWithChanges() { var test1 = new ResxDocument(TestUtils.LoadTest1()); test1.Data.Add(new ResxData { Name = "Test_key_4", Value = "Test value 4", Space = "preserve" }); Assert.AreEqual(TestUtils.LoadTest2().ToString(), test1.ToXml().ToString()); }
/// <summary> /// Finds keys present in 'a' and 'b' which have differing metadata (type, mimetype, space or comment) /// </summary> /// <param name="a">The first document</param> /// <param name="b">The second document</param> /// <returns>The keys present in 'a' and 'b' which have differing metadata</returns> public static IEnumerable <string> MismatchedMetadata(ResxDocument a, ResxDocument b) { return(PresentKeys(a, b).Where(name => { var aData = a.Data.First(data => data.Name == name); var bData = b.Data.First(data => data.Name == name); return (aData.Type != bData.Type) || (aData.Mimetype != bData.Mimetype) || (aData.Space != bData.Space) || (aData.Comment != bData.Comment); })); }
/// <summary> /// Finds keys present in 'a' and 'b' which have differing metadata (type, mimetype, space or comment) /// </summary> /// <param name="a">The first document</param> /// <param name="b">The second document</param> /// <returns>The keys present in 'a' and 'b' which have differing metadata</returns> public static IEnumerable<string> MismatchedMetadata(ResxDocument a, ResxDocument b) { return PresentKeys(a, b).Where(name => { var aData = a.Data.First(data => data.Name == name); var bData = b.Data.First(data => data.Name == name); return (aData.Type != bData.Type) || (aData.Mimetype != bData.Mimetype) || (aData.Space != bData.Space) || (aData.Comment != bData.Comment); }); }
public void Load() { var test1 = new ResxDocument(TestUtils.LoadTest1()); Assert.AreEqual(3, test1.Data.Count); Assert.AreEqual("Test_key_1", test1.Data[0].Name); Assert.AreEqual(null, test1.Data[0].Type); Assert.AreEqual(null, test1.Data[0].Mimetype); Assert.AreEqual("preserve", test1.Data[0].Space); Assert.AreEqual("Test value 1", test1.Data[0].Value); Assert.AreEqual("A comment", test1.Data[0].Comment); }
/// <summary> /// Copies keys from one document to another (complete Data objects) /// </summary> /// <param name="keys">The names of the keys to copy</param> /// <param name="from">The document to copy from</param> /// <param name="to">The document to copy to</param> public static void CopyKeys(IEnumerable<string> keys, ResxDocument from, ResxDocument to) { from.Data.Where(data => keys.Contains(data.Name)).ToList().ForEach(to.Data.Add); }
/// <summary> /// Sorts keys in alphabetical order /// </summary> /// <param name="d">The document whose keys are to be sorted</param> public static void Alphabetise(ResxDocument d) { d.Data = d.Data.OrderBy(data => data.Name).ToList(); }
/// <summary> /// Adds space="preserve" attributes to data elements which are missing it /// </summary> /// <param name="d">The document to add missing space="preserve" attributes to</param> public static void AddMissingSpacePreserve(ResxDocument d) { d.Data.Where(data => Helpers.MissingSpacePreserve(d).Contains(data.Name)).ToList().ForEach(data => data.Space = "preserve"); }
/// <summary> /// Copies values from one document to another /// </summary> /// <param name="keys">The names of the keys whose values should be copied</param> /// <param name="from">The document to copy from</param> /// <param name="to">The document to copy to</param> public static void CopyValues(IEnumerable <string> keys, ResxDocument from, ResxDocument to) { to.Data.Where(data => keys.Contains(data.Name)).ToList() .ForEach(aData => aData.Value = from.Data.First(bData => bData.Name == aData.Name).Value); }
/// <summary> /// Copies keys from one document to another (complete Data objects) /// </summary> /// <param name="keys">The names of the keys to copy</param> /// <param name="from">The document to copy from</param> /// <param name="to">The document to copy to</param> public static void CopyKeys(IEnumerable <string> keys, ResxDocument from, ResxDocument to) { from.Data.Where(data => keys.Contains(data.Name)).ToList().ForEach(to.Data.Add); }
// @todo Probably only text keys should have space="preserve". If that's the case, this should ignore non-text keys. Also applies to AddMissingSpacePreserve /// <summary> /// Finds keys that are missing the xml:space="preserve" attribute in 'd' /// </summary> /// <param name="d">The document to check for duplicate keys</param> /// <returns>The keys that appear more than once in 'd'</returns> public static IEnumerable <string> MissingSpacePreserve(ResxDocument d) { return(d.Data.Where(data => data.Space != "preserve").Select(data => data.Name)); }
/// <summary> /// Finds keys that appear more than once in 'd' /// </summary> /// <param name="d">The document to check for duplicate keys</param> /// <returns>The keys that appear more than once in 'd'</returns> public static IEnumerable <string> DuplicateKeys(ResxDocument d) { return(d.Data.GroupBy(data => data.Name).Where(group => group.Count() > 1).Select(group => group.Key)); }
/// <summary> /// Finds keys present in 'a' and 'b' which have the same values /// </summary> /// <param name="a">The first document</param> /// <param name="b">The second document</param> /// <returns>The keys present in 'a' and 'b' which have the same values</returns> public static IEnumerable<string> IdenticalValues(ResxDocument a, ResxDocument b) { return PresentKeys(a, b).Where(name => a.Data.First(aData => aData.Name == name).Value == b.Data.First(bData => bData.Name == name).Value); }
/// <summary> /// Finds keys present in 'a' that are missing in 'b' /// </summary> /// <param name="a">The base document</param> /// <param name="b">The document to check for missing keys</param> /// <returns>The keys present in 'a' that are missing in 'b'</returns> public static IEnumerable<string> MissingKeys(ResxDocument a, ResxDocument b) { var aKeys = a.Data.Select(data => data.Name); var bKeys = b.Data.Select(data => data.Name); return aKeys.Except(bKeys); }
// @todo Probably only text keys should have space="preserve". If that's the case, this should ignore non-text keys. Also applies to AddMissingSpacePreserve /// <summary> /// Finds keys that are missing the xml:space="preserve" attribute in 'd' /// </summary> /// <param name="d">The document to check for duplicate keys</param> /// <returns>The keys that appear more than once in 'd'</returns> public static IEnumerable<string> MissingSpacePreserve(ResxDocument d) { return d.Data.Where(data => data.Space != "preserve").Select(data => data.Name); }
/// <summary> /// Finds keys that are present in both 'a' and 'b' /// </summary> /// <param name="a">The first document</param> /// <param name="b">The second document</param> /// <returns>The keys that are present in both 'a' and 'b'</returns> public static IEnumerable<string> PresentKeys(ResxDocument a, ResxDocument b) { var aKeys = a.Data.Select(data => data.Name); var bKeys = b.Data.Select(data => data.Name); return aKeys.Intersect(bKeys); }
public void ResxDocumentToXml() { var test1 = new ResxDocument(TestUtils.LoadTest1()); Assert.AreEqual(TestUtils.LoadTest1().ToString(), test1.ToXml().ToString()); }
/// <summary> /// Finds keys present in 'a' and 'b' which have the same values /// </summary> /// <param name="a">The first document</param> /// <param name="b">The second document</param> /// <returns>The keys present in 'a' and 'b' which have the same values</returns> public static IEnumerable <string> IdenticalValues(ResxDocument a, ResxDocument b) { return(PresentKeys(a, b).Where(name => a.Data.First(aData => aData.Name == name).Value == b.Data.First(bData => bData.Name == name).Value)); }
/// <summary> /// Copies values from one document to another /// </summary> /// <param name="keys">The names of the keys whose values should be copied</param> /// <param name="from">The document to copy from</param> /// <param name="to">The document to copy to</param> public static void CopyValues(IEnumerable<string> keys, ResxDocument from, ResxDocument to) { to.Data.Where(data => keys.Contains(data.Name)).ToList() .ForEach(aData => aData.Value = from.Data.First(bData => bData.Name == aData.Name).Value); }
/// <summary> /// Finds keys that appear more than once in 'd' /// </summary> /// <param name="d">The document to check for duplicate keys</param> /// <returns>The keys that appear more than once in 'd'</returns> public static IEnumerable<string> DuplicateKeys(ResxDocument d) { return d.Data.GroupBy(data => data.Name).Where(group => group.Count() > 1).Select(group => group.Key); }