public async Task ResetBufferDirtyDocData_UpdatesFileNotBuffer()
        {
            var projectFilePath = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj";
            // Use some file encoding that's not the default
            var encoding            = Encoding.Default.Equals(Encoding.UTF8) ? Encoding.UTF32 : Encoding.UTF8;
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFilePath, projectEncoding: encoding);

            var xml = "<Project />";

            var msbuildAccessor = IProjectXmlAccessorFactory.Implement(() => xml, s => { });

            var docData      = IVsPersistDocDataFactory.ImplementAsIVsTextBufferIsDocDataDirty(true, VSConstants.S_OK);
            var textBuffer   = ITextBufferFactory.ImplementSnapshot("<Project />");
            var textDocument = ITextDocumentFactory.ImplementTextBuffer(textBuffer);

            var fileSystem   = new IFileSystemMock();
            var tempFilePath = @"C:\Temp\asdf.1234";

            fileSystem.SetTempFile(tempFilePath);

            var shellUtility         = IVsShellUtilitiesHelperFactory.ImplementGetRDTInfo(Path.Combine(tempFilePath, "ConsoleApp1.csproj"), docData);
            var editorAdapterFactory = IVsEditorAdaptersFactoryServiceFactory.ImplementGetDocumentBuffer(textBuffer);
            var textDocumentService  = ITextDocumentFactoryServiceFactory.ImplementGetTextDocument(textDocument, true);

            var textBufferManager = new TempFileTextBufferManager(unconfiguredProject,
                                                                  msbuildAccessor,
                                                                  editorAdapterFactory,
                                                                  textDocumentService,
                                                                  shellUtility,
                                                                  fileSystem,
                                                                  new IProjectThreadingServiceMock(),
                                                                  IServiceProviderFactory.Create());

            await textBufferManager.InitializeBufferAsync();

            var tempProjectPath = Path.Combine(tempFilePath, "ConsoleApp1.csproj");
            var tempFile        = fileSystem.Files.First(data => StringComparers.Paths.Equals(tempProjectPath, data.Key));

            Assert.Equal("<Project />", fileSystem.ReadAllText(tempProjectPath));

            xml = "<Project></Project>";
            await textBufferManager.ResetBufferAsync();

            Mock.Get(textBuffer).Verify(t => t.Replace(It.IsAny <Span>(), It.IsAny <string>()), Times.Never);
            Assert.Equal("<Project></Project>", fileSystem.ReadAllText(tempProjectPath));
            Mock.Get(unconfiguredProject).Verify(u => u.SaveAsync(null), Times.Once);
        }
        public async Task SetReadonly_SetsOnlyReadonlyFlag()
        {
            var projectFilePath = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj";
            // Use some file encoding that's not the default
            var encoding            = Encoding.Default.Equals(Encoding.UTF8) ? Encoding.UTF32 : Encoding.UTF8;
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFilePath, projectEncoding: encoding);

            var xml = "<Project />";

            var msbuildAccessor = IProjectXmlAccessorFactory.ImplementGetProjectXml(xml);

            var docData      = IVsPersistDocDataFactory.ImplementAsIVsTextBufferGetStateFlags(~(uint)BUFFERSTATEFLAGS.BSF_USER_READONLY);
            var textBuffer   = ITextBufferFactory.ImplementSnapshot("<Project></Project>");
            var textDocument = ITextDocumentFactory.ImplementTextBuffer(textBuffer);

            var fileSystem   = new IFileSystemMock();
            var tempFilePath = @"C:\Temp\asdf.1234";

            fileSystem.SetTempFile(tempFilePath);

            var shellUtility         = IVsShellUtilitiesHelperFactory.ImplementGetRDTInfo(Path.Combine(tempFilePath, "ConsoleApp1.csproj"), docData);
            var editorAdapterFactory = IVsEditorAdaptersFactoryServiceFactory.ImplementGetDocumentBuffer(textBuffer);
            var textDocumentService  = ITextDocumentFactoryServiceFactory.ImplementGetTextDocument(textDocument, true);

            var textBufferManager = new TempFileTextBufferManager(unconfiguredProject,
                                                                  msbuildAccessor,
                                                                  editorAdapterFactory,
                                                                  textDocumentService,
                                                                  shellUtility,
                                                                  fileSystem,
                                                                  new IProjectThreadingServiceMock(),
                                                                  IServiceProviderFactory.Create());

            await textBufferManager.InitializeBufferAsync();

            await textBufferManager.SetReadOnlyAsync(true);

            Mock.Get(docData).As <IVsTextBuffer>().Verify(t =>
                                                          t.SetStateFlags(~(uint)BUFFERSTATEFLAGS.BSF_USER_READONLY | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY));
            await textBufferManager.SetReadOnlyAsync(false);

            Mock.Get(docData).As <IVsTextBuffer>().Verify(t => t.SetStateFlags(~(uint)BUFFERSTATEFLAGS.BSF_USER_READONLY));
        }