private IEnumerable <FileContent> GetAdditionalFiles(string code, List <string> excluded)
        {
            yield return(new FileContent {
                Path = UserCodeFilePath, Data = Encoding.UTF8.GetBytes(code)
            });

            var useNUnitLauncher = NUnitTestClasses != null;

            yield return(new FileContent
            {
                Path = CsprojFileName,
                Data = ProjModifier.ModifyCsproj(CsprojFile, ModifyCsproj(excluded, useNUnitLauncher), toolsVersion: BuildEnvironmentOptions.ToolsVersion)
            });

            if (useNUnitLauncher)
            {
                yield return(new FileContent {
                    Path = GetNUnitTestRunnerFilename(), Data = CreateTestLauncherFile()
                });
            }

            foreach (var fileContent in ExerciseStudentZipBuilder.ResolveCsprojLinks(this))
            {
                yield return(fileContent);
            }
        }
示例#2
0
 public void NotChangeFile_OnModify()
 {
     ProjModifier.ModifyCsproj(
         new FileInfo(TestProjectFilename),
         p => ProjModifier.PrepareForChecking(p, "AAA", new string[0]));
     Assert.AreNotEqual("AAA", CreateTestProject().GetProperty("StartupObject"));
 }
示例#3
0
 private static MemoryStream GetFileContentInStudentZip(CsProjectExerciseBlock block, FileInfo file)
 {
     if (!file.Name.Equals(block.CsprojFileName, StringComparison.InvariantCultureIgnoreCase))
     {
         return(null);
     }
     return(ProjModifier.ModifyCsproj(file, proj => ProjModifier.PrepareForStudentZip(proj, block)));
 }
示例#4
0
 private byte[] ReplaceCsproj(FileInfo file)
 {
     if (!file.Name.Equals(CsprojFileName, StringComparison.InvariantCultureIgnoreCase))
     {
         return(null);
     }
     return(ProjModifier.ModifyCsproj(file, ProjModifier.RemoveCheckingFromCsproj));
 }
示例#5
0
        private Action <Project> ModifyCsproj(List <string> excluded, bool addNUnitLauncher)
        {
            return(proj =>
            {
                ProjModifier.PrepareForCheckingUserCode(proj, this, excluded);
                if (addNUnitLauncher)
                {
                    proj.AddItem("Compile", GetNUnitTestRunnerFilename());
                }

                ProjModifier.SetBuildEnvironmentOptions(proj, BuildEnvironmentOptions);
            });
        }
示例#6
0
        public static IEnumerable <FileContent> ResolveCsprojLinks(FileInfo csprojFile, string toolsVersion)
        {
            var project     = new Project(csprojFile.FullName, null, toolsVersion, new ProjectCollection());
            var filesToCopy = ProjModifier.ReplaceLinksWithItemsAndReturnWhatToCopy(project);

            foreach (var fileToCopy in filesToCopy)
            {
                var fullSourcePath = Path.Combine(project.DirectoryPath, fileToCopy.SourceFile);
                yield return(new FileContent {
                    Path = fileToCopy.DestinationFile, Data = File.ReadAllBytes(fullSourcePath)
                });
            }
        }
        public void ReplaceLinksWithItems()
        {
            var project = CreateTestProject();
            var copies  = ProjModifier.ReplaceLinksWithItemsAndReturnWhatToCopy(project);

            copies.Should().HaveCount(1);
            var writer = new StringWriter();

            foreach (var fileToCopy in copies)
            {
                writer.WriteLine("Copy " + fileToCopy.SourceFile + " to " + fileToCopy.DestinationFile);
            }
            project.Save(writer);
            Approvals.Verify(writer.ToString());
            project.Save(Path.Combine(project.DirectoryPath, "res.csproj"));
        }
示例#8
0
        private byte[] GetZipBytesForChecker(string code)
        {
            var           directoryName = Path.Combine(SlideFolderPath.FullName, ExerciseDir);
            List <string> excluded      = (PathsToExcludeForChecker ?? new string[0]).Concat(new[] { "bin/*", "obj/*" }).ToList();
            var           exerciseDir   = new DirectoryInfo(directoryName);

            return(exerciseDir.ToZip(excluded,
                                     new[]
            {
                new FileContent {
                    Path = UserCodeFileName, Data = Encoding.UTF8.GetBytes(code)
                },
                new FileContent {
                    Path = CsprojFileName,
                    Data = ProjModifier.ModifyCsproj(
                        exerciseDir.GetFile(CsprojFileName),
                        p => ProjModifier.PrepareForChecking(p, this, excluded))
                }
            }));
        }
        private void SaveTempZipFileWithFullProject()
        {
            var zipWithFullProj = new FileInfo(Path.Combine(tempSlideFolderPath, "FullProjDir.exercise.zip"));
            var noExcludedFiles = new Func <FileInfo, bool>(_ => false);
            var noExcludedDirs  = new string[0];

            var csProjFile = TestsHelper.ProjExerciseFolder.GetFile(TestsHelper.CsProjFilename);

            new LazilyUpdatingZip(
                TestsHelper.ProjExerciseFolder,
                noExcludedDirs,
                noExcludedFiles,
                ResolveCsprojLink,
                ExerciseStudentZipBuilder.ResolveCsprojLinks(csProjFile, CsProjectExerciseBlock.BuildingToolsVersion),
                zipWithFullProj)
            .UpdateZip();

            byte[] ResolveCsprojLink(FileInfo file)
            {
                return(file.Name.Equals(exerciseBlock.CsprojFileName) ? ProjModifier.ModifyCsproj(file, ProjModifier.ReplaceLinksWithItems) : null);
            }
        }
示例#10
0
        private IEnumerable <FileContent> GetAdditionalFiles(List <string> excluded)
        {
            var useNUnitLauncher = NUnitTestClasses != null;

            using (var stream = ProjModifier.ModifyCsproj(CsprojFile, ModifyCsproj(excluded, useNUnitLauncher), toolsVersion: BuildEnvironmentOptions.ToolsVersion))
                yield return new FileContent
                       {
                           Path = CsprojFileName,
                           Data = stream.ToArray()
                       };

            if (useNUnitLauncher)
            {
                yield return(new FileContent {
                    Path = GetNUnitTestRunnerFilename(), Data = CreateTestLauncherFile()
                });
            }

            foreach (var fileContent in ExerciseStudentZipBuilder.ResolveCsprojLinks(this))
            {
                yield return(fileContent);
            }
        }
示例#11
0
        public static IEnumerable <FileContent> ResolveCsprojLinks(FileInfo csprojFile, string toolsVersion)
        {
            MsBuildLocationHelper.InitPathToMsBuild();
            return(FuncUtils.Using(
                       new ProjectCollection(),
                       projectCollection =>
            {
                return Body();

                IEnumerable <FileContent> Body()
                {
                    var project = new Project(csprojFile.FullName, null, toolsVersion, projectCollection);
                    var filesToCopy = ProjModifier.ReplaceLinksWithItemsAndReturnWhatToCopy(project);
                    foreach (var fileToCopy in filesToCopy)
                    {
                        var fullSourcePath = Path.Combine(project.DirectoryPath, fileToCopy.SourceFile);
                        yield return new FileContent {
                            Path = fileToCopy.DestinationFile, Data = File.ReadAllBytes(fullSourcePath)
                        };
                    }
                }
            },
                       projectCollection => projectCollection.UnloadAllProjects()));
        }