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));
 }
示例#3
0
        public ConfigurationFactory(IToastService toastService)
        {
            mToastService = toastService;

            mXmlDocFactory     = new XmlDocumentFactory();
            mFileStreamFactory = new FileStreamWrapFactory();
            mXmlWriterFactory  = new XmlWriterFactory();
            mFile = new FileWrap();
        }
示例#4
0
 static void Serialize(this IExtendedXmlSerializer @this, IXmlWriterFactory factory, TextWriter writer,
                       object instance)
 => @this.Serialize(factory.Get(writer), instance);
示例#5
0
 static string Serialize(this IExtendedXmlSerializer @this, IXmlWriterFactory factory, Func <Stream> stream,
                         object instance)
 => new InstanceFormatter(@this, factory, stream).Get(instance);
示例#6
0
 public InstanceFormatter(IExtendedXmlSerializer serializer, IXmlWriterFactory factory, Func <Stream> stream)
 {
     _serializer = serializer;
     _factory    = factory;
     _stream     = stream;
 }