public void Save() { IXmlSerializer serializer = new DefaultXmlSerializer(); serializer.Serialize(this, CONFIGPATH); Nofity(); }
public void Should_Save_Serializer_If_Type_Not_Allready_In_Cache() { /* Setup */ var obj = new SerializerTestClass { StringProp = Guid.NewGuid().ToString() }; _cachedSerializers .Setup(c => c.Add( It.Is <Type>(type => type == typeof(SerializerTestClass)), It.IsAny <XmlSerializer>())) .Verifiable(); /* Test */ _serializer.Serialize(obj); /* Assert */ _cachedSerializers.VerifyAll(); }
public void DefaultXmlSerializer_Test() { var o1 = new TestSerializeClass() { Id = 1, Name = "zhang", Age = 19 }; IXmlSerializer xmlSerializer = new DefaultXmlSerializer(); var xml1 = xmlSerializer.Serialize(o1); var o2 = xmlSerializer.Deserialize <TestSerializeClass>(xml1); Assert.Equal(o1.Id, o2.Id); Assert.Equal(o1.Name, o2.Name); Assert.Equal(o1.Age, o2.Age); var o3 = (TestSerializeClass)xmlSerializer.Deserialize(xml1, typeof(TestSerializeClass)); Assert.Equal(o1.Id, o3.Id); Assert.Equal(o1.Name, o3.Name); Assert.Equal(o1.Age, o3.Age); }
public HttpResponseMessage GetData(string prefered = "") { var todo = new Todo { Description = "Respond with a specific content type", IsCompleted = true }; var content = string.Empty; var contentType = string.Empty; if (string.Equals(prefered, "json", StringComparison.InvariantCultureIgnoreCase)) { content = _jsonSerializer.Serialize(todo); contentType = ContentTypes.ApplicationJson; } if (string.Equals(prefered, "xml", StringComparison.InvariantCultureIgnoreCase)) { content = _xmlSerializer.Serialize(todo); contentType = ContentTypes.ApplicationXml; } if (string.IsNullOrWhiteSpace(content)) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Expect a 'prefered' query parameter with value 'json' or 'xml' in request.")); } var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(content, Encoding.UTF8, contentType) }; return(response); }