public void WebService_ToXml_WhenRequestValuesHaveEnter_ShouldBeRespectedWhenReHydrated() { //------------Setup for test-------------------------- var expected = new WebService { Source = new WebSource { ResourceID = Guid.NewGuid(), ResourceName = "TestWebSource", }, RequestUrl = "pqr", RequestMethod = WebRequestMethod.Get, RequestHeaders = "Content-Type: text/xml\nBearer: Trusted", RequestBody = "abc\nhas an enter\nin it", RequestResponse = "xyz", JsonPath = "$.somepath" }; //------------Execute Test--------------------------- var xml = expected.ToXml(); var actual = new WebService(xml); //------------Assert Results------------------------- StringAssert.Contains(actual.RequestHeaders, "\n"); StringAssert.Contains(actual.RequestBody, "\n"); }
public void WebServiceToXmlExpectedSerializesProperties() { var expected = new WebService { Source = new WebSource { ResourceID = Guid.NewGuid(), ResourceName = "TestWebSource", }, RequestUrl = "pqr", RequestMethod = WebRequestMethod.Get, RequestHeaders = "Content-Type: text/xml", RequestBody = "abc", RequestResponse = "xyz", JsonPath = "$.somepath" }; #region setup method parameters expected.Method.Parameters.AddRange( new[] { new MethodParameter { Name = "Param1", DefaultValue = "123" }, new MethodParameter { Name = "Param2", DefaultValue = "456" } }); #endregion #region setup rs1 var rs1 = new Recordset { Name = "Recordset1()" }; rs1.Fields.AddRange(new[] { new RecordsetField { Name = "Field1", Alias = "Alias1", RecordsetAlias = "RecAlias1()" }, new RecordsetField { Name = "Field2", Alias = "Alias2", RecordsetAlias = "RecAlias1()" } }); expected.Recordsets.Add(rs1); #endregion #region setup rs2 var rs2 = new Recordset { Name = "Recordset2()" }; rs2.Fields.AddRange(new[] { new RecordsetField { Name = "Field3", Alias = "Alias3" }, new RecordsetField { Name = "Field4", Alias = "Alias4" } }); expected.Recordsets.Add(rs2); #endregion var xml = expected.ToXml(); var actual = new WebService(xml); Assert.AreEqual(expected.Source.ResourceType, actual.Source.ResourceType); Assert.AreEqual(expected.Source.ResourceID, actual.Source.ResourceID); Assert.AreEqual(expected.Source.ResourceName, actual.Source.ResourceName); Assert.AreEqual(expected.ResourceType, actual.ResourceType); Assert.AreEqual(expected.RequestUrl, actual.RequestUrl); Assert.AreEqual(expected.RequestMethod, actual.RequestMethod); Assert.AreEqual(expected.RequestHeaders, actual.RequestHeaders); Assert.AreEqual(expected.RequestBody, actual.RequestBody); Assert.AreEqual(expected.JsonPath, actual.JsonPath); Assert.IsNull(actual.RequestResponse); foreach(var expectedParameter in expected.Method.Parameters) { MethodParameter parameter = expectedParameter; var actualParameter = actual.Method.Parameters.First(p => p.Name == parameter.Name); Assert.AreEqual(expectedParameter.DefaultValue, actualParameter.DefaultValue); } foreach(var expectedRecordset in expected.Recordsets) { // expect actual to have removed recordset notation ()... Recordset recordset = expectedRecordset; var actualRecordset = actual.Recordsets.First(rs => rs.Name == recordset.Name.Replace("()", "")); foreach(var expectedField in expectedRecordset.Fields) { RecordsetField field = expectedField; var actualField = actualRecordset.Fields.First(f => f.Name == field.Name); Assert.AreEqual(expectedField.Alias, actualField.Alias); // expect actual to have removed recordset notation ()... var expectedRecordsetAlias = string.IsNullOrEmpty(expectedField.RecordsetAlias) ? string.Empty : expectedField.RecordsetAlias.Replace("()", ""); Assert.AreEqual(expectedRecordsetAlias, actualField.RecordsetAlias); } } }