Given the following class, how are you going to write unit test for it? I read that any test that the IO file does is not a unit test, so is it an integration test that needs to be written? I use xUnit and MOQ for testing, and I am very new to this, so maybe I can MOQ file? Not sure.
public class Serializer { public static T LoadFromXmlFile<T>(string path) where T : class { var serializer = new XmlSerializer(typeof(T)); using (var reader = new StreamReader(path)) { return serializer.Deserialize(reader) as T; } } public static void SaveToXmlFile<T>(T instance, string path) { var serializer = new XmlSerializer(typeof(T)); using (var writer = new StreamWriter(path)) { serializer.Serialize(writer, instance); writer.Flush(); } } }
source share