forked from dotnet/Nerdbank.GitVersioning
/
AssemblyInfoTest.cs
215 lines (197 loc) · 8.45 KB
/
AssemblyInfoTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.Utilities;
using Nerdbank.GitVersioning.Tasks;
using Xunit;
public class AssemblyInfoTest : IClassFixture<MSBuildFixture>
{
[Theory]
[InlineData(false)]
[InlineData(true)]
[InlineData(null)]
public void FSharpGenerator(bool? thisAssemblyClass)
{
var info = new AssemblyVersionInfo();
info.AssemblyCompany = "company";
info.AssemblyFileVersion = "1.3.1.0";
info.AssemblyVersion = "1.3.0.0";
info.AdditionalThisAssemblyFields =
new TaskItem[]
{
new TaskItem(
"CustomString1",
new Dictionary<string,string>() { { "String", "abc" } } ),
new TaskItem(
"CustomString2",
new Dictionary<string,string>() { { "String", "" } } ),
new TaskItem(
"CustomString3",
new Dictionary<string,string>() { { "String", "" }, { "EmitIfEmpty", "true" } } ),
new TaskItem(
"CustomBool",
new Dictionary<string,string>() { { "Boolean", "true" } } ),
new TaskItem(
"CustomTicks",
new Dictionary<string,string>() { { "Ticks", "637509805729817056" } } ),
};
info.CodeLanguage = "f#";
if (thisAssemblyClass.HasValue)
{
info.EmitThisAssemblyClass = thisAssemblyClass.GetValueOrDefault();
}
var built = info.BuildCode();
var expected = $@"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AssemblyInfo
[<assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")>]
[<assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")>]
[<assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")>]
{(thisAssemblyClass.GetValueOrDefault(true) ? $@"do()
#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
[<System.CodeDom.Compiler.GeneratedCode(""{AssemblyVersionInfo.GeneratorName}"",""{AssemblyVersionInfo.GeneratorVersion}"")>]
#endif
#if NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1
[<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>]
#endif
type internal ThisAssembly() =
static member internal AssemblyCompany = ""company""
static member internal AssemblyFileVersion = ""1.3.1.0""
static member internal AssemblyVersion = ""1.3.0.0""
static member internal CustomBool = true
static member internal CustomString1 = ""abc""
static member internal CustomString3 = """"
static member internal CustomTicks = new System.DateTime(637509805729817056L, System.DateTimeKind.Utc)
static member internal IsPrerelease = false
static member internal IsPublicRelease = false
static member internal RootNamespace = """"
do()
" : "")}";
Assert.Equal(expected, built);
}
[Theory]
[InlineData(false)]
[InlineData(true)]
[InlineData(null)]
public void CSharpGenerator(bool? thisAssemblyClass)
{
var info = new AssemblyVersionInfo();
info.AssemblyCompany = "company";
info.AssemblyFileVersion = "1.3.1.0";
info.AssemblyVersion = "1.3.0.0";
info.CodeLanguage = "c#";
info.AdditionalThisAssemblyFields =
new TaskItem[]
{
new TaskItem(
"CustomString1",
new Dictionary<string,string>() { { "String", "abc" } } ),
new TaskItem(
"CustomString2",
new Dictionary<string,string>() { { "String", "" } } ),
new TaskItem(
"CustomString3",
new Dictionary<string,string>() { { "String", "" }, { "EmitIfEmpty", "true" } } ),
new TaskItem(
"CustomBool",
new Dictionary<string,string>() { { "Boolean", "true" } } ),
new TaskItem(
"CustomTicks",
new Dictionary<string,string>() { { "Ticks", "637509805729817056" } } ),
};
if (thisAssemblyClass.HasValue)
{
info.EmitThisAssemblyClass = thisAssemblyClass.GetValueOrDefault();
}
var built = info.BuildCode();
var expected = $@"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")]
[assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")]
{(thisAssemblyClass.GetValueOrDefault(true) ? $@"#if NETSTANDARD || NETFRAMEWORK || NETCOREAPP
[System.CodeDom.Compiler.GeneratedCode(""{AssemblyVersionInfo.GeneratorName}"",""{AssemblyVersionInfo.GeneratorVersion}"")]
#endif
#if NETFRAMEWORK || NETCOREAPP || NETSTANDARD2_0 || NETSTANDARD2_1
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
#endif
internal static partial class ThisAssembly {{
internal const string AssemblyCompany = ""company"";
internal const string AssemblyFileVersion = ""1.3.1.0"";
internal const string AssemblyVersion = ""1.3.0.0"";
internal const bool CustomBool = true;
internal const string CustomString1 = ""abc"";
internal const string CustomString3 = """";
internal static readonly System.DateTime CustomTicks = new System.DateTime(637509805729817056L, System.DateTimeKind.Utc);
internal const bool IsPrerelease = false;
internal const bool IsPublicRelease = false;
internal const string RootNamespace = """";
}}
" : "")}";
Assert.Equal(expected, built);
}
[Theory]
[InlineData(false)]
[InlineData(true)]
[InlineData(null)]
public void VisualBasicGenerator(bool? thisAssemblyClass)
{
var info = new AssemblyVersionInfo();
info.AssemblyCompany = "company";
info.AssemblyFileVersion = "1.3.1.0";
info.AssemblyVersion = "1.3.0.0";
info.CodeLanguage = "vb";
if (thisAssemblyClass.HasValue)
{
info.EmitThisAssemblyClass = thisAssemblyClass.GetValueOrDefault();
}
var built = info.BuildCode();
var expected = $@"'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:4.0.30319.42000
'
' Changes to this file may cause incorrect behavior and will be lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
<Assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")>
<Assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")>
<Assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")>
{(thisAssemblyClass.GetValueOrDefault(true) ? $@"#If NETFRAMEWORK Or NETCOREAPP Or NETSTANDARD2_0 Or NETSTANDARD2_1 Then
<System.CodeDom.Compiler.GeneratedCode(""{AssemblyVersionInfo.GeneratorName}"",""{AssemblyVersionInfo.GeneratorVersion}"")>
<System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage>
Partial Friend NotInheritable Class ThisAssembly
#ElseIf NETSTANDARD Or NETFRAMEWORK Or NETCOREAPP Then
<System.CodeDom.Compiler.GeneratedCode(""{AssemblyVersionInfo.GeneratorName}"",""{AssemblyVersionInfo.GeneratorVersion}"")>
Partial Friend NotInheritable Class ThisAssembly
#Else
Partial Friend NotInheritable Class ThisAssembly
#End If
Friend Const AssemblyCompany As String = ""company""
Friend Const AssemblyFileVersion As String = ""1.3.1.0""
Friend Const AssemblyVersion As String = ""1.3.0.0""
Friend Const IsPrerelease As Boolean = False
Friend Const IsPublicRelease As Boolean = False
Friend Const RootNamespace As String = """"
End Class
" : "")}";
Assert.Equal(expected, built);
}
}