Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Resolving conflicts related to #1644 .
  • Loading branch information
stazz authored and asbjornu committed May 8, 2019
commit 66c1435320b351341db3291cd4d0ada038c03e80
10 changes: 4 additions & 6 deletions src/GitVersionTask.Tests/GetVersionTaskTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Linq;
using System.Linq;
using GitVersion;
using GitVersionTask;
using Microsoft.Build.Framework;
using NUnit.Framework;
using Shouldly;

Expand All @@ -11,13 +10,12 @@ public class GetVersionTaskTests : TestBase
[Test]
public void OutputsShouldMatchVariableProvider()
{
var taskProperties = typeof(GetVersion)
var taskProperties = typeof( GetVersion.Output )
.GetProperties()
.Where(p => p.GetCustomAttributes(typeof(OutputAttribute), false).Any())
.Select(p => p.Name);
.Select( p => p.Name );

var variablesProperties = VersionVariables.AvailableVariables;

taskProperties.ShouldBe(variablesProperties, ignoreOrder: true);
taskProperties.ShouldBe( variablesProperties, ignoreOrder: true );
}
}
1 change: 0 additions & 1 deletion src/GitVersionTask.Tests/GitVersionTask.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<PackageReference Include="NUnit" Version="3.11.0"></PackageReference>
<packagereference Include="NUnit3TestAdapter" Version="3.13.0"></packagereference>
<PackageReference Include="Shouldly" Version="3.0.2"></PackageReference>
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.0.461" />
</ItemGroup>
<ItemGroup>
<Content Include="Approved\**\*.txt" />
Expand Down
128 changes: 63 additions & 65 deletions src/GitVersionTask.Tests/InvalidFileCheckerTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.IO;
using GitVersion;
using GitVersionTask.Tests.Mocks;
using Microsoft.Build.Framework;
using NUnit.Framework;

[TestFixture]
Expand All @@ -14,207 +12,207 @@ public class InvalidFileCheckerTests : TestBase
[SetUp]
public void CreateTemporaryProject()
{
projectDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
projectFile = Path.Combine(projectDirectory, "Fake.csproj");
projectDirectory = Path.Combine( Path.GetTempPath(), Guid.NewGuid().ToString() );
projectFile = Path.Combine( projectDirectory, "Fake.csproj" );

Directory.CreateDirectory(projectDirectory);
Directory.CreateDirectory( projectDirectory );

File.Create(projectFile).Close();
File.Create( projectFile ).Close();
}

[TearDown]
public void Cleanup()
{
Directory.Delete(projectDirectory, true);
Directory.Delete( projectDirectory, true );
}

[Test]
public void VerifyIgnoreNonAssemblyInfoFile()
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "SomeOtherFile.cs")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "SomeOtherFile.cs" ) ) )
{
writer.Write(@"
writer.Write( @"
using System;
using System.Reflection;

[assembly: AssemblyVersion(""1.0.0.0"")]
");
" );
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "SomeOtherFile.cs" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles( new[] { "SomeOtherFile.cs" }, projectFile );
}

[Test]
public void VerifyAttributeFoundCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System.Reflection.AssemblyVersion")]string attribute)
public void VerifyAttributeFoundCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System.Reflection.AssemblyVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
writer.Write(@"
writer.Write( @"
using System;
using System.Reflection;

[assembly:{0}(""1.0.0.0"")]
", attribute);
", attribute );
}

var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile), attribute);
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs"));
var ex = Assert.Throws<WarningException>( () => InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.cs" }, projectFile ), attribute );
Assert.That( ex.Message, Is.EqualTo( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs" ) );
}

[Test]
public void VerifyUnformattedAttributeFoundCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System . Reflection . AssemblyVersion")]string attribute)
public void VerifyUnformattedAttributeFoundCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System . Reflection . AssemblyVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
writer.Write(@"
writer.Write( @"
using System;
using System.Reflection;

[ assembly :
{0} ( ""1.0.0.0"")]
", attribute);
", attribute );
}

var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile), attribute);
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs"));
var ex = Assert.Throws<WarningException>( () => InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.cs" }, projectFile ), attribute );
Assert.That( ex.Message, Is.EqualTo( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.cs" ) );
}

[Test]
public void VerifyCommentWorksCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
public void VerifyCommentWorksCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
writer.Write(@"
writer.Write( @"
using System;
using System.Reflection;

//[assembly: {0}(""1.0.0.0"")]
", attribute);
", attribute );
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.cs" }, projectFile );
}

[Test]
public void VerifyStringWorksCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
public void VerifyStringWorksCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
writer.Write(@"
writer.Write( @"
using System;
using System.Reflection;

public class Temp
{{
static const string Foo = ""[assembly: {0}(""""1.0.0.0"""")]"";
}}
", attribute);
", attribute );
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.cs" }, projectFile );
}

[Test]
public void VerifyIdentifierWorksCSharp([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
public void VerifyIdentifierWorksCSharp( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.cs")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.cs" ) ) )
{
writer.Write(@"
writer.Write( @"
using System;
using System.Reflection;

public class {0}
{{
}}
", attribute);
", attribute );
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.cs" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.cs" }, projectFile );
}

[Test]
public void VerifyAttributeFoundVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System.Reflection.AssemblyVersion")]string attribute)
public void VerifyAttributeFoundVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System.Reflection.AssemblyVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
writer.Write(@"
writer.Write( @"
Imports System
Imports System.Reflection

<Assembly:{0}(""1.0.0.0"")>
", attribute);
", attribute );
}

var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile), attribute);
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb"));
var ex = Assert.Throws<WarningException>( () => InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.vb" }, projectFile ), attribute );
Assert.That( ex.Message, Is.EqualTo( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb" ) );
}

[Test]
public void VerifyUnformattedAttributeFoundVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System . Reflection . AssemblyVersion")]string attribute)
public void VerifyUnformattedAttributeFoundVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion", "System . Reflection . AssemblyVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
writer.Write(@"
writer.Write( @"
Imports System
Imports System.Reflection

< Assembly :
{0} ( ""1.0.0.0"")>
", attribute);
", attribute );
}

var ex = Assert.Throws<WarningException>(() => InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile), attribute);
Assert.That(ex.Message, Is.EqualTo("File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb"));
var ex = Assert.Throws<WarningException>( () => InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.vb" }, projectFile ), attribute );
Assert.That( ex.Message, Is.EqualTo( "File contains assembly version attributes which conflict with the attributes generated by GitVersion AssemblyInfo.vb" ) );
}

[Test]
public void VerifyCommentWorksVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
public void VerifyCommentWorksVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
writer.Write(@"
writer.Write( @"
Imports System
Imports System.Reflection

'<Assembly: {0}(""1.0.0.0"")>
", attribute);
", attribute );
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.vb" }, projectFile );
}

[Test]
public void VerifyStringWorksVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
public void VerifyStringWorksVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
writer.Write(@"
writer.Write( @"
Imports System
Imports System.Reflection

Public Class Temp
static const string Foo = ""<Assembly: {0}(""""1.0.0.0"""")>"";
End Class
", attribute);
", attribute );
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.vb" }, projectFile );
}

[Test]
public void VerifyIdentifierWorksVisualBasic([Values("AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion")]string attribute)
public void VerifyIdentifierWorksVisualBasic( [Values( "AssemblyVersion", "AssemblyFileVersion", "AssemblyInformationalVersion" )]string attribute )
{
using (var writer = File.CreateText(Path.Combine(projectDirectory, "AssemblyInfo.vb")))
using ( var writer = File.CreateText( Path.Combine( projectDirectory, "AssemblyInfo.vb" ) ) )
{
writer.Write(@"
writer.Write( @"
Imports System
Imports System.Reflection

Public Class {0}
End Class
", attribute);
", attribute );
}

InvalidFileChecker.CheckForInvalidFiles(new ITaskItem[] { new MockTaskItem { ItemSpec = "AssemblyInfo.vb" } }, projectFile);
InvalidFileChecker.CheckForInvalidFiles( new[] { "AssemblyInfo.vb" }, projectFile );
}
}
45 changes: 0 additions & 45 deletions src/GitVersionTask.Tests/Mocks/MockBuildEngine.cs

This file was deleted.

Loading