public void GetCollectionFromEmptyHeader() { WebHeaderCollection headers = new WebHeaderCollection(); Assert.IsNull(headers.GetNameValueCollectionFromHeader("Correlation-Context")); headers["Correlation-Context"] = " "; var correlationContext = headers.GetNameValueCollectionFromHeader("Correlation-Context"); Assert.IsTrue(correlationContext == null || !correlationContext.Any()); }
public void GetCollectionFromInvalidHeader() { WebHeaderCollection headers = new WebHeaderCollection(); // no valid items headers["Correlation-Context"] = "k1, some string,k2=v2=v3"; var correlationContext = headers.GetNameValueCollectionFromHeader("Correlation-Context"); Assert.IsTrue(correlationContext == null || !correlationContext.Any()); // some valid items headers["Correlation-Context"] = "k1=v1, some string"; correlationContext = headers.GetNameValueCollectionFromHeader("Correlation-Context"); Assert.IsNotNull(correlationContext); Assert.AreEqual(1, correlationContext.Count()); Assert.IsTrue(correlationContext.Contains(new KeyValuePair <string, string>("k1", "v1"))); }
public void GetCollectionFromHeaderWithDuplicates() { WebHeaderCollection headers = new WebHeaderCollection(); headers["Correlation-Context"] = "k1=v1, k2=v2, k1 = v3"; var correlationContext = headers.GetNameValueCollectionFromHeader("Correlation-Context").ToArray(); Assert.AreEqual(2, correlationContext.Length); Assert.IsTrue(correlationContext.Contains(new KeyValuePair <string, string>("k1", "v1"))); Assert.IsTrue(correlationContext.Contains(new KeyValuePair <string, string>("k2", "v2"))); }
public void GetCollectionFromHeaderNoDuplicates() { WebHeaderCollection headers = new WebHeaderCollection(); headers["Correlation-Context"] = "k1=v1, k2=v2, k3 = v3 "; var correlationContext = headers.GetNameValueCollectionFromHeader("Correlation-Context"); Assert.IsNotNull(correlationContext); var corrContextDict = correlationContext.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); Assert.AreEqual(3, corrContextDict.Count); Assert.AreEqual("v1", corrContextDict["k1"]); Assert.AreEqual("v2", corrContextDict["k2"]); Assert.AreEqual("v3", corrContextDict["k3"]); }