예제 #1
0
 private IEnumerable <IClass> GetTestClassesDerivedFrom(IClass c)
 {
     return(TestClasses
            .Where(testClass => testClass.IsDerivedFrom(c))
            .Select(testClass => testClass.Class)
            .ToArray());
 }
예제 #2
0
 // This method gets called by the runtime. Use this method to add services to the container.
 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddInMemoryClasses(TestClasses.Get());
     services.AddInMemorySkills(TestSkills.Get());
     services.AddControllers();
     services.AddSwaggerGen();
 }
예제 #3
0
        /// <summary>
        /// Updates the test class methods based on the newly parsed class
        /// information.
        /// </summary>
        void UpdateTestClass(IClass c)
        {
            if (TestClasses.Contains(c.DotNetName))
            {
                if (IsTestClass(c))
                {
                    TestClass testClass = TestClasses[c.DotNetName];
                    testClass.UpdateClass(c);
                }
                else
                {
                    // TestFixture attribute has been removed so
                    // remove the class from the set of TestClasses.
                    TestClasses.Remove(c.DotNetName);
                }
            }
            else
            {
                // TestFixture attribute may have been recently added to
                // this class so call AddNewTestClass. No need to
                // check if the class is actually a test class since
                // AddNewTestClass does this anyway.
                AddNewTestClass(c);
            }

            var derivedTestClasses = GetTestClassesDerivedFrom(c);

            if (derivedTestClasses.Any())
            {
                UpdateClassesFromProjectContent(derivedTestClasses);
            }
        }
예제 #4
0
 /// <summary>
 /// Adds a new class to the test project's classes only if
 /// the class is a test class.
 /// </summary>
 void AddNewTestClass(IClass c)
 {
     if (IsTestClass(c))
     {
         TestClass testClass = CreateTestClass(c);
         TestClasses.Add(testClass);
     }
 }
예제 #5
0
 /// <summary>
 /// Adds a new class to the test project's classes only if
 /// the class is a test class.
 /// </summary>
 void AddNewTestClass(IClass c)
 {
     if (TestClass.IsTestClass(c))
     {
         TestClass testClass = new TestClass(c);
         TestClasses.Add(testClass);
     }
 }
예제 #6
0
        public Runner(string pathDll)
        {
            NbTest        = 0;
            NbSucceedTest = 0;
            NbFailedTest  = 0;

            LoadDll(pathDll);

            TestClasses = this.Dll.DefinedTypes.Where(typeInfo => typeInfo.CustomAttributes.Any(customAttributeData => customAttributeData.AttributeType.Name == "TestClass")).ToList();
            var methods = new List <MethodInfo>();

            TestClasses.ForEach(typeInfo => typeInfo.GetMethods().ToList().ForEach(methodInfo => methods.Add(methodInfo)));
            TestMethods = methods.Where(methodInfo => methodInfo.CustomAttributes.Any(customAttributeData => customAttributeData.AttributeType.Name == "Test")).ToList();
        }
예제 #7
0
        /// <summary>
        /// Updates the classes and methods based on the new parse information.
        /// </summary>
        /// <param name="oldUnit">The old compiliation unit
        /// (ParseInformationEventArgs.ParseInformation.BestCompilationUnit as ICompilationUnit)</param>
        /// <param name="newUnit">The new compilation unit
        /// (ParseInformationEventArgs.CompilationUnit).</param>
        public void UpdateParseInfo(ICompilationUnit oldUnit, ICompilationUnit newUnit)
        {
            if (!IsParseInfoForThisProject(oldUnit, newUnit))
            {
                return;
            }

            RemovedClasses removedClasses = new RemovedClasses();

            if (oldUnit != null)
            {
                removedClasses.Add(oldUnit.Classes);
            }
            if (newUnit != null)
            {
                foreach (IClass c in newUnit.Classes)
                {
                    UpdateTestClass(c);
                    foreach (IClass innerClass in new InnerClassEnumerator(c))
                    {
                        UpdateTestClass(innerClass);
                        removedClasses.Remove(innerClass);
                    }
                    removedClasses.Remove(c);
                }
            }

            // Remove missing classes.
            foreach (IClass c in removedClasses.GetMissingClasses())
            {
                IClass existingClass = GetExistingTestClassInProject(c);
                if (existingClass != null)
                {
                    UpdateTestClass(existingClass);
                }
                else
                {
                    TestClasses.Remove(c.DotNetName);
                }
            }
        }
예제 #8
0
        void FindAssemblyCleanupMethod()
        {
            var methods =
                TestClasses
                .Select(c => c.AssemblyCleanupMethod)
                .Where(c => c != null)
                .ToList();

            if (methods.Count > 1)
            {
                throw new UserException(
                          $"[TestAssembly] {Assembly.FullName} contains more than one [AssemblyCleanup] method");
            }

            if (methods.Count == 0)
            {
                return;
            }

            AssemblyCleanupMethod = methods[0];
        }
예제 #9
0
        void FindAssemblyCleanupMethod()
        {
            var methods =
                TestClasses
                .Select(c => c.AssemblyCleanupMethod)
                .Where(c => c != null)
                .ToList();

            if (methods.Count > 1)
            {
                throw new UserException(
                          StringExtensions.FormatInvariant(
                              "[TestAssembly] {0} contains more than one [AssemblyCleanup] method",
                              Assembly.FullName));
            }

            if (methods.Count == 0)
            {
                return;
            }

            AssemblyCleanupMethod = methods[0];
        }
예제 #10
0
        private ClassTask GetTestClass(TestExecutionClassClientEvent message)
        {
            var fullClassName = string.Format("{0}.{1}", message.NamespaceName, message.ClassName);

            return(TestClasses.FirstOrDefault(c => c.GetFullClassName() == fullClassName));
        }
예제 #11
0
 /// <summary>
 /// Sets all the test results back to none.
 /// </summary>
 public void ResetTestResults()
 {
     TestClasses.ResetTestResults();
 }
예제 #12
0
 /// <summary>
 /// Updates the test method based on the test result.
 /// </summary>
 public void UpdateTestResult(TestResult testResult)
 {
     TestClasses.UpdateTestResult(testResult);
 }
예제 #13
0
파일: TestFile.cs 프로젝트: Suui/SlothUnit
 private TestFile(string path, string name, TestClasses testClasses)
 {
     Path        = path;
     Name        = name;
     TestClasses = testClasses;
 }