protected override void ProcessRecord() { foreach (string path in Path) { using (IContentWriter writer = InvokeProvider.Content.GetWriter(path).Single()) { IList items = writer.Write(Value); // Need to close writer before disposing it otherwise Microsoft's // FileSystemProvider throws an exception. writer.Close(); } } }
public void TestGetContentWriter() { FileSystemProvider fileSystemProvider = new FileSystemProvider(); ProviderInfo providerInfoToSet = GetProvider(); fileSystemProvider.SetProviderInformation(providerInfoToSet); fileSystemProvider.Context = new CmdletProviderContext(GetExecutionContext()); IContentWriter contentWriter = fileSystemProvider.GetContentWriter(testPath); contentWriter.Write(new List <string>() { "contentWriterTestContent" }); contentWriter.Close(); Assert.Equal(File.ReadAllText(testPath), testContent + @"contentWriterTestContent" + System.Environment.NewLine); }