コード例 #1
0
        /// <summary>
        /// Create a Document from a string through creating a project that contains it.
        /// </summary>
        /// <param name="fileSources">Classes in the form of MvxTestFileSources</param>
        /// <param name="fileSource">The file the should be added last, aldo also to be returned</param>
        /// <returns>A Document created from the source string</returns>
        protected static Document CreateDocument(MvxTestFileSource[] fileSources, MvxTestFileSource fileSource)
        {
            var documents = fileSources?.ToList() ?? new List <MvxTestFileSource>();

            documents.Add(fileSource);

            return(CreateSolution(documents.ToArray())
                   .GetProject(GetProjectId(fileSource)).Documents.Last());
        }
コード例 #2
0
 private static ProjectId GetProjectId(MvxTestFileSource fileSource)
 {
     if (fileSource.ProjType == MvxProjType.Core)
     {
         return(_coreProjectId);
     }
     if (fileSource.ProjType == MvxProjType.Droid)
     {
         return(_droidProjectId);
     }
     return(_iosProjectId);
 }
コード例 #3
0
        private static bool IsFromProject(MvxTestFileSource file, ProjectId projectId)
        {
            MvxProjType mvxProjType;

            if (projectId == _coreProjectId)
            {
                mvxProjType = MvxProjType.Core;
            }
            else if (projectId == _droidProjectId)
            {
                mvxProjType = MvxProjType.Droid;
            }
            else
            {
                mvxProjType = MvxProjType.Ios;
            }
            return(file.ProjType == mvxProjType);
        }
コード例 #4
0
 /// <summary>
 /// Given classes in the form of strings, their language, and an IDiagnosticAnlayzer to apply to it, return the diagnostics found in the string after converting it to a document.
 /// </summary>
 /// <param name="fileSources">Classes in the form of MvxTestFileSources</param>
 /// <param name="analyzer">The analyzer to be run on the sources</param>
 /// <returns>An IEnumerable of Diagnostics that surfaced in the source code, sorted by Location</returns>
 private static Diagnostic[] GetSortedDiagnostics(MvxTestFileSource[] fileSources, DiagnosticAnalyzer analyzer)
 {
     return GetSortedDiagnosticsFromDocuments(analyzer, GetDocuments(fileSources));
 }
コード例 #5
0
        /// <summary>
        /// Create a project using the inputted strings as sources.
        /// </summary>
        /// <param name="fileSources">Classes in the form of MvxTestFileSources</param>
        /// <returns>A Solution created out of the Documents created from the source strings</returns>
        private static Solution CreateSolution(MvxTestFileSource[] fileSources)
        {
            string fileNamePrefix = DefaultFilePathPrefix;

            _coreProjectId = ProjectId.CreateNewId(debugName: TestCoreProjectName);
            _droidProjectId = ProjectId.CreateNewId(debugName: TestDroidProjectName);
            _iosProjectId = ProjectId.CreateNewId(debugName: TestIosProjectName);

            var solution = new AdhocWorkspace()
                .CurrentSolution
                .AddProject(_coreProjectId, TestCoreProjectName, TestCoreProjectName, LanguageNames.CSharp)
                .AddProject(_droidProjectId, TestDroidProjectName, TestDroidProjectName, LanguageNames.CSharp)
                .AddProject(_iosProjectId, TestIosProjectName, TestIosProjectName, LanguageNames.CSharp)
                .AddMetadataReference(_coreProjectId, _corlibReference)
                .AddMetadataReference(_coreProjectId, _systemCoreReference)
                .AddMetadataReference(_coreProjectId, _cSharpSymbolsReference)
                .AddMetadataReference(_coreProjectId, _codeAnalysisReference)
                .AddMetadataReference(_coreProjectId, _mvvmCrossCoreReference)
                .AddMetadataReference(_coreProjectId, _mvvmCrossPlatformReference)
                .AddMetadataReference(_coreProjectId, _componentModelReference)
                .AddMetadataReference(_coreProjectId, _objectModelReference)
                .AddMetadataReference(_coreProjectId, _runtimeReference)
                .AddMetadataReference(_droidProjectId, _corlibReference)
                .AddMetadataReference(_droidProjectId, _systemCoreReference)
                .AddMetadataReference(_droidProjectId, _cSharpSymbolsReference)
                .AddMetadataReference(_droidProjectId, _codeAnalysisReference)
                .AddMetadataReference(_droidProjectId, _mvvmCrossCoreReference)
                .AddMetadataReference(_droidProjectId, _mvvmCrossDroidReference)
                .AddMetadataReference(_droidProjectId, _componentModelReference)
                .AddMetadataReference(_droidProjectId, _objectModelReference)
                .AddProjectReference(_droidProjectId, new ProjectReference(_coreProjectId))
                .AddMetadataReference(_iosProjectId, _corlibReference)
                .AddMetadataReference(_iosProjectId, _systemCoreReference)
                .AddMetadataReference(_iosProjectId, _cSharpSymbolsReference)
                .AddMetadataReference(_iosProjectId, _codeAnalysisReference)
                .AddMetadataReference(_iosProjectId, _mvvmCrossCoreReference)
                .AddMetadataReference(_iosProjectId, _mvvmCrossIosReference)
                .AddMetadataReference(_iosProjectId, _componentModelReference)
                .AddMetadataReference(_iosProjectId, _objectModelReference)
                .AddProjectReference(_iosProjectId, new ProjectReference(_coreProjectId));

            int count = 0;
            foreach (var fileSource in fileSources)
            {
                var newFileName = fileNamePrefix + count + "." + CSharpDefaultFileExt;
                var documentId = DocumentId.CreateNewId(GetProjectId(fileSource), debugName: newFileName);
                solution = solution.AddDocument(documentId, newFileName, SourceText.From(fileSource.Source));
                count++;
            }

            return solution;
        }
コード例 #6
0
 private static ProjectId GetProjectId(MvxTestFileSource fileSource)
 {
     if (fileSource.ProjType == MvxProjType.Core)
         return _coreProjectId;
     if (fileSource.ProjType == MvxProjType.Droid)
         return _droidProjectId;
     return _iosProjectId;
 }
コード例 #7
0
        /// <summary>
        /// Create a Document from a string through creating a project that contains it.
        /// </summary>
        /// <param name="fileSources">Classes in the form of MvxTestFileSources</param>
        /// <param name="fileSource">The file the should be added last, aldo also to be returned</param>
        /// <returns>A Document created from the source string</returns>
        protected static Document CreateDocument(MvxTestFileSource[] fileSources, MvxTestFileSource fileSource)
        {
            var documents = fileSources?.ToList() ?? new List<MvxTestFileSource>();
            documents.Add(fileSource);

            return CreateSolution(documents.ToArray())
                .GetProject(GetProjectId(fileSource)).Documents.Last();
        }
コード例 #8
0
 private static bool IsFromProject(MvxTestFileSource file, ProjectId projectId)
 {
     MvxProjType mvxProjType;
     if (projectId == _coreProjectId)
         mvxProjType = MvxProjType.Core;
     else if (projectId == _droidProjectId)
         mvxProjType = MvxProjType.Droid;
     else
         mvxProjType = MvxProjType.Ios;
     return file.ProjType == mvxProjType;
 }
コード例 #9
0
        /// <summary>
        /// Given an array of strings as sources and a language, turn them into a project and return the documents and spans of it.
        /// </summary>
        /// <param name="fileSources">Classes in the form of MvxTestFileSources</param>
        /// <returns>A Tuple containing the Documents produced from the sources and their TextSpans if relevant</returns>
        protected static Document[] GetDocuments(MvxTestFileSource[] fileSources)
        {
            var solution = CreateSolution(fileSources);

            var documents = new List<Document>();
            foreach (var projectId in solution.ProjectIds)
            {
                var project = solution.GetProject(projectId);
                var projectDocuments = project.Documents.ToArray();

                if (fileSources.Count(f => IsFromProject(f, projectId)) != projectDocuments.Length)
                {
                    throw new SystemException("Amount of sources did not match amount of Documents created");
                }
                documents.AddRange(projectDocuments);
            }

            return documents.ToArray();
        }