public void AspectPropertyValue_DefaultConstructor() { AspectPropertyValue <int> value = new AspectPropertyValue <int>(); Assert.IsFalse(value.HasValue); var result = value.Value; }
public void SetHeadersElement(bool valueIsAPV) { var valueStr = "UA-Platform"; object value = valueStr; if (valueIsAPV) { value = new AspectPropertyValue <string>(valueStr); } var propertyNameValues = new Dictionary <string, object>() { { "SetHeaderBrowserAccept-CH", value } }; CreatePipeline(propertyNameValues); var data = _pipeline.CreateFlowData(); data.Process(); // Verify the output var typedOutput = GetFromFlowData(data); Assert.AreEqual(1, typedOutput.ResponseHeaderDictionary.Count); Assert.IsTrue(typedOutput.ResponseHeaderDictionary.ContainsKey("Accept-CH")); Assert.AreEqual("UA-Platform", typedOutput.ResponseHeaderDictionary["Accept-CH"]); }
public void AspectPropertyValue_ValueConstructor() { AspectPropertyValue <int> value = new AspectPropertyValue <int>(1); Assert.AreEqual(1, value.Value); Assert.IsTrue(value.HasValue); }
public void AspectPropertyValue_DefaultConstructor_SetValue() { AspectPropertyValue <int> value = new AspectPropertyValue <int>(); value.Value = 1; Assert.AreEqual(1, value.Value); Assert.IsTrue(value.HasValue); }
public void AspectPropertyValueConverter_WriteInt_NoValue() { AspectPropertyValue <int> value = new AspectPropertyValue <int>(); var result = JsonConvert.SerializeObject(value, _converter); Assert.AreEqual($"null", result); }
public void AspectPropertyValueConverter_WriteString() { AspectPropertyValue <string> value = new AspectPropertyValue <string>("testing"); var result = JsonConvert.SerializeObject(value, _converter); string expected = @"""testing"""; Assert.AreEqual(expected, result); }
public void AspectPropertyValue_CustomErrorMessage() { AspectPropertyValue <int> value = new AspectPropertyValue <int>(); value.NoValueMessage = "CUSTOM MESSAGE"; Assert.IsFalse(value.HasValue); try { var result = value.Value; Assert.Fail("Expected NoValueException to be thrown"); } catch (NoValueException ex) { Assert.AreEqual("CUSTOM MESSAGE", ex.Message); } }
public void AspectPropertyValueConverter_WriteObjectInDictionary() { AspectPropertyValue <string> value1 = new AspectPropertyValue <string>("testing"); AspectPropertyValue <int> value2 = new AspectPropertyValue <int>(3); AspectPropertyValue <string> value3 = new AspectPropertyValue <string>(); Dictionary <string, object> data = new Dictionary <string, object>() { { "v1", value1 }, { "v2", value2 }, { "v3", value3 } }; var result = JsonConvert.SerializeObject(data, _converter); string expected = @"{""v1"":""testing"",""v2"":3,""v3"":null}"; Assert.AreEqual(expected, result); }
protected override IAspectPropertyValue <JavaScript> GetValueAsJavaScript(string propertyName) { var result = new AspectPropertyValue <JavaScript>(); var results = GetSingleResults(propertyName); if (results != null) { using (var value = results.getValueAsString(propertyName)) { if (value.hasValue()) { result.Value = new JavaScript(value.getValue()); } else { result.NoValueMessage = value.getNoValueMessage(); } } } return(result); }
public void SetHeadersElement_APV_InvalidPropertyValues(bool hasValue, string sourcePropertyValue = null) { var value = new AspectPropertyValue <string>(); if (hasValue) { value.Value = sourcePropertyValue; } var propertyNameValues = new Dictionary <string, object>() { { "SetHeaderBrowserAccept-CH", value } }; CreatePipeline(propertyNameValues); var data = _pipeline.CreateFlowData(); data.Process(); // Verify the output var typedOutput = GetFromFlowData(data); Assert.AreEqual(0, typedOutput.ResponseHeaderDictionary.Count); }
public override IAspectPropertyValue <IReadOnlyList <string> > GetValues(string propertyName) { var result = new AspectPropertyValue <IReadOnlyList <string> >(); var results = GetSingleResults(propertyName); if (results != null) { using (var value = results.getValues(propertyName)) { if (value.hasValue()) { using (var vector = value.getValue()) { result.Value = vector.ToList(); } } else { result.NoValueMessage = value.getNoValueMessage(); } } } return(result); }
public void JsonBuilder_Serialization_Text(string valueOfProperty, TypeToBeTested typeToBeTested) { var jsonBuilder = new TestJsonBuilderElement(_loggerFactory); // valueInDict holds the object that will be added // to the dictionary to be serialized. object valueInDict = null; // ExpectedValue holds the value that we expect // the property to have in the generated json // including any surrounding tokens such as quotes, // square brackets, etc. string expectedValue = (valueOfProperty ?? "null").Replace(@"\", @"\\"); expectedValue = expectedValue.Replace(@"""", @"\"""); expectedValue = expectedValue.Replace(@" ", @"\ "); expectedValue = expectedValue.Replace(@" ", @"\r\n"); // Replacing as there is no carriage returnon Linux format. expectedValue = expectedValue.Replace(@"\r", @""); expectedValue = valueOfProperty == null ? expectedValue : $"\"{expectedValue}\""; // Create the object to be serialized switch (typeToBeTested) { case TypeToBeTested.String: valueInDict = valueOfProperty; break; case TypeToBeTested.JavaScript: valueInDict = new JavaScript(valueOfProperty); break; case TypeToBeTested.List: valueInDict = new List <string>() { valueOfProperty }; expectedValue = $@"[ {expectedValue} ]"; break; case TypeToBeTested.APV_String: valueInDict = new AspectPropertyValue <string>(valueOfProperty); break; case TypeToBeTested.APV_JavaScript: valueInDict = new AspectPropertyValue <JavaScript>(new JavaScript(valueOfProperty)); break; case TypeToBeTested.APV_List: valueInDict = new AspectPropertyValue <IReadOnlyList <string> >(new List <string>() { valueOfProperty }); expectedValue = $@"[ {expectedValue} ]"; break; default: break; } // Create the dictionary to be serialized var data = new Dictionary <string, object>() { { "element", new Dictionary <string, object>() { { "property", valueInDict }, } } }; var result = jsonBuilder.Serialize(data); Assert.AreEqual($@"{{ ""element"": {{ ""property"": {expectedValue} }} }}", result.Replace(@"\r", @"")); }