Skip to content

Commit c242d14

Browse files
devleadgep13
authored andcommitted
Add log string & object methods
* fixes cake-build#1455
1 parent 2e46585 commit c242d14

File tree

5 files changed

+527
-9
lines changed

5 files changed

+527
-9
lines changed

src/Cake.Common.Tests/Unit/Diagnostics/LoggingAliasesTests.cs

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,36 @@ public void Should_Evaluate_And_Write_Error_Message_To_Log()
4444
fixture.Context.Log.Received(1).Write(Verbosity.Quiet, LogLevel.Error, fixture.Format, fixture.Args);
4545
Assert.True(fixture.Evaluated);
4646
}
47+
48+
[Fact]
49+
public void Should_Write_Error_String_Value_To_Log()
50+
{
51+
// Given
52+
var context = Substitute.For<ICakeContext>();
53+
context.Log.Returns(Substitute.For<ICakeLog>());
54+
const string value = "Hello {0}";
55+
56+
// When
57+
context.Error(value);
58+
59+
// Then
60+
context.Log.Received(1).Write(Verbosity.Quiet, LogLevel.Error, "{0}", value);
61+
}
62+
63+
[Fact]
64+
public void Should_Write_Error_Object_Value_To_Log()
65+
{
66+
// Given
67+
var context = Substitute.For<ICakeContext>();
68+
context.Log.Returns(Substitute.For<ICakeLog>());
69+
var value = new { FirstName = "John", LastName="Doe" };
70+
71+
// When
72+
context.Error(value);
73+
74+
// Then
75+
context.Log.Received(1).Write(Verbosity.Quiet, LogLevel.Error, "{0}", value);
76+
}
4777
}
4878

4979
public sealed class TheWarningMethod
@@ -91,6 +121,36 @@ public void Should_Not_Evaluate_And_Write_Warning_Message_To_Log()
91121
fixture.Context.Log.DidNotReceive().Write(Verbosity.Minimal, LogLevel.Warning, fixture.Format, fixture.Args);
92122
Assert.False(fixture.Evaluated);
93123
}
124+
125+
[Fact]
126+
public void Should_Write_Warning_String_Value_To_Log()
127+
{
128+
// Given
129+
var context = Substitute.For<ICakeContext>();
130+
context.Log.Returns(Substitute.For<ICakeLog>());
131+
const string value = "Hello {0}";
132+
133+
// When
134+
context.Warning(value);
135+
136+
// Then
137+
context.Log.Received(1).Write(Verbosity.Minimal, LogLevel.Warning, "{0}", value);
138+
}
139+
140+
[Fact]
141+
public void Should_Write_Warning_Object_Value_To_Log()
142+
{
143+
// Given
144+
var context = Substitute.For<ICakeContext>();
145+
context.Log.Returns(Substitute.For<ICakeLog>());
146+
var value = new { FirstName = "John", LastName="Doe" };
147+
148+
// When
149+
context.Warning(value);
150+
151+
// Then
152+
context.Log.Received(1).Write(Verbosity.Minimal, LogLevel.Warning, "{0}", value);
153+
}
94154
}
95155

96156
public sealed class TheInformationMethod
@@ -138,6 +198,36 @@ public void Should_Not_Evaluate_And_Write_Information_Message_To_Log()
138198
fixture.Context.Log.DidNotReceive().Write(Verbosity.Normal, LogLevel.Information, fixture.Format, fixture.Args);
139199
Assert.False(fixture.Evaluated);
140200
}
201+
202+
[Fact]
203+
public void Should_Write_Information_String_Value_To_Log()
204+
{
205+
// Given
206+
var context = Substitute.For<ICakeContext>();
207+
context.Log.Returns(Substitute.For<ICakeLog>());
208+
const string value = "Hello {0}";
209+
210+
// When
211+
context.Information(value);
212+
213+
// Then
214+
context.Log.Received(1).Write(Verbosity.Normal, LogLevel.Information, "{0}", value);
215+
}
216+
217+
[Fact]
218+
public void Should_Write_Information_Object_Value_To_Log()
219+
{
220+
// Given
221+
var context = Substitute.For<ICakeContext>();
222+
context.Log.Returns(Substitute.For<ICakeLog>());
223+
var value = new { FirstName = "John", LastName="Doe" };
224+
225+
// When
226+
context.Information(value);
227+
228+
// Then
229+
context.Log.Received(1).Write(Verbosity.Normal, LogLevel.Information, "{0}", value);
230+
}
141231
}
142232

143233
public sealed class TheVerboseMethod
@@ -185,6 +275,36 @@ public void Should_Not_Evaluate_And_Write_Verbose_Message_To_Log()
185275
fixture.Context.Log.DidNotReceive().Write(Verbosity.Verbose, LogLevel.Verbose, fixture.Format, fixture.Args);
186276
Assert.False(fixture.Evaluated);
187277
}
278+
279+
[Fact]
280+
public void Should_Write_Verbose_String_Value_To_Log()
281+
{
282+
// Given
283+
var context = Substitute.For<ICakeContext>();
284+
context.Log.Returns(Substitute.For<ICakeLog>());
285+
const string value = "Hello {0}";
286+
287+
// When
288+
context.Verbose(value);
289+
290+
// Then
291+
context.Log.Received(1).Write(Verbosity.Verbose, LogLevel.Verbose, "{0}", value);
292+
}
293+
294+
[Fact]
295+
public void Should_Write_Verbose_Object_Value_To_Log()
296+
{
297+
// Given
298+
var context = Substitute.For<ICakeContext>();
299+
context.Log.Returns(Substitute.For<ICakeLog>());
300+
var value = new { FirstName = "John", LastName="Doe" };
301+
302+
// When
303+
context.Verbose(value);
304+
305+
// Then
306+
context.Log.Received(1).Write(Verbosity.Verbose, LogLevel.Verbose, "{0}", value);
307+
}
188308
}
189309

190310
public sealed class TheDebugMethod
@@ -232,6 +352,36 @@ public void Should_Not_Evaluate_And_Write_Debug_Message_To_Log()
232352
fixture.Context.Log.DidNotReceive().Write(Verbosity.Diagnostic, LogLevel.Debug, fixture.Format, fixture.Args);
233353
Assert.False(fixture.Evaluated);
234354
}
355+
356+
[Fact]
357+
public void Should_Write_Debug_String_Value_To_Log()
358+
{
359+
// Given
360+
var context = Substitute.For<ICakeContext>();
361+
context.Log.Returns(Substitute.For<ICakeLog>());
362+
const string value = "Hello {0}";
363+
364+
// When
365+
context.Debug(value);
366+
367+
// Then
368+
context.Log.Received(1).Write(Verbosity.Diagnostic, LogLevel.Debug, "{0}", value);
369+
}
370+
371+
[Fact]
372+
public void Should_Write_Debug_Object_Value_To_Log()
373+
{
374+
// Given
375+
var context = Substitute.For<ICakeContext>();
376+
context.Log.Returns(Substitute.For<ICakeLog>());
377+
var value = new { FirstName = "John", LastName="Doe" };
378+
379+
// When
380+
context.Debug(value);
381+
382+
// Then
383+
context.Log.Received(1).Write(Verbosity.Diagnostic, LogLevel.Debug, "{0}", value);
384+
}
235385
}
236386
}
237387
}

src/Cake.Common.Tests/project.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
"/additionalfile:../stylecop.json"
88
],
99
"compile": {
10-
"includeFiles": [
11-
"../SolutionInfo.cs"
12-
]
10+
"includeFiles": [
11+
"../SolutionInfo.cs"
12+
]
1313
},
1414
"copyToOutput": {
15-
"include": [ "./Properties/PropertyList-1.0.dtd" ]
15+
"include": [
16+
"./Properties/PropertyList-1.0.dtd"
17+
]
1618
}
1719
},
1820
"configurations": {

0 commit comments

Comments
 (0)