public void CanSerialize(LogConfiguration configuration) { var serializer = new JsonSerializer(); var json = configuration.ToString(); // ToString returns the JSON representation itself. using (var reader = new StringReader(json)) { using (var jsonReader = new JsonTextReader(reader)) { var deserialized = serializer.Deserialize <LogConfiguration>(jsonReader); Assert.AreEqual(configuration, deserialized); Assert.AreEqual(configuration.Name, deserialized.Name); Assert.AreEqual(configuration.Type, deserialized.Type); foreach (var sub in configuration.Subscriptions) { Assert.IsTrue(deserialized.Subscriptions.Contains(sub)); } foreach (var filter in configuration.Filters) { Assert.IsTrue(deserialized.Filters.Contains(filter)); } Assert.AreEqual(configuration.BufferSizeMB, deserialized.BufferSizeMB); Assert.AreEqual(configuration.Directory, deserialized.Directory); Assert.AreEqual(configuration.FilenameTemplate, deserialized.FilenameTemplate); Assert.AreEqual(configuration.TimestampLocal, deserialized.TimestampLocal); Assert.AreEqual(configuration.RotationInterval, deserialized.RotationInterval); Assert.AreEqual(configuration.Hostname, deserialized.Hostname); Assert.AreEqual(configuration.Port, deserialized.Port); } } }