Example #1
0
        private MethodUsage CreateUsage(MemberReference operand, ModuleDefinition assembly, TypeDefinition type, MethodDefinition method, string testAssemblyPath)
        {
            if (operand == null)
                return null;

            Test test = new Test
                {
                    PathToAssembly = Path.GetDirectoryName(testAssemblyPath),
                    AssemblyName = assembly.Assembly.Name.Name,
                    NamespaceName = type.Namespace,
                    ClassName = type.Name,
                    MethodName = method.Name
                };

            var instructionCall = new MethodUsage
                {
                    AssemblyName = operand.DeclaringType.Scope.Name + ".dll",
                    NamespaceName = operand.DeclaringType.Namespace,
                    ClassName = operand.DeclaringType.Name,
                    MethodName = operand.Name,
                    TestCoverage = new List<Test> {test}
                };

            return instructionCall;
        }
        public void Given_a_list_of_method_usages_it_filters_down_based_on_changed_methods_list()
        {
            ChangedMethod method = new ChangedMethod {
                                                         ClassName = "Class1", MethodName = "Method1"
                                                     };

            MethodUsage usage = new MethodUsage {ClassName = "Class1", MethodName = "Method1"};

            var expectedTestToExecuted = new Test{ClassName = "Class1Tests", MethodName = "Method1Tests"};
            usage.TestCoverage = new List<Test>();
            usage.TestCoverage.Add(expectedTestToExecuted);

            ChangedMethodsFilter filter = new ChangedMethodsFilter();
            IEnumerable<Test> testsToExecuted = filter.FindUnitTestsAffectedByChanges(new List<ChangedMethod> {method}, new List<MethodUsage> {usage});

            Assert.That(testsToExecuted.Count(), Is.EqualTo(1));
            Assert.IsTrue(testsToExecuted.Contains(expectedTestToExecuted));
        }