Exemplo n.º 1
0
 public void ResourceStaticAnalysisCanHandleFilteringExpressions()
 {
     try
     {
         var assemblyResolver = new AssemblyResolver(TestContext.DeploymentDirectory);
         assemblyResolver.Init();
         var inputCfg = TestHelpers.CreateSampleConfig(TestContext, @"SampleRule1.cs", 6);
         // Add a filtering expression that will match only a single resource in the sample file
         inputCfg.DefaultFilteringExpression = "ResourceId.Value.Contains(\"Item6\")";
         var engine = new ResourceStaticAnalysisEngine(inputCfg);
         if (engine.StartRun())
         {
             engine.WaitForJobFinish();
         }
         Assert.IsFalse(engine.Monitor.NoOfExceptionsLogged > 0, "Engine reported some execution errors.");
         // Only Item6 should be processed
         Assert.IsTrue(engine.Monitor.TotalNumResults.Equals(1), "Rule results were not as expected");
     }
     catch (OperationCanceledException ex)
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
     catch (ResourceStaticAnalysisEngineInitializationException ex) // Thrown when there are no rules to run on the input set.
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
 }
Exemplo n.º 2
0
 public void ResourceStaticAnalysisCanBeConfiguredAndRunAgainstSource()
 {
     try
     {
         var assemblyResolver = new AssemblyResolver(TestContext.DeploymentDirectory);
         assemblyResolver.Init();
         var inputCfg = TestHelpers.CreateSampleConfig(TestContext, @"SampleRule1.cs", 6);
         var engine   = new ResourceStaticAnalysisEngine(inputCfg);
         if (engine.StartRun())
         {
             engine.WaitForJobFinish();
         }
         Assert.IsFalse(engine.Monitor.NoOfExceptionsLogged > 0, "Engine reported some execution errors.");
         // Only 3 of the resources should have been flagged by the rule
         Assert.IsTrue(engine.Monitor.TotalNumResults.Equals(3), "Rule results were not as expected");
     }
     catch (OperationCanceledException ex)
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
     catch (ResourceStaticAnalysisEngineInitializationException ex) // Thrown when there are no rules to run on the input set.
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
 }
Exemplo n.º 3
0
 public void ResourceStaticAnalysisCanBeConfiguredWithPreLoadedCOsAndRunAgainstModule()
 {
     try
     {
         var assemblyResolver = new AssemblyResolver(TestContext.DeploymentDirectory);
         assemblyResolver.Init();
         var inputCfg = TestHelpers.CreateSampleConfig(TestContext, @"UnitTests.dll", 6);
         var engine   = new ResourceStaticAnalysisEngine(inputCfg, true);
         engine.ParsedCOList = TestHelpers.GenerateParesdCOs(6);
         if (engine.StartRun())
         {
             engine.WaitForJobFinish();
         }
         Assert.IsFalse(engine.Monitor.NoOfExceptionsLogged > 0, "Engine reported some execution errors.");
         Assert.IsTrue(engine.Monitor.TotalNumResults.Equals(26), "Rule results were not as expected");
     }
     catch (OperationCanceledException ex)
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
     catch (ResourceStaticAnalysisEngineInitializationException ex) // Thrown when there are no rules to run on the input set.
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Method that runs the ResourceStaticAnalysis.
        /// </summary>
        /// <param name="config">Object that contains the configuration of the engine.</param>
        /// <param name="deploymentDirectory">Unit test directory where the engine and its dependencies gets deployed.</param>
        /// <returns>The engine object if succeeds. Null if not.</returns>
        internal static ResourceStaticAnalysisEngine RunEngine(EngineConfig config, string deploymentDirectory)
        {
            try
            {
                var assemblyResolver = new AssemblyResolver(deploymentDirectory);
                assemblyResolver.Init();

                var engine = new ResourceStaticAnalysisEngine(config);
                if (engine.StartRun())
                {
                    engine.WaitForJobFinish();
                }

                return(engine);
            }
            catch (OperationCanceledException ex)
            {
                Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
            }
            catch (ResourceStaticAnalysisEngineInitializationException ex) // Thrown when there are no rules to run on the input set.
            {
                Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
            }

            return(null);
        }
        /// <summary>
        /// Execute the engine against the supplied data source object.
        /// </summary>
        /// <param name="dataSource">Datasource to validate.</param>
        /// <param name="outputRuleSummary">A value indicating if the rule summary should be logged to the output.</param>
        /// <param name="exceptions">Collection of exceptions that occurred during execution.</param>
        /// <returns>Collection of results.</returns>
        public virtual IEnumerable <OutputEntryForOneRule> Execute(object dataSource, bool outputRuleSummary,
                                                                   out List <Exception> exceptions)
        {
            ResourceStaticAnalysisEngine engine             = null;
            List <Exception>             exceptionsInternal = null;

            if (dataSource == null)
            {
                throw new ArgumentNullException("dataSource",
                                                "The dataSource object to run the ResourceStaticAnalysis Engine on cannot be null.");
            }

            if (this.EngineConfiguration == null || this.EngineConfiguration.RuleContainers == null ||
                !this.EngineConfiguration.RuleContainers.Any())
            {
                throw new ArgumentException(
                          "The configuration for the ResourceStaticAnalysis Engine has not been set or no rules were added to the configuration to run.");
            }

            this.EngineConfiguration.DataSourcePkgs.FirstOrDefault().PrimaryDataSource.SetSourceLocation(dataSource);

            engine = new ResourceStaticAnalysisEngine(this.EngineConfiguration);
            engine.Monitor.LogExceptionDetails = true;

            Stopwatch watch = new Stopwatch();

            watch.Start();

            Trace.TraceInformation("Starting Resource Static Analysis Engine...");

            if (engine.StartRun())
            {
                engine.WaitForJobFinish();
            }

            watch.Stop();
            Trace.TraceInformation("Resource Static Analysis Engine completed in {0:00}:{1:00}:{2:00}.{3:00}",
                                   watch.Elapsed.Hours, watch.Elapsed.Minutes, watch.Elapsed.Seconds, watch.Elapsed.Milliseconds / 10);

            if (engine.Monitor.NoOfExceptionsLogged > 0)
            {
                exceptionsInternal = engine.Monitor.ExceptionDetails.ToList();
            }

            engine.Cleanup();

            if (outputRuleSummary)
            {
                string perfResults = engine.Monitor.PrintRulePerformanceSummary();
                Trace.TraceInformation(perfResults);
            }

            exceptions = exceptionsInternal;
            return(engine.CurrentRuleManager.OutputFromAllRules);
        }
Exemplo n.º 6
0
 public void IncompatibleRulesAreFilteredCorrectly()
 {
     try
     {
         var assemblyResolver = new AssemblyResolver(TestContext.DeploymentDirectory);
         assemblyResolver.Init();
         var inputCfg = TestHelpers.CreateSampleConfig(TestContext, "UnitTests.dll", 6);
         var engine   = new ResourceStaticAnalysisEngine(inputCfg);
         if (engine.StartRun())
         {
             engine.WaitForJobFinish();
         }
         Assert.IsFalse(engine.Monitor.NoOfExceptionsLogged > 0, "Engine reported some execution errors.");
         Assert.IsTrue(engine.Monitor.RulePerformance.Count().Equals(8), "Rule results were not as expected");
     }
     catch (OperationCanceledException ex)
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
     catch (ResourceStaticAnalysisEngineInitializationException ex) // Thrown when there are no rules to run on the input set.
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
 }
Exemplo n.º 7
0
 public void ResourceStaticAnalysisCanHandleLargeVolumeOfResources()
 {
     try
     {
         var assemblyResolver = new AssemblyResolver(TestContext.DeploymentDirectory);
         assemblyResolver.Init();
         var inputCfg = TestHelpers.CreateSampleConfig(TestContext, @"UnitTests.dll", 1000000);
         var engine   = new ResourceStaticAnalysisEngine(inputCfg);
         if (engine.StartRun())
         {
             engine.WaitForJobFinish();
         }
         Assert.IsFalse(engine.Monitor.NoOfExceptionsLogged > 0, "Engine reported some execution errors.");
         Assert.IsTrue(engine.Monitor.TotalNumResults > 100000, "Rule results were not as expected");
     }
     catch (OperationCanceledException ex)
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
     catch (ResourceStaticAnalysisEngineInitializationException ex) // Thrown when there are no rules to run on the input set.
     {
         Assert.Fail("ResourceStaticAnalysis engine failed because {0}", ex.Message);
     }
 }