Exemple #1
0
        private EditProjectFileCommand CreateInstance(
            UnconfiguredProject unconfiguredProject = null,
            bool implementCapabilities       = true,
            IMsBuildAccessor msbuildAccessor = null,
            IFileSystem fileSystem           = null,
            ITextDocumentFactoryService textDocumentService      = null,
            IVsEditorAdaptersFactoryService editorAdapterService = null,
            IProjectThreadingService threadingService            = null,
            IVsShellUtilitiesHelper shellUtilities = null
            )
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var uProj        = unconfiguredProject ?? IUnconfiguredProjectFactory.Create();
            var capabilities = IProjectCapabilitiesServiceFactory.ImplementsContains(CapabilityChecker(implementCapabilities));
            var msbuild      = msbuildAccessor ?? IMsBuildAccessorFactory.Create();
            var fs           = fileSystem ?? new IFileSystemMock();
            var tds          = textDocumentService ?? ITextDocumentFactoryServiceFactory.Create();
            var eas          = editorAdapterService ?? IVsEditorAdaptersFactoryServiceFactory.Create();
            var threadServ   = threadingService ?? IProjectThreadingServiceFactory.Create();
            var shellUt      = shellUtilities ?? new TestShellUtilitiesHelper(
                (sp, path) => Tuple.Create(IVsHierarchyFactory.Create(), (uint)1, IVsPersistDocDataFactory.Create(), (uint)1),
                (sp, path, edType, logView) => IVsWindowFrameFactory.Create());

            return(new EditProjectFileCommand(uProj, capabilities, IServiceProviderFactory.Create(), msbuild, fs, tds, eas, threadServ, shellUt));
        }
        public async Task NonStandardEncoding_UsesProjectEncoding()
        {
            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 msbuildAccessor = IProjectXmlAccessorFactory.ImplementGetProjectXml("<Project />");

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

            fileSystem.SetTempFile(tempFilePath);

            var textBufferManager = new TempFileTextBufferManager(unconfiguredProject,
                                                                  msbuildAccessor,
                                                                  IVsEditorAdaptersFactoryServiceFactory.Create(),
                                                                  ITextDocumentFactoryServiceFactory.Create(),
                                                                  IVsShellUtilitiesHelperFactory.Create(),
                                                                  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(encoding, tempFile.Value.FileEncoding);
        }
        public async Task Initialize_CreatesTempFile()
        {
            var projectFilePath     = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj";
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFilePath, projectEncoding: Encoding.Default);

            var msbuildAccessor = IProjectXmlAccessorFactory.ImplementGetProjectXml("<Project />");

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

            fileSystem.SetTempFile(tempFilePath);

            var textBufferManager = new TempFileTextBufferManager(unconfiguredProject,
                                                                  msbuildAccessor,
                                                                  IVsEditorAdaptersFactoryServiceFactory.Create(),
                                                                  ITextDocumentFactoryServiceFactory.Create(),
                                                                  IVsShellUtilitiesHelperFactory.Create(),
                                                                  fileSystem,
                                                                  new IProjectThreadingServiceMock(),
                                                                  IServiceProviderFactory.Create());

            await textBufferManager.InitializeBufferAsync();

            var tempProjectPath = Path.Combine(tempFilePath, "ConsoleApp1.csproj");

            Assert.True(fileSystem.FileExists(tempProjectPath));
            Assert.Equal("<Project />", fileSystem.ReadAllText(tempProjectPath));
        }
 public void NullShellUtilities_Throws()
 {
     Assert.Throws <ArgumentNullException>("shellUtilities", () => new TempFileBufferStateListener(
                                               IProjectFileEditorPresenterFactory.Create(),
                                               IVsEditorAdaptersFactoryServiceFactory.Create(),
                                               ITextDocumentFactoryServiceFactory.Create(),
                                               IProjectThreadingServiceFactory.Create(),
                                               null,
                                               IServiceProviderFactory.Create()));
 }
 public void NullFileSystem_Throws()
 {
     Assert.Throws <ArgumentNullException>("fileSystem", () => new TempFileTextBufferManager(
                                               UnconfiguredProjectFactory.Create(),
                                               IProjectXmlAccessorFactory.Create(),
                                               IVsEditorAdaptersFactoryServiceFactory.Create(),
                                               ITextDocumentFactoryServiceFactory.Create(),
                                               IVsShellUtilitiesHelperFactory.Create(),
                                               null,
                                               IProjectThreadingServiceFactory.Create(),
                                               IServiceProviderFactory.Create()));
 }
 public void TempFileBufferStateListener_NullEditorState_Throws()
 {
     Assert.Throws <ArgumentNullException>("editorState", () => new TempFileBufferStateListener(null,
                                                                                                IVsEditorAdaptersFactoryServiceFactory.Create(),
                                                                                                ITextDocumentFactoryServiceFactory.Create(),
                                                                                                IProjectThreadingServiceFactory.Create(),
                                                                                                IVsShellUtilitiesHelperFactory.Create(),
                                                                                                IServiceProviderFactory.Create()));
 }