Пример #1
0
        public void TestParse2()
        {
            var path = TestPath.Get(@"Parser/MissingTargetsAttribute.csproj");

            new Action(() => _parser.Parse(path))
            .ShouldThrow <ParseException>()
            .WithMessage("error  : The required attribute \"Name\" is empty or missing from the element <Target>.");
        }
Пример #2
0
        private void CleanOutputPath()
        {
            foreach (string projectDirectory in ProjectDirectories)
            {
                string directory = TestPath.Get(Path.Combine(@"Build.SystemTest\TestData\CSharp", projectDirectory));

                Clean(Path.Combine(directory, "bin", "debug"));
                Clean(Path.Combine(directory, "bin", "release"));
                Clean(Path.Combine(directory, "obj", "debug"));
                Clean(Path.Combine(directory, "obj", "release"));
            }
        }
Пример #3
0
        protected int Run(string relativeFileName, out string output)
        {
            string fullPath         = TestPath.Get(Path.Combine("Build.SystemTest", relativeFileName));
            string workingDirectory = Path.GetDirectory(fullPath);

            Console.WriteLine("Executing '{0}'", fullPath);

            int exitCode = ProcessEx.Run(fullPath,
                                         workingDirectory,
                                         new ArgumentBuilder(),
                                         out output);

            return(exitCode);
        }
Пример #4
0
        private void Clean()
        {
            var arguments = new Arguments
            {
                InputFile = TestPath.Get(Path.Combine(@"Build.SystemTest\Projects", ProjectFilePath)),
                Targets   = { Targets.Clean },
                Verbosity = Verbosity.Normal
            };

            using (var engine = new BuildEngine.BuildEngine(arguments))
            {
                new Action(() => engine.Execute())
                .ShouldNotThrow("Because cleaning this project should succeed");
            }
        }
Пример #5
0
        public void TestEvaluateProject3()
        {
            var fname       = TestPath.Get(@"Build.Test\Build.Test.csproj");
            var project     = new ProjectParser(new FileSystem()).Parse(fname);
            var envirnoment = new BuildEnvironment();

            _engine.Evaluate(project, envirnoment);

            var fullPath  = Path.Normalize(Path.Combine(Directory.GetCurrentDirectory(), fname));
            var directory = Path.GetDirectory(fullPath);

            envirnoment.Properties[Properties.MSBuildProjectDirectory].Should().Be(directory);
            envirnoment.Properties[Properties.MSBuildProjectDirectoryNoRoot].Should().Be(directory.Remove(0, 3));
            envirnoment.Properties[Properties.MSBuildProjectExtension].Should().Be(".csproj");
            envirnoment.Properties[Properties.MSBuildProjectFile].Should().Be("Build.Test.csproj");
            envirnoment.Properties[Properties.MSBuildProjectFullPath].Should().Be(fullPath);
            envirnoment.Properties[Properties.MSBuildProjectName].Should().Be("Build.Test");
        }
Пример #6
0
        private void Build()
        {
            var arguments = new Arguments
            {
                InputFile = TestPath.Get(Path.Combine(@"Build.SystemTest\Projects", ProjectFilePath)),
                Targets   = { Targets.Build },
                Verbosity = Verbosity.Minimal
            };

            using (var engine = new BuildEngine.BuildEngine(arguments))
            {
                new Action(() => engine.Execute())
                .ShouldNotThrow("Because building this project should succeed");

                BuildLog log = engine.Log;
                log.Warnings.Should().BeEmpty("Because no warnings should've been encountered during the build process");
                log.Errors.Should().BeEmpty("Because no errors shoud've been encountered during the build process");
            }
        }
Пример #7
0
        protected override void PostBuildChecks()
        {
            var source = TestPath.Get(@"Build.SystemTest\Projects\EmbeddedResource\bin\Debug\EmbeddedResource.dll");
            var dest   = Path.Combine(Path.GetDirectory(source), "tmp.dll");

            File.Copy(source, dest, true);

            var assembly  = Assembly.LoadFile(dest);
            var resources = assembly.GetManifestResourceNames();

            resources.Should().BeEquivalentTo(new[]
            {
                "EmbeddedResource.HelloWorld.txt",
                "EmbeddedResource.SomeFolder.SomeDataFile.xml",
                "EmbeddedResource.SomeFolder.Some File With Spaces.xml"
            });

            ReadResource(assembly, "EmbeddedResource.HelloWorld.txt").Should().Be("Hello World!");
            ReadResource(assembly, "EmbeddedResource.SomeFolder.SomeDataFile.xml").Should().Be("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
            ReadResource(assembly, "EmbeddedResource.SomeFolder.Some File With Spaces.xml").Should().Be("<?xml version=\"1.0\" encoding=\"utf-8\" ?> <importantdata value=\"42\" />");
        }
Пример #8
0
        private void Clean(string relativeFolderName)
        {
            if (relativeFolderName.Contains(".."))
            {
                throw new Exception();
            }

            string folderPath = Path.Normalize(TestPath.Get(relativeFolderName));

            if (!Directory.Exists(folderPath))
            {
                return;
            }

            Console.WriteLine("Cleaning '{0}'", folderPath);
            IEnumerable <string> files = Directory.EnumerateFiles(folderPath, "*.*");

            foreach (string file in files)
            {
                File.Delete(file);
            }
        }
Пример #9
0
        public void TestBuild()
        {
            Build();

            foreach (string file in ExpectedOutputFiles)
            {
                string path = TestPath.Get(Path.Combine(@"Build.SystemTest\Projects", file));
                File.Exists(path).Should().BeTrue(
                    "because the file '{0}' should've been created during the build process",
                    path);
            }

            PostBuildChecks();

            Clean();

            foreach (string file in ExpectedOutputFiles)
            {
                string path = TestPath.Get(Path.Combine(@"Build.SystemTest\Projects", file));
                File.Exists(path).Should().BeFalse(
                    "because the file '{0}' should've been deleted during the clean process",
                    path);
            }
        }
Пример #10
0
        public void TestParse1()
        {
            var path    = TestPath.Get(@"Build.Test/Parser/Build.Test.csproj");
            var project = _parser.Parse(path);

            project.Should().NotBeNull();
            project.Filename.Should().Be(path);
            project.Properties.Should().NotBeNull();
            project.Properties.Count.Should().Be(3);

            var group = project.Properties[0];

            group.Should().NotBeNull();
            group.Condition.Should().BeNull();
            group.Count.Should().Be(9);
            group[0].Should().Be(new Property(Properties.Configuration, "Debug", " '$(Configuration)' == '' "));
            group[1].Should().Be(new Property(Properties.Platform, "AnyCPU", " '$(Platform)' == '' "));
            group[2].Should().Be(new Property(Properties.ProjectGuid, "{34B3464E-CBE5-4410-9052-3AB2E720BACF}"));
            group[3].Should().Be(new Property(Properties.OutputType, "Library"));
            group[4].Should().Be(new Property(Properties.AppDesignerFolder, "Properties"));
            group[5].Should().Be(new Property(Properties.RootNamespace, "Build.Test"));
            group[6].Should().Be(new Property(Properties.AssemblyName, "Build.Test"));
            group[7].Should().Be(new Property(Properties.TargetFrameworkVersion, "v4.5"));
            group[8].Should().Be(new Property(Properties.FileAlignment, "512"));

            group = project.Properties[1];
            group.Should().NotBeNull();
            group.Condition.Should().Be(" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ");
            group.Count.Should().Be(7);
            group[0].Should().Be(new Property(Properties.DebugSymbols, "true"));
            group[1].Should().Be(new Property(Properties.DebugType, "full"));
            group[2].Should().Be(new Property(Properties.Optimize, "false"));
            group[3].Should().Be(new Property(Properties.OutputPath, @"bin\Debug\"));
            group[4].Should().Be(new Property(Properties.DefineConstants, "DEBUG;TRACE"));
            group[5].Should().Be(new Property(Properties.ErrorReport, "prompt"));
            group[6].Should().Be(new Property(Properties.WarningLevel, "4"));

            group = project.Properties[2];
            group.Should().NotBeNull();
            group.Condition.Should().Be(" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ");
            group.Count.Should().Be(6);
            group[0].Should().Be(new Property(Properties.DebugType, "pdbonly"));
            group[1].Should().Be(new Property(Properties.Optimize, "true"));
            group[2].Should().Be(new Property(Properties.OutputPath, @"bin\Release\"));
            group[3].Should().Be(new Property(Properties.DefineConstants, "TRACE"));
            group[4].Should().Be(new Property(Properties.ErrorReport, "prompt"));
            group[5].Should().Be(new Property(Properties.WarningLevel, "4"));

            var itemGroups = project.ItemGroups;

            itemGroups.Should().NotBeNull();
            itemGroups.Count.Should().Be(4);

            var items = itemGroups[0];

            items.Should().NotBeNull();
            items.Condition.Should().BeNull();
            items.Count.Should().Be(10);
            items[0].Should()
            .Be(new ProjectItem(Items.Reference, "FluentAssertions",
                                metadata:
                                new List <Metadata>
            {
                new Metadata(Metadatas.HintPath,
                             @"..\packages\FluentAssertions.4.0.0\lib\net45\FluentAssertions.dll")
            }));
            items[1].Should().Be(new ProjectItem(Items.Reference, "FluentAssertions.Core",
                                                 metadata: new List <Metadata>
            {
                new Metadata(Metadatas.HintPath, @"..\packages\FluentAssertions.4.0.0\lib\net45\FluentAssertions.Core.dll")
            }));
            items[2].Should().Be(new ProjectItem(Items.Reference, "nunit.framework",
                                                 metadata: new List <Metadata>
            {
                new Metadata(Metadatas.HintPath, @"..\packages\NUnit.2.6.4\lib\nunit.framework.dll")
            }));
            items[3].Should().Be(new ProjectItem(Items.Reference, "System"));
            items[4].Should().Be(new ProjectItem(Items.Reference, "System.Core"));
            items[5].Should().Be(new ProjectItem(Items.Reference, "System.Xml.Linq"));
            items[6].Should().Be(new ProjectItem(Items.Reference, "System.Data.DataSetExtensions"));
            items[7].Should().Be(new ProjectItem(Items.Reference, "Microsoft.CSharp"));
            items[8].Should().Be(new ProjectItem(Items.Reference, "System.Data"));
            items[9].Should().Be(new ProjectItem(Items.Reference, "System.Xml"));

            items = itemGroups[1];
            items.Should().NotBeNull();
            items.Condition.Should().BeNull();
            items.Count.Should().Be(8);
            items[0].Should().Be(new ProjectItem(Items.Compile, @"BusinessLogic\ExpressionEngine\BinaryExpressionTest.cs"));
            items[1].Should().Be(new ProjectItem(Items.Compile, @"BusinessLogic\ExpressionEngine\ExpressionEngineParsingTest.cs"));
            items[2].Should().Be(new ProjectItem(Items.Compile, @"BusinessLogic\ExpressionEngine\ExpressionEngineEvaluationTest.cs"));
            items[3].Should().Be(new ProjectItem(Items.Compile, @"BusinessLogic\ExpressionEngine\TokenizerTest.cs"));
            items[4].Should().Be(new ProjectItem(Items.Compile, @"BusinessLogic\ExpressionEngine\UnaryExpressionTest.cs"));
            items[5].Should().Be(new ProjectItem(Items.Compile, @"BusinessLogic\PathTest.cs"));
            items[6].Should().Be(new ProjectItem(Items.Compile, @"Class1.cs"));
            items[7].Should().Be(new ProjectItem(Items.Compile, @"Properties\AssemblyInfo.cs"));

            items = itemGroups[2];
            items.Should().NotBeNull();
            items.Condition.Should().BeNull();
            items.Count.Should().Be(2);
            items[0].Should().Be(new ProjectItem(Items.Folder, @"BusinessLogic\BuildEngine\"));
            items[1].Should().Be(new ProjectItem(Items.Folder, @"BusinessLogic\Parser\"));

            items = itemGroups[3];
            items.Should().NotBeNull();
            items.Condition.Should().BeNull();
            items.Count.Should().Be(1);
            items[0].Should().Be(new ProjectItem(Items.ProjectReference, @"..\Build\Build.csproj",
                                                 metadata: new List <Metadata>
            {
                new Metadata("Project", "{63F3A0B5-909C-43C5-8B79-CEA032DFE4F1}"),
                new Metadata("Name", "Build")
            }));
        }
Пример #11
0
        protected bool FileExists(string relativeFilePath)
        {
            string path = TestPath.Get(relativeFilePath);

            return(File.Exists(path));
        }