public void SerializeOphalenInschrijvingRequest_Rsin() { // Arrange var reference = "ACC_I_002"; var kvkNumber = "8541214521"; var expectedMessage = $@"<ophalenInschrijvingRequest xmlns=""http://schemas.kvk.nl/schemas/hrip/dataservice/2015/02""><klantreferentie>{reference}</klantreferentie><rsin>{kvkNumber}</rsin></ophalenInschrijvingRequest>"; var parser = new HRDataserviceMessageParser(); var request = new ophalenInschrijvingRequest( new InschrijvingRequestType() { Item = kvkNumber, klantreferentie = reference, ItemElementName = ItemChoiceType.rsin } ); // Act var msg = parser.SerializeOphalenInschrijvingRequest(request); //Assert msg = msg .Replace(Environment.NewLine, string.Empty) .Replace(" ", string.Empty) .Replace(" ", string.Empty) .Replace(" ", string.Empty) .Replace(" <", "<"); Assert.AreEqual(expectedMessage, msg); }
public string SerializeOphalenInschrijvingRequest(ophalenInschrijvingRequest request) { if (request == null) { return(string.Empty); } // parse the request to this xml // Althoug it would be better to use datacontractserializer, this won't fly one way or another... var elementName = request.ophalenInschrijvingRequest1.ItemElementName; return($@"<ophalenInschrijvingRequest xmlns=""http://schemas.kvk.nl/schemas/hrip/dataservice/2015/02""> <klantreferentie>{request.ophalenInschrijvingRequest1.klantreferentie}</klantreferentie> <{elementName}>{request.ophalenInschrijvingRequest1.Item}</{elementName}> </ophalenInschrijvingRequest>"); //var ophalenInschrijvingRequest1 = request.ophalenInschrijvingRequest1; //var ophalenInschrijvingRequest1Type = ophalenInschrijvingRequest1.GetType(); //var requestType = request.GetType().Name; //var ns = new XmlSerializerNamespaces(); //ns.Add("", ""); //var serializer = new XmlSerializer(ophalenInschrijvingRequest1Type); //var sb = new StringBuilder(); //var settings = new XmlWriterSettings //{ // Indent = false, // OmitXmlDeclaration = true, // WriteEndDocumentOnClose = true, // NamespaceHandling = NamespaceHandling.OmitDuplicates, //}; //using (var w = XmlWriter.Create(sb, settings)) //{ // serializer.Serialize(w, ophalenInschrijvingRequest1, ns); //} //var tempResult = sb.ToString() // .Replace(@" xmlns=""http://schemas.kvk.nl/schemas/hrip/dataservice/2015/02""", string.Empty) // .Replace(ophalenInschrijvingRequest1Type.Name, requestType) // .Replace($@"<{requestType}>", $@"<{requestType} xmlns=""http://schemas.kvk.nl/schemas/hrip/dataservice/2015/02"">"); //return tempResult; }