Esempio n. 1
0
            public void Should_Publish_Test_Results()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();
                var data    = new TFBuildPublishTestResultsData
                {
                    Configuration         = "Debug",
                    MergeTestResults      = true,
                    Platform              = "x86",
                    PublishRunAttachments = true,
                    TestRunner            = TFTestRunnerType.XUnit,
                    TestRunTitle          = "Cake Test Run 1 [master]",
                    TestResultsFiles      = new string[]
                    {
                        FilePath.FromString("./artifacts/resultsXUnit.trx").ToString(),
                        FilePath.FromString("./artifacts/resultsJs.trx").ToString()
                    }
                };

                // When
                service.Commands.PublishTestResults(data);

                // Then
                const string expected = @"##vso[results.publish type=XUnit;mergeResults=true;platform=x86;config=Debug;runTitle='Cake Test Run 1 [master]';publishRunAttachments=true;resultFiles=C:\build\CAKE-CAKE-JOB1\artifacts\resultsXUnit.trx,C:\build\CAKE-CAKE-JOB1\artifacts\resultsJs.trx;]";
                var          actual   = fixture.Log.Entries.FirstOrDefault();

                Assert.Equal(expected, actual?.Message);
            }
Esempio n. 2
0
            public void Should_Publish_Test_Results_If_File_Path_Is_Absolute()
            {
                // Given
                var fixture = new TFBuildFixture();

                fixture.Environment.WorkingDirectory.Returns("/build/CAKE-CAKE-JOB1");
                fixture.Environment.Platform.Family.Returns(PlatformFamily.OSX);
                var service = fixture.CreateTFBuildService();
                var data    = new TFBuildPublishTestResultsData
                {
                    Configuration         = "Debug",
                    MergeTestResults      = true,
                    Platform              = "x86",
                    PublishRunAttachments = true,
                    TestRunner            = TFTestRunnerType.XUnit,
                    TestRunTitle          = "Cake Test Run 1 [master]",
                    TestResultsFiles      = new FilePath[]
                    {
                        "/build/CAKE-CAKE-JOB1/artifacts/resultsXUnit.trx",
                        "/build/CAKE-CAKE-JOB1/artifacts/resultsJs.trx"
                    }
                };

                // When
                service.Commands.PublishTestResults(data);

                // Then
                const string expected = @"##vso[results.publish type=XUnit;mergeResults=true;platform=x86;config=Debug;runTitle='Cake Test Run 1 [master]';publishRunAttachments=true;resultFiles=/build/CAKE-CAKE-JOB1/artifacts/resultsXUnit.trx,/build/CAKE-CAKE-JOB1/artifacts/resultsJs.trx;]";
                var          actual   = fixture.Log.Entries.FirstOrDefault();

                Assert.Equal(expected.Replace('/', System.IO.Path.DirectorySeparatorChar), actual?.Message);
            }
Esempio n. 3
0
            public void Should_Publish_Test_Results_If_File_Path_Is_Absolute_Windows()
            {
                const string expected = @"##vso[results.publish type=XUnit;mergeResults=true;platform=x86;config=Debug;runTitle='Cake Test Run 1 [master]';publishRunAttachments=true;resultFiles=C:\build\CAKE-CAKE-JOB1\artifacts\resultsXUnit.trx,C:\build\CAKE-CAKE-JOB1\artifacts\resultsJs.trx;]";

                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();
                var data    = new TFBuildPublishTestResultsData
                {
                    Configuration         = "Debug",
                    MergeTestResults      = true,
                    Platform              = "x86",
                    PublishRunAttachments = true,
                    TestRunner            = TFTestRunnerType.XUnit,
                    TestRunTitle          = "Cake Test Run 1 [master]",
                    TestResultsFiles      = new FilePath[]
                    {
                        "C:\\build\\CAKE-CAKE-JOB1\\artifacts\\resultsXUnit.trx",
                        "C:\\build\\CAKE-CAKE-JOB1\\artifacts\\resultsJs.trx"
                    }
                };

                // When
                service.Commands.PublishTestResults(data);

                // Then
                Assert.Equal(expected.Replace('/', System.IO.Path.DirectorySeparatorChar), fixture.Writer.Entries.FirstOrDefault());
            }
Esempio n. 4
0
            public void Should_Not_Be_Null()
            {
                // Given
                var fixture = new TFBuildFixture();

                // When
                var service = fixture.CreateTFBuildService();

                // Then
                Assert.NotNull(service.Commands);
            }
Esempio n. 5
0
            public void Should_Log_Warning_Message(string msg)
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.WriteWarning(msg);

                // Then
                Assert.Contains(fixture.Writer.Entries, m => m == $"##vso[task.logissue type=warning;]{msg}");
            }
Esempio n. 6
0
            public void Should_Return_False_If_Not_Running_On_AzurePipelinesHosted()
            {
                // Given
                var fixture = new TFBuildFixture();
                var tfBuild = fixture.CreateTFBuildService();

                // When
                var result = tfBuild.IsRunningOnAzurePipelinesHosted;

                // Then
                Assert.False(result);
            }
Esempio n. 7
0
            public void Should_Set_Current_Progress()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.SetProgress(75, "Testing Provider");

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[task.setprogress value=75;]Testing Provider");
            }
Esempio n. 8
0
            public void Should_Log_Error_Message(string msg)
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.WriteError(msg);

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[task.logissue type=error;]{msg}");
            }
Esempio n. 9
0
            public void Should_Set_Secret_Variable()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.SetSecretVariable("Secret Variable", "Secret Value");

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == "##vso[task.setvariable variable=Secret Variable;issecret=true;]Secret Value");
            }
Esempio n. 10
0
            public void Should_Complete_Current_Task()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.CompleteCurrentTask();

                // Then
                Assert.Contains(fixture.Writer.Entries, m => m == $"##vso[task.complete ]DONE");
            }
Esempio n. 11
0
            public void UploadArtifactDirectory_Should_Throw_If_ArtifactName_Is_Null()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                var result = Record.Exception(() => service.Commands.UploadArtifactDirectory("./artifacts/Packages", null));

                // Then
                AssertEx.IsArgumentNullException(result, "artifactName");
            }
Esempio n. 12
0
            public void Should_Update_Build_Number()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.UpdateBuildNumber("CIBuild_1");

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == "##vso[build.updatebuildnumber ]CIBuild_1");
            }
Esempio n. 13
0
            public void Should_Return_False_If_Not_Running_On_TFS()
            {
                // Given
                var fixture = new TFBuildFixture();
                var vsts    = fixture.CreateTFBuildService();

                // When
                var result = vsts.IsRunningOnTFS;

                // Then
                Assert.False(result);
            }
Esempio n. 14
0
            public void Should_Complete_Current_Task_With_Status()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.CompleteCurrentTask(TFBuildTaskResult.Failed);

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[task.complete result=Failed;]DONE");
            }
Esempio n. 15
0
            public void Should_Add_Build_Tag()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.AddBuildTag("Stable");

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == "##vso[build.addbuildtag ]Stable");
            }
Esempio n. 16
0
            public void Should_Return_Non_Null_Reference()
            {
                // Given
                var fixture = new TFBuildFixture();
                var vsts    = fixture.CreateTFBuildService();

                // When
                var result = vsts.Environment;

                // Then
                Assert.NotNull(result);
            }
Esempio n. 17
0
            public void Should_Set_Variable()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.SetVariable("varname", "VarValue");

                // Then
                Assert.Contains(fixture.Log.Entries,
                                m => m.Message == $"##vso[task.setvariable variable=varname;]VarValue");
            }
Esempio n. 18
0
            public void Should_Create_New_Record()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                var guid = service.Commands.CreateNewRecord("New record", "build", 1);

                // Then
                Assert.NotNull(guid);
                Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[task.logdetail id={guid.ToString()};name=New record;type=build;order=1;]create new timeline record");
            }
Esempio n. 19
0
            public void Should_Upload_Task_Summary()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();
                var path    = FilePath.FromString("./summary.md").MakeAbsolute(fixture.Environment);

                // When
                service.Commands.UploadTaskSummary("./summary.md");

                // Then
                Assert.Contains(fixture.Writer.Entries, m => m == $"##vso[task.uploadsummary ]{path}");
            }
Esempio n. 20
0
            public void Should_Link_Build_Artifacts(string name, TFBuildArtifactType type, string location)
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.LinkArtifact(name, type, location);

                // Then
                Assert.Contains(fixture.Log.Entries,
                                m => m.Message == $"##vso[artifact.associate artifactname={name};type={type};]{location}");
            }
Esempio n. 21
0
            public void Should_Upload_Task_Log()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();
                var path    = FilePath.FromString("./logs/task.log").MakeAbsolute(fixture.Environment);

                // When
                service.Commands.UploadTaskLogFile("./logs/task.log");

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[task.uploadfile ]{path}");
            }
Esempio n. 22
0
            public void Should_Upload_Directory_As_Container_Artifact()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();
                var path    = DirectoryPath.FromString("./artifacts/Packages").MakeAbsolute(fixture.Environment).FullPath;

                // When
                service.Commands.UploadArtifactDirectory("./artifacts/Packages", "NuGet");

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[artifact.upload containerfolder=NuGet;artifactname=NuGet;]{path}");
            }
Esempio n. 23
0
            public void Should_Upload_Build_Log()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();
                var path    = FilePath.FromString("./dist/buildlog.txt").MakeAbsolute(fixture.Environment).FullPath;

                // When
                service.Commands.UploadBuildLogFile("./dist/buildlog.txt");

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[build.uploadlog ]{path}");
            }
Esempio n. 24
0
            public void Should_Upload_To_Container_Artifact()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();
                var path    = FilePath.FromString("./artifacts/results.trx").MakeAbsolute(fixture.Environment).FullPath;

                // When
                service.Commands.UploadArtifact("tests", "./artifacts/results.trx", "Test Results");

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[artifact.upload containerfolder=tests;artifactname=Test Results;]{path}");
            }
Esempio n. 25
0
            public void Should_Return_True_If_Running_On_AzurePipelines()
            {
                // Given
                var fixture = new TFBuildFixture();

                fixture.IsRunningOnAzurePipelines();
                var tfBuild = fixture.CreateTFBuildService();

                // When
                var result = tfBuild.IsRunningOnAzurePipelines;

                // Then
                Assert.True(result);
            }
Esempio n. 26
0
            public void Should_Return_False_If_Not_Running_On_VSTS()
            {
                // Given
                var fixture = new TFBuildFixture();
                var tfBuild = fixture.CreateTFBuildService();

                // When
#pragma warning disable 618
                var result = tfBuild.IsRunningOnVSTS;
#pragma warning restore 618

                // Then
                Assert.False(result);
            }
Esempio n. 27
0
            public void Should_Return_True_If_Running_On_VSTS()
            {
                // Given
                var fixture = new TFBuildFixture();

                fixture.IsRunningOnVSTS();
                var vsts = fixture.CreateTFBuildService();

                // When
                var result = vsts.IsRunningOnVSTS;

                // Then
                Assert.True(result);
            }
Esempio n. 28
0
            public void Should_Return_True_If_Running_On_AzurePipelinesExtraAgent(string agentName)
            {
                // Given
                var fixture = new TFBuildFixture();

                fixture.IsRunningOnAzurePipelinesHosted(agentName);
                var tfBuild = fixture.CreateTFBuildService();

                // When
                var result = tfBuild.IsRunningOnAzurePipelinesHosted;

                // Then
                Assert.True(result);
            }
Esempio n. 29
0
            public void Should_Upload_To_Container()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();
                var path    = FilePath.FromString("./dist/package.nupkg").MakeAbsolute(fixture.Environment).FullPath;

                // When
                service.Commands.UploadArtifact("packages", "./dist/package.nupkg");

                // Then
                Assert.Contains(fixture.Log.Entries,
                                m => m.Message == $"##vso[artifact.upload containerfolder=packages;]{path}");
            }
Esempio n. 30
0
            public void Should_Log_Warning_Message_With_Data()
            {
                // Given
                var fixture = new TFBuildFixture();
                var service = fixture.CreateTFBuildService();

                // When
                service.Commands.WriteWarning("build warning", new TFBuildMessageData
                {
                    SourcePath   = "./code file.cs",
                    LineNumber   = 5,
                    ColumnNumber = 12,
                    ErrorCode    = 9
                });

                // Then
                Assert.Contains(fixture.Log.Entries, m => m.Message == $"##vso[task.logissue sourcepath=./code file.cs;linenumber=5;columnnumber=12;code=9;type=warning;]build warning");
            }