Skip to content

Commit

Permalink
Make artifact type comparison case-insensitive (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbumann authored Oct 10, 2023
1 parent 66b2bd8 commit f6883f6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Cake.AzureDevOps.Tests/Cake.AzureDevOps.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Cake.Common" Version="3.0.0" />
<PackageReference Include="Cake.Core" Version="3.0.0" />
<PackageReference Include="Cake.Testing" Version="3.0.0" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.205.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
namespace Cake.AzureDevOps.Tests.Pipelines
{
using System.Collections.Generic;
using System.Linq;
using Cake.AzureDevOps.Pipelines;
using Cake.Common.Build.AzurePipelines.Data;
using Microsoft.TeamFoundation.Build.WebApi;
using Shouldly;
using Xunit;

// ReSharper disable once ClassNeverInstantiated.Global
public sealed class ArtifactResourceExtensionsTests
{
public sealed class TheToAzureDevOpsArtifactResourceExtensionMethod
{
[Fact]
public void Should_Return_The_Correct_AzureDevOpsArtifactResource_For_ArtifactResource()
{
// Given
var artifactResource = new ArtifactResource()
{
Data = "data",
DownloadUrl = "downloadUrl",
Url = "url",
Type = "FilePath",
Properties = new Dictionary<string, string>()
{
{ "foo", "bar" },
},
};

// When
var result = artifactResource.ToAzureDevOpsArtifactResource();

// Then
result.Data.ShouldBe(artifactResource.Data);
result.DownloadUrl.ShouldBe(artifactResource.DownloadUrl);
result.Url.ShouldBe(artifactResource.Url);
result.Type.ShouldBe(AzurePipelinesArtifactType.FilePath);
result.Properties.Count.ShouldBe(1);
result.Properties.Single().Key.ShouldBe(artifactResource.Properties.Single().Key);
result.Properties.Single().Value.ShouldBe(artifactResource.Properties.Single().Value);
}

[Theory]
[InlineData("container", AzurePipelinesArtifactType.Container)]
[InlineData("Container", AzurePipelinesArtifactType.Container)]
[InlineData("FilePath", AzurePipelinesArtifactType.FilePath)]
[InlineData("filepath", AzurePipelinesArtifactType.FilePath)]
[InlineData("GitRef", AzurePipelinesArtifactType.GitRef)]
[InlineData("gitref", AzurePipelinesArtifactType.GitRef)]
[InlineData("TFVCLabel", AzurePipelinesArtifactType.TFVCLabel)]
[InlineData("tfvclabel", AzurePipelinesArtifactType.TFVCLabel)]
[InlineData("VersionControl", AzurePipelinesArtifactType.VersionControl)]
[InlineData("versioncontrol", AzurePipelinesArtifactType.VersionControl)]

public void Should_Return_The_Correct_AzureDevOpsArtifactResource_Type_EnumValue_Independent_The_ArtifactResource_Type_String_Casing(string typeString, AzurePipelinesArtifactType expectedResult)
{
// Given
var artifactResource = new ArtifactResource()
{
Type = typeString,
};

// When
var result = artifactResource.ToAzureDevOpsArtifactResource();

// Then
result.Type.ShouldBe(expectedResult);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static AzureDevOpsArtifactResource ToAzureDevOpsArtifactResource(this Art
{
artifactResource.NotNull(nameof(artifactResource));

if (!Enum.TryParse(artifactResource.Type, out AzurePipelinesArtifactType type))
if (!Enum.TryParse(artifactResource.Type, true, out AzurePipelinesArtifactType type))
{
throw new InvalidOperationException($"Unexpected value for artifact type '{artifactResource.Type}'");
}
Expand Down

0 comments on commit f6883f6

Please sign in to comment.