public void IsMvcProject_Returns_True_If_MvcFeature_Is_Present()
        {
            var mockResult = new FeatureDetectionResult
            {
                FeatureStatus = { { Constants.AspNetMvcFeatureName, true } }
            };

            Assert.True(mockResult.IsMvcProject());
        }
Beispiel #2
0
        public void DownloadTestProjects()
        {
            _tempDirName = Path.Combine("Projects", "TempFD");
            _tempBaseDir = Path.Combine(TestUtils.GetTstPath(), _tempDirName);
            var tempDownloadDir = Path.Combine(_tempBaseDir, "d");

            // Download test solutions
            DownloadTestProjects(tempDownloadDir);

            // Get directory of each solution
            var tempCoreMvcSolutionDir                 = GetSolutionDir(tempDownloadDir, CoreMvcSolutionName);
            var tempCoreWebApiSolutionDir              = GetSolutionDir(tempDownloadDir, CoreWebApiSolutionName);
            var tempEfSolutionDir                      = GetSolutionDir(tempDownloadDir, EfSolutionName);
            var tempMvcSolutionDir                     = GetSolutionDir(tempDownloadDir, MvcSolutionName);
            var tempWebApiSolutionDir                  = GetSolutionDir(tempDownloadDir, WebApiSolutionName);
            var tempWebClassLibrarySolutionDir         = GetSolutionDir(tempDownloadDir, WebClassLibrarySolutionName);
            var tempWindowsAuthenticationSolutionDir   = GetSolutionDir(tempDownloadDir, WindowsAuthenticationSolutionName);
            var tempFormsAuthenticationSolutionDir     = GetSolutionDir(tempDownloadDir, FormsAuthenticationSolutionName);
            var tempFederatedAuthenticationSolutionDir = GetSolutionDir(tempDownloadDir, FederatedAuthenticationSolutionName);

            // Copy solutions to a directory with a shorter path
            var destDir = "dest";

            _targetDir = Path.Combine(_tempBaseDir, destDir);
            TestUtils.CopyDirectory(tempCoreMvcSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _coreMvcDir)));
            TestUtils.CopyDirectory(tempCoreWebApiSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _coreWebApiDir)));
            TestUtils.CopyDirectory(tempEfSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _efDir)));
            TestUtils.CopyDirectory(tempMvcSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _mvcDir)));
            TestUtils.CopyDirectory(tempWebApiSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _webApiDir)));
            TestUtils.CopyDirectory(tempWebClassLibrarySolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _webClassLibraryDir)));
            TestUtils.CopyDirectory(tempWindowsAuthenticationSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _windowsAuthenticationDir)));
            TestUtils.CopyDirectory(tempFormsAuthenticationSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _formsAuthenticationDir)));
            TestUtils.CopyDirectory(tempFederatedAuthenticationSolutionDir, new DirectoryInfo(Path.Combine(_targetDir, _federatedAuthenticationDir)));

            // Run source code analysis
            CoreMvcAnalyzerResults                 = AnalyzerResultsFactory.GetAnalyzerResults(CoreMvcSolutionPath);
            CoreWebApiAnalyzerResults              = AnalyzerResultsFactory.GetAnalyzerResults(CoreWebApiSolutionPath);
            EfAnalyzerResults                      = AnalyzerResultsFactory.GetAnalyzerResults(EfSolutionPath);
            MvcAnalyzerResults                     = AnalyzerResultsFactory.GetAnalyzerResults(MvcSolutionPath);
            WebApiAnalyzerResults                  = AnalyzerResultsFactory.GetAnalyzerResults(WebApiSolutionPath);
            WebClassLibraryAnalyzerResults         = AnalyzerResultsFactory.GetAnalyzerResults(WebClassLibrarySolutionPath);
            WindowsAuthenticationAnalyzerResults   = AnalyzerResultsFactory.GetAnalyzerResults(WindowsAuthenticationSolutionPath);
            FormsAuthenticationAnalyzerResults     = AnalyzerResultsFactory.GetAnalyzerResults(FormsAuthenticationSolutionPath);
            FederatedAuthenticationAnalyzerResults = AnalyzerResultsFactory.GetAnalyzerResults(FederatedAuthenticationSolutionPath);

            // Detect features in each solution
            FeatureDetector = new FeatureDetector(ConfigFile);
            CoreMvcFeatureDetectionResult                 = FeatureDetector.DetectFeaturesInProjects(CoreMvcAnalyzerResults)[CoreMvcProjectPath];
            CoreWebApiFeatureDetectionResult              = FeatureDetector.DetectFeaturesInProjects(CoreWebApiAnalyzerResults)[CoreWebApiProjectPath];
            Ef6FeatureDetectionResult                     = FeatureDetector.DetectFeaturesInProjects(EfAnalyzerResults)[Ef6ProjectPath];
            MvcFeatureDetectionResult                     = FeatureDetector.DetectFeaturesInProjects(MvcAnalyzerResults)[MvcProjectPath];
            WebApiFeatureDetectionResult                  = FeatureDetector.DetectFeaturesInProjects(WebApiAnalyzerResults)[WebApiProjectPath];
            WebClassLibraryFeatureDetectionResult         = FeatureDetector.DetectFeaturesInProjects(WebClassLibraryAnalyzerResults)[WebClassLibraryProjectPath];
            WindowsAuthenticationFeatureDetectionResult   = FeatureDetector.DetectFeaturesInProjects(WindowsAuthenticationAnalyzerResults)[WindowsAuthenticationProjectPath];
            FormsAuthenticationFeatureDetectionResult     = FeatureDetector.DetectFeaturesInProjects(FormsAuthenticationAnalyzerResults)[FormsAuthenticationProjectPath];
            FederatedAuthenticationFeatureDetectionResult = FeatureDetector.DetectFeaturesInProjects(FederatedAuthenticationAnalyzerResults)[FederatedAuthenticationProjectPath];
        }
        public void IsWebClassLibrary_Returns_True_If_WebClassFeature_Is_Present()
        {
            var mockResult = new FeatureDetectionResult
            {
                FeatureStatus = { { Constants.WebClassLibraryFeatureName, true } }
            };

            Assert.True(mockResult.IsWebClassLibrary());
        }
 public void SetUp()
 {
     FeatureDetectionResult = new FeatureDetectionResult();
     FeatureDetectionResult.FeatureStatus[PresentFeature1] = true;
     FeatureDetectionResult.FeatureStatus[PresentFeature2] = true;
     FeatureDetectionResult.FeatureStatus[AbsentFeature1]  = false;
     FeatureDetectionResult.FeatureStatus[AbsentFeature2]  = false;
     FeatureDetectionResult.ProjectPath = @"some\path";
 }
        public void SetUp()
        {
            var analyzerResult = TestProjectsSetupFixture.EfAnalyzerResults.First(a =>
                                                                                  a.ProjectResult.ProjectFilePath == TestProjectsSetupFixture.Ef6ProjectPath);

            var featureDetector = new FeatureDetector(ConfigFile);

            _featureDetectionResult = featureDetector.DetectFeaturesInProject(analyzerResult);
        }
Beispiel #6
0
 public void SetUp()
 {
     TestProjectDirectory                   = TestUtils.GetTestAssemblySourceDirectory(typeof(TestUtils));
     FeatureDetector                        = TestProjectsSetupFixture.FeatureDetector;
     _coreMvcFeatureDetectionResult         = TestProjectsSetupFixture.CoreMvcFeatureDetectionResult;
     _coreWebApiFeatureDetectionResult      = TestProjectsSetupFixture.CoreWebApiFeatureDetectionResult;
     _ef6FeatureDetectionResult             = TestProjectsSetupFixture.Ef6FeatureDetectionResult;
     _mvcFeatureDetectionResult             = TestProjectsSetupFixture.MvcFeatureDetectionResult;
     _webApiFeatureDetectionResult          = TestProjectsSetupFixture.WebApiFeatureDetectionResult;
     _webClassLibraryFeatureDetectionResult = TestProjectsSetupFixture.WebClassLibraryFeatureDetectionResult;
 }
Beispiel #7
0
 internal ProjectType GetProjectType(FeatureDetectionResult projectTypeFeatureResult)
 {
     if (projectTypeFeatureResult.IsMvcProject())
     {
         return(ProjectType.Mvc);
     }
     else if (projectTypeFeatureResult.IsWebApiProject())
     {
         return(ProjectType.WebApi);
     }
     else if (projectTypeFeatureResult.IsWebClassLibrary())
     {
         return(ProjectType.WebClassLibrary);
     }
     return(ProjectType.ClassLibrary);
 }
Beispiel #8
0
 private ProjectType GetProjectType(FeatureDetectionResult projectTypeFeatureResult)
 {
     if (projectTypeFeatureResult.IsMvcProject())
     {
         return ProjectType.Mvc;
     }
     else if (projectTypeFeatureResult.IsWebApiProject())
     {
         return ProjectType.WebApi;
     }
     else if (projectTypeFeatureResult.IsWebClassLibrary())
     {
         return ProjectType.WebClassLibrary;
     }
     return ProjectType.ClassLibrary;
 }
Beispiel #9
0
 public void SetUp()
 {
     TestProjectDirectory                           = TestUtils.GetTestAssemblySourceDirectory(typeof(TestUtils));
     FeatureDetector                                = TestProjectsSetupFixture.FeatureDetector;
     _coreMvcFeatureDetectionResult                 = TestProjectsSetupFixture.CoreMvcFeatureDetectionResult;
     _coreWebApiFeatureDetectionResult              = TestProjectsSetupFixture.CoreWebApiFeatureDetectionResult;
     _ef6FeatureDetectionResult                     = TestProjectsSetupFixture.Ef6FeatureDetectionResult;
     _mvcFeatureDetectionResult                     = TestProjectsSetupFixture.MvcFeatureDetectionResult;
     _webFormsFeatureDetectionResult                = TestProjectsSetupFixture.WebFormsFeatureDetectionResult;
     _webApiFeatureDetectionResult                  = TestProjectsSetupFixture.WebApiFeatureDetectionResult;
     _webClassLibraryFeatureDetectionResult         = TestProjectsSetupFixture.WebClassLibraryFeatureDetectionResult;
     _windowsAuthenticationFeatureDetectionResult   = TestProjectsSetupFixture.WindowsAuthenticationFeatureDetectionResult;
     _formsAuthenticationFeatureDetectionResult     = TestProjectsSetupFixture.FormsAuthenticationFeatureDetectionResult;
     _iisConfigFeatureDetectionResult               = TestProjectsSetupFixture.IISConfigFeatureDetectionResult;
     _federatedAuthenticationFeatureDetectionResult = TestProjectsSetupFixture.FederatedAuthenticationFeatureDetectionResult;
     _coreWCFServiceConfigFeatureDetectionResult    = TestProjectsSetupFixture.CoreWCFServiceConfigFeatureDetectionResult;
     _coreWCFServiceCodeFeatureDetectionResult      = TestProjectsSetupFixture.CoreWCFServiceCodeFeatureDetectionResult;
     _wcfClientFeatureDetectionResult               = TestProjectsSetupFixture.WCFClientFeatureDetectionResult;
     _wcfServiceHostFeatureDetectionResult          = TestProjectsSetupFixture.CoreWCFServiceCodeFeatureDetectionResult;
 }
Beispiel #10
0
        /// <summary>
        /// Searches AnalyzerResult object for specified features
        /// </summary>
        /// <param name="analyzerResult">AnalyzerResult object to be searched for features</param>
        /// <returns>FeatureDetectionResults containing information about the feature search</returns>
        public FeatureDetectionResult DetectFeaturesInProject(AnalyzerResult analyzerResult)
        {
            var result = new FeatureDetectionResult
            {
                ProjectPath = analyzerResult.ProjectResult.ProjectFilePath
            };

            foreach (var loadedFeature in LoadedFeatureSet.AllFeatures)
            {
                try
                {
                    result.FeatureStatus[loadedFeature.Name] = loadedFeature.IsPresent(analyzerResult);
                }
                catch (Exception e)
                {
                    Logger.LogError(e, $"Feature detection failed for {loadedFeature.GetType()}");
                }
            }

            return(result);
        }
Beispiel #11
0
 internal ProjectType GetProjectType(FeatureDetectionResult projectTypeFeatureResult)
 {
     if (projectTypeFeatureResult.IsMvcProject())
     {
         return(ProjectType.Mvc);
     }
     else if (projectTypeFeatureResult.IsWebApiProject())
     {
         return(ProjectType.WebApi);
     }
     else if (projectTypeFeatureResult.IsAspNetWebFormsProject())
     {
         return(ProjectType.WebForms);
     }
     else if (projectTypeFeatureResult.IsWebClassLibrary())
     {
         return(ProjectType.WebClassLibrary);
     }
     else if (projectTypeFeatureResult.IsWCFServiceConfigBasedProject())
     {
         if (projectTypeFeatureResult.HasServiceHostReference())
         {
             return(ProjectType.WCFConfigBasedService);
         }
         else
         {
             return(ProjectType.WCFServiceLibrary);
         }
     }
     else if (projectTypeFeatureResult.IsWCFServiceCodeBasedProject())
     {
         return(ProjectType.WCFCodeBasedService);
     }
     else if (projectTypeFeatureResult.IsWCFClientProject())
     {
         return(ProjectType.WCFClient);
     }
     return(ProjectType.ClassLibrary);
 }
Beispiel #12
0
        private void InitRules(PortCoreConfiguration projectConfiguration, AnalyzerResult analyzerResult)
        {
            using var projectTypeFeatureDetector = new FeatureDetector();

            ProjectTypeFeatureResults = projectTypeFeatureDetector.DetectFeaturesInProject(analyzerResult);

            projectConfiguration.ProjectType = _solutionPort.GetProjectType(ProjectTypeFeatureResults);
            if (projectConfiguration.UseDefaultRules)
            {
                //If a rules dir was provided, copy files from that dir into the rules folder
                if (!string.IsNullOrEmpty(projectConfiguration.RulesDir))
                {
                    _solutionPort.CopyOverrideRules(projectConfiguration.RulesDir);
                }
                projectConfiguration.RulesDir = Constants.RulesDefaultPath;
                var projectResult = analyzerResult.ProjectResult;

                projectResult?.SourceFileResults?.SelectMany(s => s.References)?.Select(r => r.Namespace).Distinct().ToList().ForEach(currentReference =>
                {
                    if (currentReference != null && !ProjectReferences.Contains(currentReference))
                    {
                        ProjectReferences.Add(currentReference);
                    }
                });

                projectResult?.SourceFileResults?.SelectMany(s => s.Children.OfType <UsingDirective>())?.Select(u => u.Identifier).Distinct().ToList().ForEach(currentReference =>
                {
                    if (currentReference != null && !ProjectReferences.Contains(currentReference))
                    {
                        ProjectReferences.Add(currentReference);
                    }
                });
                ProjectReferences.Add(Constants.ProjectRecommendationFile);
            }

            _solutionPort.DownloadRecommendationFiles(ProjectReferences);
        }
 /// <summary>
 /// Queries a FeatureDetectionResult object to determine if the project is a WCF Client Project.
 /// </summary>
 /// <param name="featureDetectionResult">Result from feature detection</param>
 /// <returns>Whether or not the project is a WCF Client Project</returns>
 public static bool IsWCFClientProject(this FeatureDetectionResult featureDetectionResult)
 {
     return(featureDetectionResult.FeatureStatus.GetValueOrDefault(Constants.WCFClientFeatureName, false));
 }
 /// <summary>
 /// Queries a FeatureDetectionResult object to determine if the project is a WCF Code based Service Project.
 /// </summary>
 /// <param name="featureDetectionResult">Result from feature detection</param>
 /// <returns>Whether or not the project is a WCF Code Based Service Project</returns>
 public static bool IsWCFServiceCodeBasedProject(this FeatureDetectionResult featureDetectionResult)
 {
     return(featureDetectionResult.FeatureStatus.GetValueOrDefault(Constants.WCFServiceCodeFeatureName, false));
 }
 /// <summary>
 /// Queries a FeatureDetectionResult object to determine if the project is a .NET Framework MVC project
 /// </summary>
 /// <param name="featureDetectionResult">Result from feature detection</param>
 /// <returns>Whether or not the project is a .NET Framework MVC project</returns>
 public static bool IsMvcProject(this FeatureDetectionResult featureDetectionResult)
 {
     return(featureDetectionResult.FeatureStatus.GetValueOrDefault(Constants.AspNetMvcFeatureName, false));
 }
Beispiel #16
0
 public void SetUp()
 {
     _featureDetectionResult = TestProjectsSetupFixture.Ef6FeatureDetectionResult;
 }
 /// <summary>
 /// Queries a FeatureDetectionResult object to determine if the project is a WebAPI project only
 /// </summary>
 /// <param name="featureDetectionResult">Result from feature detection</param>
 /// <returns>Whether or not the project is a WebAPI project only</returns>
 public static bool IsWebApiProjectOnly(this FeatureDetectionResult featureDetectionResult)
 {
     return(IsWebApiProject(featureDetectionResult) && !IsMvcProject(featureDetectionResult));
 }
Beispiel #18
0
 private void AppendProjectResult(ProjectResult projectAnalysisResult, ProjectResult projectResult, AnalyzerResult analyzerResult, FeatureDetectionResult featureDetectionResult)
 {
     _context.AddProjectToMap(analyzerResult);
     _solutionAnalysisResult.ProjectResults.Add(projectAnalysisResult);
     _solutionRunResult.ProjectResults.Add(projectResult);
     _projectTypeFeatureResults.Add(projectResult.ProjectFile, featureDetectionResult);
 }
 /// <summary>
 /// Queries a FeatureDetectionResult object to determine if the project is a Web class library
 /// </summary>
 /// <param name="featureDetectionResult">Result from feature detection</param>
 /// <returns>Whether or not the project is a Web class library</returns>
 public static bool IsWebClassLibrary(this FeatureDetectionResult featureDetectionResult)
 {
     return(featureDetectionResult.FeatureStatus.GetValueOrDefault(Constants.WebClassLibraryFeatureName, false));
 }
 /// <summary>
 ///
 /// Queries a FeatureDetectionResult object to determine if the project has a ServiceHost Reference, by checking
 /// if project Type is WCFServiceHost.
 /// </summary>
 /// <param name="featureDetectionResult"></param>
 /// <returns></returns>
 public static bool HasServiceHostReference(this FeatureDetectionResult featureDetectionResult)
 {
     return(featureDetectionResult.FeatureStatus.GetValueOrDefault(Constants.WCFServiceHostFeatureName, false));
 }