Ejemplo n.º 1
0
        public async void LoadCode(CodeLanguage selectedLanguage)
        {
            _viewModel.IsCodeLoading = true;
            _viewModel.ClearCode();

            var mutant = _currentMutant;

            if (mutant != null)
            {
                MutationResult mutationResult = await _mutantsCache.GetMutatedModulesAsync(mutant);

                CodeWithDifference diff = await _codeVisualizer.CreateDifferenceListing(selectedLanguage,
                                                                                        mutant, mutationResult);

                if (diff != null)
                {
                    _viewModel.PresentCode(diff);
                    _viewModel.IsCodeLoading = false;
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <XElement> CreateCodeDifferenceListings(List <Mutant> mutants, ProgressCounter progress, CancellationToken token)
        {
            var list = new List <XElement>();

            foreach (var mutant in mutants)
            {
                progressAction(progress, token);
                var mutresult = await _mutantsCache.GetMutatedModulesAsync(mutant);

                var diff = await _codeVisualizer.CreateDifferenceListing(CodeLanguage.CSharp,
                                                                         mutant, mutresult);

                var el = new XElement("MutantCodeListing",
                                      new XAttribute("MutantId", mutant.Id),

                                      new XElement("Code",
                                                   Environment.NewLine + diff.Code));
                list.Add(el);
            }
            return(new XElement("CodeDifferenceListings", list));
        }
Ejemplo n.º 3
0
        public async Task <StoredMutantInfo> StoreMutant(Mutant mutant)
        {
            mutant.State = MutantResultState.Creating;

            var mutationResult = await _mutantsCache.GetMutatedModulesAsync(mutant);

            mutant.State = MutantResultState.Writing;

            var clone = await _clonesManager.CreateCloneAsync("InitTestEnvironment");

            var info = new StoredMutantInfo(clone);


            if (mutationResult.MutatedModules != null)
            {
                //AKB

                /*foreach (ICciModuleSource mutatedModule in mutationResult.MutatedModules)
                 * {*/
                var singleMutated = mutationResult.MutatedModules.Modules.SingleOrDefault();
                if (singleMutated != null)
                {
                    //TODO: remove: assemblyDefinition.Name.Name + ".dll", use factual original file name
                    string file = Path.Combine(info.Directory, singleMutated.Name + ".dll");
                    //
                    //                    var memory = mutationResult.MutatedModules.WriteToStream(singleMutated);
                    //                    // _mutantsCache.Release(mutationResult);
                    //
                    //                    using (FileStream peStream = File.Create(file))
                    //                    {
                    //                        await memory.CopyToAsync(peStream);
                    //                    }
                    using (FileStream peStream = File.Create(file))
                    {
                        mutationResult.MutatedModules.WriteToStream(singleMutated, peStream, file);

                        //  await memory.CopyToAsync(peStream);
                    }

                    info.AssembliesPaths.Add(file);
                }

                var otherModules = _originalCodebase.Modules
                                   .Where(_ => singleMutated == null || _.Module.Name != singleMutated.Name);

                foreach (var otherModule in otherModules)
                {
                    string file = Path.Combine(info.Directory, otherModule.Module.Name + ".dll");
                    info.AssembliesPaths.Add(file);
                }
                //}
            }
            else
            {
                foreach (var cciModuleSource in mutationResult.Old)
                {
                    var module = cciModuleSource.Modules.Single();
                    //TODO: remove: assemblyDefinition.Name.Name + ".dll", use factual original file name
                    string file = Path.Combine(info.Directory, module.Name + ".dll");


                    // _mutantsCache.Release(mutationResult);

                    using (FileStream peStream = File.Create(file))
                    {
                        cciModuleSource.WriteToStream(module, peStream, file);
                        //  await memory.CopyToAsync(peStream);
                    }

                    info.AssembliesPaths.Add(file);
                }
            }


            return(info);
        }