public void SetUp() { IConfigurationXml configFactory = new ConfigurationFactory(Substitute.For <IToastService>()).Create(Filename); const string sutFieldName = "LoadAndSave"; mSut = (ICanLoadAndSaveXml)configFactory.GetType().GetField(sutFieldName, BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(configFactory); if (mSut == null) { Assert.Fail($"Unable to find private instance field '{sutFieldName}'"); } mXmlDoc = Substitute.For <IXmlDocument>(); IXmlDocumentFactory xmlDocFactory = Substitute.For <IXmlDocumentFactory>(); xmlDocFactory.Create().Returns(mXmlDoc); SetSutField("mXmlDocFactory", xmlDocFactory); IFile file = Substitute.For <IFile>(); file.Exists(Filename).Returns(ci => mFileExists); SetSutField("mFile", file); mXmlWriterFactory = Substitute.For <IXmlWriterFactory>(); SetSutField("mXmlWriterFactory", mXmlWriterFactory); //Substitute fileStreamFactory to avoid disk access attempts IFileStreamFactory fileStreamFactory = Substitute.For <IFileStreamFactory>(); SetSutField("mFileStreamFactory", fileStreamFactory); }
public CanLoadAndSaveXml(string filename, IXmlDocumentFactory xmlDocFactory, IFileStreamFactory fileStreamFactory, IXmlWriterFactory xmlWriterFactory, IFile fileWrap) { mFilename = filename ?? throw new ArgumentNullException(nameof(filename)); mXmlDocFactory = xmlDocFactory ?? throw new ArgumentNullException(nameof(xmlDocFactory)); mFileStreamFactory = fileStreamFactory ?? throw new ArgumentNullException(nameof(fileStreamFactory)); mXmlWriterFactory = xmlWriterFactory ?? throw new ArgumentNullException(nameof(xmlWriterFactory)); mFile = fileWrap ?? throw new ArgumentNullException(nameof(fileWrap)); }
public ConfigurationFactory(IToastService toastService) { mToastService = toastService; mXmlDocFactory = new XmlDocumentFactory(); mFileStreamFactory = new FileStreamWrapFactory(); mXmlWriterFactory = new XmlWriterFactory(); mFile = new FileWrap(); }
static void Serialize(this IExtendedXmlSerializer @this, IXmlWriterFactory factory, TextWriter writer, object instance) => @this.Serialize(factory.Get(writer), instance);
static string Serialize(this IExtendedXmlSerializer @this, IXmlWriterFactory factory, Func <Stream> stream, object instance) => new InstanceFormatter(@this, factory, stream).Get(instance);
public InstanceFormatter(IExtendedXmlSerializer serializer, IXmlWriterFactory factory, Func <Stream> stream) { _serializer = serializer; _factory = factory; _stream = stream; }