public CodeVisualizer(
     OriginalCodebase originalCodebase,
     ICodeDifferenceCreator differenceCreator)
 {
     _originalCodebase  = originalCodebase;
     _differenceCreator = differenceCreator;
 }
 public CodeVisualizer(
     OriginalCodebase originalCodebase,
     ICodeDifferenceCreator differenceCreator)
 {
     _originalCodebase = originalCodebase;
     _differenceCreator = differenceCreator;
 }
Beispiel #3
0
        public void IntegrationTestingAutoMapper()
        {
            var paths = new[] {
                TestProjects.AutoMapper,
                TestProjects.AutoMapperNet4,
                TestProjects.AutoMapperTests
            }.Select(_ => _.ToFilePathAbs()).ToList();

            var cci      = new CciModuleSource(TestProjects.AutoMapper);
            var cci1     = new CciModuleSource(TestProjects.AutoMapperNet4);
            var cciTests = new CciModuleSource(TestProjects.AutoMapperTests);

            var original = new OriginalCodebase(new List <CciModuleSource> {
                cci, cci1, cciTests
            });
            var toMutate = new List <string> {
                TestProjects.AutoMapper,
                TestProjects.AutoMapperNet4
            };

            var oper = new IdentityOperator2().InList <IMutationOperator>();

            var mutants = SetupMutations(original, paths, toMutate, oper);

            var vis = _kernel.Get <ICodeVisualizer>();


            var muma = _kernel.Get <MutantMaterializer>();


            IObserver <SessionEventArgs> sub = new ReplaySubject <SessionEventArgs>();

            foreach (var mutant in mutants)
            {
                //  var copy = new CciModuleSource(TestProjects.MiscUtil);
                //    MutationResult result = exec.ExecuteMutation(mutant, copy).Result;
                var muma2 = _kernel.Get <IFactory <TestingMutant> >().CreateWithParams(sub, mutant);


                var r          = muma2.RunAsync().Result;
                var namespaces = _kernel.Get <TestsContainer>().CreateMutantTestTree(mutant);
                var meth       = namespaces.Cast <CheckedNode>()
                                 .SelectManyRecursive(n => n.Children, leafsOnly: true).OfType <TestNodeMethod>();

                meth.Count(m => m.State == TestNodeState.Failure).ShouldEqual(0);
                //  var storedMutantInfo = muma.StoreMutant(mutant).Result;

                //  RunTestsForMutant(_choices.MutantsTestingOptions, _storedMutantInfo);

                //   CodeWithDifference differenceListing = vis.CreateDifferenceListing(CodeLanguage.CSharp, mutant, result).Result;
                //     differenceListing.LineChanges.Count.ShouldEqual(2);
            }
        }
Beispiel #4
0
        public void IntegrationTestingMiscUtil()
        {
            var paths = new[] {
                TestProjects.MiscUtil,
                TestProjects.MiscUtilTests
            }.Select(_ => _.ToFilePathAbs()).ToList();

            var cci      = new CciModuleSource(TestProjects.MiscUtil);
            var cciTests = new CciModuleSource(TestProjects.MiscUtilTests);

            var toMutate = TestProjects.MiscUtil.InList();
            var original = new OriginalCodebase(new List <CciModuleSource> {
                cci, cciTests
            });

            var type   = (NamedTypeDefinition)cci.Module.Module.GetAllTypes().Single(t => t.Name.Value == "Range");
            var method = type.Methods.First(m => m.Name.Value == "Contains");

            var oper = new ROR_RelationalOperatorReplacement().InList <IMutationOperator>();

            var mutants = SetupMutations(original, paths, toMutate, oper, new MethodIdentifier(method));

            var vis = _kernel.Get <ICodeVisualizer>();


            var muma = _kernel.Get <MutantMaterializer>();


            IObserver <SessionEventArgs> sub = new ReplaySubject <SessionEventArgs>();

            foreach (var mutant in mutants)
            {
                //  var copy = new CciModuleSource(TestProjects.MiscUtil);
                //    MutationResult result = exec.ExecuteMutation(mutant, copy).Result;
                var muma2 = _kernel.Get <IFactory <TestingMutant> >().CreateWithParams(sub, mutant);


                var r          = muma2.RunAsync().Result;
                var namespaces = _kernel.Get <TestsContainer>().CreateMutantTestTree(mutant);
                var meth       = namespaces.Cast <CheckedNode>()
                                 .SelectManyRecursive(n => n.Children, leafsOnly: true).OfType <TestNodeMethod>();

                //   vis.CreateDifferenceListing()
                meth.Count(m => m.State == TestNodeState.Failure).ShouldBeGreaterThan(0);
                //  var storedMutantInfo = muma.StoreMutant(mutant).Result;

                //  RunTestsForMutant(_choices.MutantsTestingOptions, _storedMutantInfo);

                //   CodeWithDifference differenceListing = vis.CreateDifferenceListing(CodeLanguage.CSharp, mutant, result).Result;
                //     differenceListing.LineChanges.Count.ShouldEqual(2);
            }
        }
Beispiel #5
0
        public async Task <IObjectRoot <SessionController> > CreateSession(MethodIdentifier methodIdentifier, List <string> testAssemblies, bool auto)
        {
            _whiteCache.Pause(true);
            try
            {
                AutoCreationController creationController = _autoCreationControllerFactory.Create();
                var choices = await creationController.Run(methodIdentifier, testAssemblies, auto);

                var original = new OriginalCodebase(LoadAssemblies().Result, testAssemblies.ToEmptyIfNull().ToList());
                _log.Info("Created original codebase with assemblies to mutate: " + original.ModulesToMutate.Select(m => m.Module.Name).MakeString());
                return(_sessionFactory.CreateWithBindings(choices, original));
            }
            finally
            {
                _whiteCache.Pause(false);
            }
        }
        public void IntegrationTestMutation()
        {
            var cci = new CciModuleSource(TestProjects.MiscUtil);

            var original = new OriginalCodebase(cci.InList());
            var type     =
                cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Adler32") as NamedTypeDefinition;
            var method  = type.Methods.First(m => m.Name.Value == "ComputeChecksum");
            var choices = new MutationSessionChoices
            {
                Filter = new MutationFilter(
                    new List <TypeIdentifier>(),
                    new MethodIdentifier(method).InList()),
                SelectedOperators = new LOR_LogicalOperatorReplacement().InList <IMutationOperator>(),
            };

            var exec      = new MutationExecutor(new OptionsModel(), choices, null);
            var container = new MutantsContainer(exec, original, new OptionsModel());
            IList <AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive());

            var mutants = assemblies.Cast <CheckedNode>()
                          .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>())
                          .OfType <Mutant>();

            var diff = new CodeDifferenceCreator();
            var vis  = new CodeVisualizer(original, diff);

            foreach (var mutant in mutants)
            {
                var                copy              = new CciModuleSource(TestProjects.MiscUtil);
                MutationResult     result            = exec.ExecuteMutation(mutant, copy).Result;
                CodeWithDifference differenceListing =
                    vis.CreateDifferenceListing(CodeLanguage.CSharp, mutant, result).Result;
                differenceListing.LineChanges.Count.ShouldEqual(2);
            }
        }
        public async Task<IObjectRoot<SessionController>> CreateSession(MethodIdentifier methodIdentifier, List<string> testAssemblies, bool auto)
        {
            _whiteCache.Pause(true);
            try
            {
                AutoCreationController creationController = _autoCreationControllerFactory.Create();
                var choices = await creationController.Run(methodIdentifier, testAssemblies, auto);
                var original = new OriginalCodebase(LoadAssemblies().Result, testAssemblies.ToEmptyIfNull().ToList());
                _log.Info("Created original codebase with assemblies to mutate: "+ original.ModulesToMutate.Select(m => m.Module.Name).MakeString());
                return _sessionFactory.CreateWithBindings(choices, original);
            }
            finally
            {
                _whiteCache.Pause(false);
            }
            

            
        }
Beispiel #8
0
        private IEnumerable <Mutant> SetupMutations(OriginalCodebase original,
                                                    List <FilePathAbsolute> paths, List <string> toMutate,
                                                    List <IMutationOperator> operators, MethodIdentifier method = null)
        {
            var options = new OptionsModel();

            options.OtherParams = "--debugfiles true";

            _kernel.Bind <IProjectClonesManager>().To <ProjectClonesManager>().InSingletonScope();
            _kernel.Bind <ProjectFilesClone>().ToSelf().AndFromFactory();
            _kernel.Bind <FilesManager>().ToSelf().InSingletonScope();
            _kernel.Bind <TestServiceManager>().ToSelf().InSingletonScope();
            _kernel.Bind <XUnitTestService>().ToSelf().InSingletonScope();
            _kernel.Bind <XUnitResultsParser>().ToSelf().InSingletonScope();
            _kernel.Bind <WhiteCache>().ToSelf().AndFromFactory();

            _kernel.Bind <INUnitWrapper>().To <NUnitWrapper>().InSingletonScope();
            _kernel.Bind <OriginalCodebase>().ToConstant(original);
            _kernel.Bind <ICodeDifferenceCreator>().To <CodeDifferenceCreator>().InSingletonScope();
            _kernel.Bind <ICodeVisualizer>().To <CodeVisualizer>().InSingletonScope();
            _kernel.Bind <IMutantsCache>().To <MutantsCache>().InSingletonScope();
            _kernel.Bind <NUnitTestsRunContext>().ToSelf().AndFromFactory();
            _kernel.Bind <XUnitTestsRunContext>().ToSelf().AndFromFactory();
            _kernel.Bind <OptionsModel>().ToConstant(options);
            _kernel.Bind <IMutationExecutor>().To <MutationExecutor>().InSingletonScope();
            _kernel.Bind <TestingMutant>().ToSelf().AndFromFactory();
            _kernel.Bind <TestLoader>().ToSelf().AndFromFactory();

            _kernel.BindMock <IHostEnviromentConnection>(mock =>
            {
                mock.Setup(_ => _.GetProjectAssemblyPaths()).Returns(paths);
                mock.Setup(_ => _.GetTempPath()).Returns(Path.GetTempPath());
            });

            _kernel.Get <ISettingsManager>()["NUnitConsoleDirPath"] = TestProjects.NUnitConsoleDirPath;
            _kernel.Get <ISettingsManager>()["XUnitConsoleDirPath"] = TestProjects.XUnitConsoleDirPath;

            _kernel.Bind <IWhiteSource>().ToConstant(new WhiteDummy(toMutate));

            var testsClone = _kernel.Get <IProjectClonesManager>().CreateClone("Tests");
            var testsTask  = _kernel.Get <TestsLoader>().LoadTests(testsClone.Assemblies.AsStrings().ToList());

            var strategy = new AllTestsSelectStrategy(testsTask);

            var choices = new MutationSessionChoices
            {
                Filter = method == null?MutationFilter.AllowAll() :
                             new MutationFilter(
                                 new List <TypeIdentifier>(),
                                 method.InList()),
                             SelectedOperators = operators,
                             TestAssemblies    = strategy.SelectTests(null).Result
            };

            _kernel.Bind <MutationSessionChoices>().ToConstant(choices);

            var exec      = _kernel.Get <MutationExecutor>();
            var container = new MutantsContainer(exec, original);
            IList <AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive());

            var mutants = assemblies.Cast <CheckedNode>()
                          .SelectManyRecursive(n => n.Children ?? new NotifyingCollection <CheckedNode>())
                          .OfType <Mutant>();//.Take(4);

            return(mutants);
        }
        public void IntegrationTestingMiscUtil()
        {
            var paths = new[] {
                 TestProjects.MiscUtil,
                 TestProjects.MiscUtilTests}.Select(_ => _.ToFilePathAbs()).ToList();

            var cci = new CciModuleSource(TestProjects.MiscUtil);
            var cciTests = new CciModuleSource(TestProjects.MiscUtilTests);

            var toMutate = TestProjects.MiscUtil.InList();
            var original = new OriginalCodebase(new List<CciModuleSource> {cci, cciTests});

            var type = (NamedTypeDefinition)cci.Module.Module.GetAllTypes().Single(t => t.Name.Value == "Range");
            var method = type.Methods.First(m => m.Name.Value == "Contains");

            var oper = new ROR_RelationalOperatorReplacement().InList<IMutationOperator>();

            var mutants = SetupMutations(original, paths, toMutate, oper, new MethodIdentifier(method));

            var vis = _kernel.Get<ICodeVisualizer>();


            var muma = _kernel.Get<MutantMaterializer>();


            IObserver<SessionEventArgs> sub = new ReplaySubject<SessionEventArgs>();
            foreach (var mutant in mutants)
            {
                //  var copy = new CciModuleSource(TestProjects.MiscUtil);
                //    MutationResult result = exec.ExecuteMutation(mutant, copy).Result;
                var muma2 = _kernel.Get<IFactory<TestingMutant>>().CreateWithParams(sub, mutant);


                var r = muma2.RunAsync().Result;
                var namespaces = _kernel.Get<TestsContainer>().CreateMutantTestTree(mutant);
                var meth = namespaces.Cast<CheckedNode>()
                    .SelectManyRecursive(n => n.Children, leafsOnly: true).OfType<TestNodeMethod>();

             //   vis.CreateDifferenceListing()
                meth.Count(m => m.State == TestNodeState.Failure).ShouldBeGreaterThan(0);
                //  var storedMutantInfo = muma.StoreMutant(mutant).Result;

                //  RunTestsForMutant(_choices.MutantsTestingOptions, _storedMutantInfo);

                //   CodeWithDifference differenceListing = vis.CreateDifferenceListing(CodeLanguage.CSharp, mutant, result).Result;
                //     differenceListing.LineChanges.Count.ShouldEqual(2);

            }

        }
        private IEnumerable<Mutant> SetupMutations(OriginalCodebase original, 
            List<FilePathAbsolute> paths, List<string> toMutate, 
            List<IMutationOperator> operators, MethodIdentifier method= null)
        {

            var options = new OptionsModel();
            options.OtherParams = "--debugfiles true";

            _kernel.Bind<IProjectClonesManager>().To<ProjectClonesManager>().InSingletonScope();
            _kernel.Bind<ProjectFilesClone>().ToSelf().AndFromFactory();
            _kernel.Bind<FilesManager>().ToSelf().InSingletonScope();
            _kernel.Bind<TestServiceManager>().ToSelf().InSingletonScope();
            _kernel.Bind<XUnitTestService>().ToSelf().InSingletonScope();
            _kernel.Bind<XUnitResultsParser>().ToSelf().InSingletonScope();
            _kernel.Bind<WhiteCache>().ToSelf().AndFromFactory();

            _kernel.Bind<INUnitWrapper>().To<NUnitWrapper>().InSingletonScope();
            _kernel.Bind<OriginalCodebase>().ToConstant(original);
            _kernel.Bind<ICodeDifferenceCreator>().To<CodeDifferenceCreator>().InSingletonScope();
            _kernel.Bind<ICodeVisualizer>().To<CodeVisualizer>().InSingletonScope();
            _kernel.Bind<IMutantsCache>().To<MutantsCache>().InSingletonScope();
            _kernel.Bind<NUnitTestsRunContext>().ToSelf().AndFromFactory();
            _kernel.Bind<XUnitTestsRunContext>().ToSelf().AndFromFactory();
            _kernel.Bind<OptionsModel>().ToConstant(options);
            _kernel.Bind<IMutationExecutor>().To<MutationExecutor>().InSingletonScope();
            _kernel.Bind<TestingMutant>().ToSelf().AndFromFactory();
            _kernel.Bind<TestLoader>().ToSelf().AndFromFactory();

            _kernel.BindMock<IHostEnviromentConnection>(mock =>
            {
                mock.Setup(_ => _.GetProjectAssemblyPaths()).Returns(paths);
                mock.Setup(_ => _.GetTempPath()).Returns(Path.GetTempPath());
            });

            _kernel.Get<ISettingsManager>()["NUnitConsoleDirPath"] = TestProjects.NUnitConsoleDirPath;
            _kernel.Get<ISettingsManager>()["XUnitConsoleDirPath"] = TestProjects.XUnitConsoleDirPath;

            _kernel.Bind<IWhiteSource>().ToConstant(new WhiteDummy(toMutate));

            var testsClone = _kernel.Get<IProjectClonesManager>().CreateClone("Tests");
            var testsTask = _kernel.Get<TestsLoader>().LoadTests(testsClone.Assemblies.AsStrings().ToList());

            var strategy = new AllTestsSelectStrategy(testsTask);
         
            var choices = new MutationSessionChoices
                          {
                              Filter = method == null ? MutationFilter.AllowAll() :
                                 new MutationFilter(
                                  new List<TypeIdentifier>(),
                                  method.InList()),
                              SelectedOperators = operators,
                              TestAssemblies = strategy.SelectTests(null).Result
                          };
            _kernel.Bind<MutationSessionChoices>().ToConstant(choices);

            var exec = _kernel.Get<MutationExecutor>();
            var container = new MutantsContainer(exec, original);
            IList<AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive());

            var mutants = assemblies.Cast<CheckedNode>()
                .SelectManyRecursive(n => n.Children ?? new NotifyingCollection<CheckedNode>())
                .OfType<Mutant>();//.Take(4);
            return mutants;
        }
        public void IntegrationTestingAutoMapper()
        {
            var paths = new[] {
                 TestProjects.AutoMapper,
                 TestProjects.AutoMapperNet4,
                 TestProjects.AutoMapperTests
            }.Select(_ => _.ToFilePathAbs()).ToList();

            var cci = new CciModuleSource(TestProjects.AutoMapper);
            var cci1 = new CciModuleSource(TestProjects.AutoMapperNet4);
            var cciTests = new CciModuleSource(TestProjects.AutoMapperTests);

            var original = new OriginalCodebase(new List<CciModuleSource> {cci, cci1, cciTests});
            var toMutate = new List<string>{
                    TestProjects.AutoMapper,
                 TestProjects.AutoMapperNet4};

            var oper = new IdentityOperator2().InList<IMutationOperator>();

            var mutants = SetupMutations(original, paths, toMutate, oper);

            var vis = _kernel.Get<ICodeVisualizer>();


            var muma = _kernel.Get<MutantMaterializer>();


            IObserver<SessionEventArgs> sub = new ReplaySubject<SessionEventArgs>();
            foreach (var mutant in mutants)
            {
                //  var copy = new CciModuleSource(TestProjects.MiscUtil);
                //    MutationResult result = exec.ExecuteMutation(mutant, copy).Result;
                var muma2 = _kernel.Get<IFactory<TestingMutant>>().CreateWithParams(sub, mutant);


                var r = muma2.RunAsync().Result;
                var namespaces = _kernel.Get<TestsContainer>().CreateMutantTestTree(mutant);
                var meth = namespaces.Cast<CheckedNode>()
                    .SelectManyRecursive(n => n.Children, leafsOnly: true).OfType<TestNodeMethod>();

                meth.Count(m => m.State == TestNodeState.Failure).ShouldEqual(0);
                //  var storedMutantInfo = muma.StoreMutant(mutant).Result;

                //  RunTestsForMutant(_choices.MutantsTestingOptions, _storedMutantInfo);

                //   CodeWithDifference differenceListing = vis.CreateDifferenceListing(CodeLanguage.CSharp, mutant, result).Result;
                //     differenceListing.LineChanges.Count.ShouldEqual(2);

            }

        }
        public void IntegrationTestMutation()
        {

            var cci = new CciModuleSource(TestProjects.MiscUtil);

            var original = new OriginalCodebase(cci.InList());
            var type =
                cci.Modules.Single().Module.GetAllTypes().Single(t => t.Name.Value == "Adler32") as NamedTypeDefinition;
            var method = type.Methods.First(m => m.Name.Value == "ComputeChecksum");
            var choices = new MutationSessionChoices
                          {
                              Filter = new MutationFilter(
                                  new List<TypeIdentifier>(),
                                  new MethodIdentifier(method).InList()),
                              SelectedOperators = new LOR_LogicalOperatorReplacement().InList<IMutationOperator>(),
                          };

            var exec = new MutationExecutor(new OptionsModel(), choices, null);
            var container = new MutantsContainer(exec, original);
            IList<AssemblyNode> assemblies = container.InitMutantsForOperators(ProgressCounter.Inactive());

            var mutants = assemblies.Cast<CheckedNode>()
                .SelectManyRecursive(n => n.Children ?? new NotifyingCollection<CheckedNode>())
                .OfType<Mutant>();

            var diff = new CodeDifferenceCreator();
            var vis = new CodeVisualizer(original, diff);

            foreach (var mutant in mutants)
            {
                var copy = new CciModuleSource(TestProjects.MiscUtil);
                MutationResult result = exec.ExecuteMutation(mutant, copy).Result;
                CodeWithDifference differenceListing =
                    vis.CreateDifferenceListing(CodeLanguage.CSharp, mutant, result).Result;
                differenceListing.LineChanges.Count.ShouldEqual(2);

            }


        }