public void BatchReaderHeadersTest() { IEnumerable <KeyValuePair <string, string> > invalidInitialHeaders = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("ABC", "ABC"), new KeyValuePair <string, string>("ABC", "ABC"), }; Dictionary <string, string> validInitialHeaders = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "ABC", "ABC" }, { "DEF", "DEF" }, { "GHI", "GHI" }, }; IEnumerable <BatchHeadersTestCase> testCases = new BatchHeadersTestCase[] { // Duplicate case-sensitive keys will fail new BatchHeadersTestCase(this.Settings) { InitialHeaders = invalidInitialHeaders, ExpectedException = new ExpectedException(typeof(ArgumentException)) }, // Valid items should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, ExpectedHeaders = validInitialHeaders }, // Replacing an item and adding a new one via the indexer should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers["ABC"] = "NewAbc"; headers["XYZ"] = "XYZ"; }, ExpectedHeaders = new Dictionary <string, string>(validInitialHeaders).Set("ABC", "NewAbc").With("XYZ", "XYZ") }, // Adding new items via Add should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Add("ABc", "ABc"); }, ExpectedException = new ExpectedException(typeof(ArgumentException)) }, // Adding the same item should fail new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Add("ABC", "ABC"); }, ExpectedException = new ExpectedException(typeof(ArgumentException)) }, // Removing an item (case-sensitive match) should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Remove("ABC"); }, ExpectedHeaders = new Dictionary <string, string>(validInitialHeaders, StringComparer.OrdinalIgnoreCase).Without("ABC") }, // Removing an item (case-insensitive match) should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Remove("ghi"); }, ExpectedHeaders = new Dictionary <string, string>(validInitialHeaders, StringComparer.OrdinalIgnoreCase).Without("GHI") }, // Removing a non-existing item should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Remove("AAA"); }, ExpectedHeaders = validInitialHeaders }, // ContainsKeyOrdinal should work for existing key new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { this.Settings.Assert.IsTrue(headers.ContainsKeyOrdinal("abc"), "Expected to find 'abc' in the headers."); }, ExpectedHeaders = validInitialHeaders }, // TryGetValue should work for existing key (case-sensitive match) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v; this.Assert.IsTrue(headers.TryGetValue("abc", out v), "TryGetValue should work for 'abc'."); this.Assert.AreEqual("ABC", v, "Header values don't match."); }, ExpectedHeaders = validInitialHeaders }, // TryGetValue should work for existing key (single case-insensitive match) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v; this.Assert.IsTrue(headers.TryGetValue("ghi", out v), "TryGetValue should work for 'ghi'."); this.Assert.AreEqual("GHI", v, "Header values don't match."); }, ExpectedHeaders = validInitialHeaders }, // TryGetValue should work for non-existing key new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v; this.Assert.IsFalse(headers.TryGetValue("AAA", out v), "TryGetValue should work for 'AAA'."); }, ExpectedHeaders = validInitialHeaders }, // Indexer should work for existing key (case-sensitive match) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v = headers["abc"]; this.Assert.AreEqual("ABC", v, "Header values don't match."); }, ExpectedHeaders = validInitialHeaders }, // Indexer should work for existing key (single case-insensitive match) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v = headers["ghi"]; this.Assert.AreEqual("GHI", v, "Header values don't match."); }, ExpectedHeaders = validInitialHeaders }, // Indexer should fail for non-existing key new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v = headers["AAA"]; }, ExpectedException = new ExpectedException(typeof(KeyNotFoundException)) }, }; this.CombinatorialEngineProvider.RunCombinations(testCases, testCase => testCase.Run()); }
public void BatchReaderHeadersTest() { IEnumerable<KeyValuePair<string, string>> invalidInitialHeaders = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("ABC", "ABC"), new KeyValuePair<string, string>("ABC", "ABC"), }; Dictionary<string, string> validInitialHeaders = new Dictionary<string, string> { { "ABC", "ABC"}, { "Abc", "Abc"}, { "abc", "abc"}, { "DEF", "DEF"}, { "def", "def"}, { "GHI", "GHI"}, }; IEnumerable<BatchHeadersTestCase> testCases = new BatchHeadersTestCase[] { // Duplicate case-sensitive keys will fail new BatchHeadersTestCase(this.Settings) { InitialHeaders = invalidInitialHeaders, ExpectedException = new ExpectedException(typeof(ArgumentException)) }, // Valid items should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, ExpectedHeaders = validInitialHeaders }, // Replacing an item and adding a new one via the indexer should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers["ABC"] = "NewAbc"; headers["XYZ"] = "XYZ"; }, ExpectedHeaders = new Dictionary<string, string>(validInitialHeaders).Set("ABC", "NewAbc").With("XYZ", "XYZ") }, // Adding new items via Add should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Add("ABc", "ABc"); }, ExpectedHeaders = new Dictionary<string, string>(validInitialHeaders).With("ABc", "ABc") }, // Adding the same item should fail new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Add("ABC", "ABC"); }, ExpectedException = new ExpectedException(typeof(ArgumentException)) }, // Removing an item (case-sensitive match) should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Remove("ABC"); }, ExpectedHeaders = new Dictionary<string, string>(validInitialHeaders).Without("ABC") }, // Removing an item (case-insensitive match) should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Remove("ghi"); }, ExpectedHeaders = new Dictionary<string, string>(validInitialHeaders).Without("GHI") }, // Removing an item (multiple case-insensitive matches) should fail new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Remove("ABc"); }, ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchOperationHeaderDictionary_DuplicateCaseInsensitiveKeys", "ABc") }, // Removing a non-existing item should work new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { headers.Remove("AAA"); }, ExpectedHeaders = validInitialHeaders }, // ContainsKeyOrdinal should work for existing key new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { this.Settings.Assert.IsTrue(headers.ContainsKeyOrdinal("abc"), "Expected to find 'abc' in the headers."); }, ExpectedHeaders = validInitialHeaders }, // ContainsKeyOrdinal should fail for non-existing key new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { this.Settings.Assert.IsFalse(headers.ContainsKeyOrdinal("ABc"), "Expected to not find 'ABc' in the headers."); }, ExpectedHeaders = validInitialHeaders }, // TryGetValue should work for existing key (case-sensitive match) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v; this.Assert.IsTrue(headers.TryGetValue("abc", out v), "TryGetValue should work for 'abc'."); this.Assert.AreEqual("abc", v, "Header values don't match."); }, ExpectedHeaders = validInitialHeaders }, // TryGetValue should work for existing key (single case-insensitive match) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v; this.Assert.IsTrue(headers.TryGetValue("ghi", out v), "TryGetValue should work for 'ghi'."); this.Assert.AreEqual("GHI", v, "Header values don't match."); }, ExpectedHeaders = validInitialHeaders }, // TryGetValue should fail for existing key (multiple case-insensitive matches) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v; headers.TryGetValue("ABc", out v); }, ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchOperationHeaderDictionary_DuplicateCaseInsensitiveKeys", "ABc") }, new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v; headers.TryGetValue("DEf", out v); }, ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchOperationHeaderDictionary_DuplicateCaseInsensitiveKeys", "DEf") }, // TryGetValue should work for non-existing key new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v; this.Assert.IsFalse(headers.TryGetValue("AAA", out v), "TryGetValue should work for 'AAA'."); }, ExpectedHeaders = validInitialHeaders }, // Indexer should work for existing key (case-sensitive match) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v = headers["abc"]; this.Assert.AreEqual("abc", v, "Header values don't match."); }, ExpectedHeaders = validInitialHeaders }, // Indexer should work for existing key (single case-insensitive match) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v = headers["ghi"]; this.Assert.AreEqual("GHI", v, "Header values don't match."); }, ExpectedHeaders = validInitialHeaders }, // Indexer should fail for existing key (multiple case-insensitive matches) new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v = headers["ABc"]; }, ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchOperationHeaderDictionary_DuplicateCaseInsensitiveKeys", "ABc") }, new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v = headers["DEf"]; }, ExpectedException = ODataExpectedExceptions.ODataException("ODataBatchOperationHeaderDictionary_DuplicateCaseInsensitiveKeys", "DEf") }, // Indexer should fail for non-existing key new BatchHeadersTestCase(this.Settings) { InitialHeaders = validInitialHeaders, CustomizationFunc = headers => { string v = headers["AAA"]; }, ExpectedException = new ExpectedException(typeof(KeyNotFoundException)) }, }; this.CombinatorialEngineProvider.RunCombinations(testCases, testCase => testCase.Run()); }