-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9208346
commit d44664e
Showing
9 changed files
with
545 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Cake.Core; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.IO; | ||
using Cake.Core.Tests.Fakes; | ||
using NSubstitute; | ||
using Xunit; | ||
using System.IO; | ||
|
||
namespace Cake.Common.Tests.Fixtures | ||
{ | ||
public sealed class AssemblyInfoFixture | ||
{ | ||
public IFileSystem FileSystem { get; set; } | ||
public ICakeLog Log { get; set; } | ||
public ICakeEnvironment Environment { get; set; } | ||
|
||
public AssemblyInfoSettings Settings { get; set; } | ||
public FilePath Path { get; set; } | ||
|
||
public AssemblyInfoFixture() | ||
{ | ||
FileSystem = new FakeFileSystem(false); | ||
|
||
Environment = Substitute.For<ICakeEnvironment>(); | ||
Environment.WorkingDirectory.Returns(new DirectoryPath("/Working")); | ||
|
||
Log = Substitute.For<ICakeLog>(); | ||
Settings = new AssemblyInfoSettings(); | ||
Path = "AssemblyInfo.cs"; | ||
} | ||
|
||
public string CreateAndReturnContent() | ||
{ | ||
var creator = new AssemblyInfoCreator(FileSystem, Environment, Log); | ||
creator.Create(Path, Settings); | ||
|
||
var file = FileSystem.GetFile(Path.MakeAbsolute(Environment)); | ||
Assert.True(file.Exists, "File was not created."); | ||
using (var reader = new StreamReader(file.OpenRead())) | ||
{ | ||
return reader.ReadToEnd(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,273 @@ | ||
using System; | ||
using Cake.Common.Tests.Fixtures; | ||
using Cake.Core; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.IO; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Cake.Common.Tests.Unit | ||
{ | ||
public sealed class AssemblyInfoCreatorTests | ||
{ | ||
public sealed class TheConstructor | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_File_System_Is_Null() | ||
{ | ||
// Given | ||
var environment = Substitute.For<ICakeEnvironment>(); | ||
var log = Substitute.For<ICakeLog>(); | ||
|
||
// When | ||
var result = Record.Exception(() => new AssemblyInfoCreator(null, environment, log)); | ||
|
||
// Then | ||
Assert.IsType<ArgumentNullException>(result); | ||
Assert.Equal("fileSystem", ((ArgumentNullException)result).ParamName); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Environment_Is_Null() | ||
{ | ||
// Given | ||
var fileSystem = Substitute.For<IFileSystem>(); | ||
var log = Substitute.For<ICakeLog>(); | ||
|
||
// When | ||
var result = Record.Exception(() => new AssemblyInfoCreator(fileSystem, null, log)); | ||
|
||
// Then | ||
Assert.IsType<ArgumentNullException>(result); | ||
Assert.Equal("environment", ((ArgumentNullException)result).ParamName); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Log_Is_Null() | ||
{ | ||
// Given | ||
var fileSystem = Substitute.For<IFileSystem>(); | ||
var environment = Substitute.For<ICakeEnvironment>(); | ||
|
||
// When | ||
var result = Record.Exception(() => new AssemblyInfoCreator(fileSystem, environment, null)); | ||
|
||
// Then | ||
Assert.IsType<ArgumentNullException>(result); | ||
Assert.Equal("log", ((ArgumentNullException)result).ParamName); | ||
} | ||
} | ||
|
||
public sealed class TheCreateMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Output_Path_Is_Null() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
var creator = new AssemblyInfoCreator(fixture.FileSystem, fixture.Environment, fixture.Log); | ||
|
||
// When | ||
var result = Record.Exception(() => creator.Create(null, new AssemblyInfoSettings())); | ||
|
||
// Then | ||
Assert.IsType<ArgumentNullException>(result); | ||
Assert.Equal("outputPath", ((ArgumentNullException)result).ParamName); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Settings_Are_Null() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
var creator = new AssemblyInfoCreator(fixture.FileSystem, fixture.Environment, fixture.Log); | ||
|
||
// When | ||
var result = Record.Exception(() => creator.Create("A.cs", null)); | ||
|
||
// Then | ||
Assert.IsType<ArgumentNullException>(result); | ||
Assert.Equal("settings", ((ArgumentNullException)result).ParamName); | ||
} | ||
|
||
[Fact] | ||
public void Should_Make_Relative_Output_Path_Absolute() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
var creator = new AssemblyInfoCreator(fixture.FileSystem, fixture.Environment, fixture.Log); | ||
|
||
// When | ||
creator.Create("AssemblyInfo.cs", new AssemblyInfoSettings()); | ||
|
||
// Then | ||
Assert.True(fixture.FileSystem.Exist((FilePath)"/Working/AssemblyInfo.cs")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Title_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.Title = "TheTitle"; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Reflection;")); | ||
Assert.True(result.Contains("[assembly: AssemblyTitle(\"TheTitle\")]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Description_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.Description = "TheDescription"; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Reflection;")); | ||
Assert.True(result.Contains("[assembly: AssemblyDescription(\"TheDescription\")]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Guid_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.Guid = "TheGuid"; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Runtime.InteropServices;")); | ||
Assert.True(result.Contains("[assembly: Guid(\"TheGuid\")]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Product_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.Product = "TheProduct"; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Reflection;")); | ||
Assert.True(result.Contains("[assembly: AssemblyProduct(\"TheProduct\")]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Copyright_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.Copyright = "TheCopyright"; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Reflection;")); | ||
Assert.True(result.Contains("[assembly: AssemblyCopyright(\"TheCopyright\")]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Trademark_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.Trademark = "TheTrademark"; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Reflection;")); | ||
Assert.True(result.Contains("[assembly: AssemblyTrademark(\"TheTrademark\")]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Version_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.Version = "TheVersion"; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Reflection;")); | ||
Assert.True(result.Contains("[assembly: AssemblyVersion(\"TheVersion\")]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_FileVersion_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.FileVersion = "TheFileVersion"; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Reflection;")); | ||
Assert.True(result.Contains("[assembly: AssemblyFileVersion(\"TheFileVersion\")]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_InformationalVersion_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.InformationalVersion = "TheInformationalVersion"; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Reflection;")); | ||
Assert.True(result.Contains("[assembly: AssemblyInformationalVersion(\"TheInformationalVersion\")]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_ComVisible_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.ComVisible = true; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Runtime.InteropServices;")); | ||
Assert.True(result.Contains("[assembly: ComVisible(true)]")); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_CLSCompliant_Attribute_If_Set() | ||
{ | ||
// Given | ||
var fixture = new AssemblyInfoFixture(); | ||
fixture.Settings.CLSCompliant = true; | ||
|
||
// When | ||
var result = fixture.CreateAndReturnContent(); | ||
|
||
// Then | ||
Assert.True(result.Contains("using System.Runtime.InteropServices;")); | ||
Assert.True(result.Contains("[assembly: CLSCompliant(true)]")); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.