|
| 1 | +using System.Collections.Generic; |
| 2 | +using SabreTools.IO.Extensions; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace SabreTools.IO.Test.Extensions |
| 6 | +{ |
| 7 | + public class DictionaryExtensionsTests |
| 8 | + { |
| 9 | + #region MergeWith |
| 10 | + |
| 11 | + [Fact] |
| 12 | + public void MergeWith_EmptySource_EmptyOther_Empty() |
| 13 | + { |
| 14 | + Dictionary<string, List<string>> source = []; |
| 15 | + Dictionary<string, List<string>> other = []; |
| 16 | + |
| 17 | + source.MergeWith(other); |
| 18 | + Assert.Empty(source); |
| 19 | + } |
| 20 | + |
| 21 | + [Fact] |
| 22 | + public void MergeWith_EmptySource_EmptyKeyOther_Empty() |
| 23 | + { |
| 24 | + Dictionary<string, List<string>> source = []; |
| 25 | + Dictionary<string, List<string>> other = []; |
| 26 | + other.Add("key", []); |
| 27 | + |
| 28 | + source.MergeWith(other); |
| 29 | + Assert.Empty(source); |
| 30 | + } |
| 31 | + |
| 32 | + [Fact] |
| 33 | + public void MergeWith_EmptySource_FilledOther_Filled() |
| 34 | + { |
| 35 | + Dictionary<string, List<string>> source = []; |
| 36 | + Dictionary<string, List<string>> other = []; |
| 37 | + other.Add("key", ["value"]); |
| 38 | + |
| 39 | + source.MergeWith(other); |
| 40 | + string key = Assert.Single(source.Keys); |
| 41 | + Assert.Equal("key", key); |
| 42 | + List<string> actual = source[key]; |
| 43 | + string value = Assert.Single(actual); |
| 44 | + Assert.Equal("value", value); |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public void MergeWith_FilledSource_EmptyOther_Filled() |
| 49 | + { |
| 50 | + Dictionary<string, List<string>> source = []; |
| 51 | + source.Add("key", ["value"]); |
| 52 | + Dictionary<string, List<string>> other = []; |
| 53 | + |
| 54 | + source.MergeWith(other); |
| 55 | + string key = Assert.Single(source.Keys); |
| 56 | + Assert.Equal("key", key); |
| 57 | + List<string> actual = source[key]; |
| 58 | + string value = Assert.Single(actual); |
| 59 | + Assert.Equal("value", value); |
| 60 | + } |
| 61 | + |
| 62 | + [Fact] |
| 63 | + public void MergeWith_FilledSource_FilledOther_Filled() |
| 64 | + { |
| 65 | + Dictionary<string, List<string>> source = []; |
| 66 | + source.Add("key1", ["value1"]); |
| 67 | + Dictionary<string, List<string>> other = []; |
| 68 | + other.Add("key2", ["value2"]); |
| 69 | + |
| 70 | + source.MergeWith(other); |
| 71 | + Assert.Equal(2, source.Keys.Count); |
| 72 | + |
| 73 | + Assert.Contains("key1", source.Keys); |
| 74 | + List<string> actualKey1 = source["key1"]; |
| 75 | + string value1 = Assert.Single(actualKey1); |
| 76 | + Assert.Equal("value1", value1); |
| 77 | + |
| 78 | + Assert.Contains("key2", source.Keys); |
| 79 | + List<string> actualKey2 = source["key2"]; |
| 80 | + string value2 = Assert.Single(actualKey2); |
| 81 | + Assert.Equal("value2", value2); |
| 82 | + } |
| 83 | + |
| 84 | + #endregion |
| 85 | + } |
| 86 | +} |
0 commit comments