-
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
Showing
14 changed files
with
331 additions
and
162 deletions.
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
10 changes: 10 additions & 0 deletions
10
src/Analyzer.Tests/EventSources/LogFieldAndPropertyDoNotExistEventSource.cs
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,10 @@ | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Thor.Analyzer.Tests.EventSources | ||
{ | ||
[EventSource(Name = "LogFieldAndPropertyDoesNotExist")] | ||
public sealed class LogFieldAndPropertyDoNotExistEventSource | ||
: EventSource | ||
{ | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
src/Analyzer.Tests/EventSources/LogFieldDoesNotExistEventSource.cs
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
src/Analyzer.Tests/EventSources/LogFieldDoesNotHaveValueEventSource.cs
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
src/Analyzer.Tests/EventSources/LogFieldNullEventSource.cs
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,11 @@ | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Thor.Analyzer.Tests.EventSources | ||
{ | ||
[EventSource(Name = "LogFieldNull")] | ||
public sealed class LogFieldNullEventSource | ||
: EventSource | ||
{ | ||
public static readonly LogFieldNullEventSource Log; | ||
} | ||
} |
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,11 @@ | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Thor.Analyzer.Tests.EventSources | ||
{ | ||
[EventSource(Name = "LogProperty")] | ||
public sealed class LogPropertyEventSource | ||
: EventSource | ||
{ | ||
public static LogPropertyEventSource Log { get; } = new LogPropertyEventSource(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Analyzer.Tests/EventSources/LogPropertyNotPublicEventSource.cs
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,12 @@ | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Thor.Analyzer.Tests.EventSources | ||
{ | ||
[EventSource(Name = "LogPropertyNotPublic")] | ||
public sealed class LogPropertyNotPublicEventSource | ||
: EventSource | ||
{ | ||
internal static LogPropertyNotPublicEventSource Log { get; } = | ||
new LogPropertyNotPublicEventSource(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Analyzer.Tests/EventSources/LogPropertyNotReadOnlyEventSource.cs
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,12 @@ | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Thor.Analyzer.Tests.EventSources | ||
{ | ||
[EventSource(Name = "LogPropertyNotReadOnly")] | ||
public sealed class LogPropertyNotReadOnlyEventSource | ||
: EventSource | ||
{ | ||
public static LogPropertyNotReadOnlyEventSource Log { get; set; } = | ||
new LogPropertyNotReadOnlyEventSource(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Analyzer.Tests/EventSources/LogPropertyNotStaticEventSource.cs
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,12 @@ | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Thor.Analyzer.Tests.EventSources | ||
{ | ||
[EventSource(Name = "LogPropertyNotStatic")] | ||
public sealed class LogPropertyNotStaticEventSource | ||
: EventSource | ||
{ | ||
public LogPropertyNotStaticEventSource Log { get; } = | ||
new LogPropertyNotStaticEventSource(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Analyzer.Tests/EventSources/LogPropertyNullEventSource.cs
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,11 @@ | ||
using System.Diagnostics.Tracing; | ||
|
||
namespace Thor.Analyzer.Tests.EventSources | ||
{ | ||
[EventSource(Name = "LogPropertyNull")] | ||
public sealed class LogPropertyNullEventSource | ||
: EventSource | ||
{ | ||
public static LogPropertyNullEventSource Log { get; } | ||
} | ||
} |
224 changes: 224 additions & 0 deletions
224
src/Analyzer.Tests/Rules/MustHaveStaticLogFieldOrPropertyTests.cs
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,224 @@ | ||
using Thor.Analyzer.Rules; | ||
using Thor.Analyzer.Tests.EventSources; | ||
using FluentAssertions; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Thor.Analyzer.Tests.Rules | ||
{ | ||
public class MustHaveStaticLogFieldOrPropertyTests | ||
: EventSourceRuleTestBase<MustHaveStaticLogFieldOrProperty> | ||
{ | ||
protected override MustHaveStaticLogFieldOrProperty CreateRule(IRuleSet ruleSet) | ||
{ | ||
return new MustHaveStaticLogFieldOrProperty(ruleSet); | ||
} | ||
|
||
[Fact(DisplayName = "Apply: Should return an error if log field and property does not exist")] | ||
public void Apply_NoLogFieldAndProperty() | ||
{ | ||
// arrange | ||
LogFieldAndPropertyDoNotExistEventSource eventSource = new LogFieldAndPropertyDoNotExistEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
|
||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
|
||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Error>(); | ||
} | ||
|
||
[Fact(DisplayName = "Apply: Should return an error if log field is not public")] | ||
public void Apply_LogFieldNotPublic() | ||
{ | ||
// arrange | ||
LogFieldNotPublicEventSource eventSource = new LogFieldNotPublicEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
|
||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
|
||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Error>(); | ||
} | ||
|
||
[Fact(DisplayName = "Apply: Should return an error if log field is not readonly")] | ||
public void Apply_LogFieldNotReadOnly() | ||
{ | ||
// arrange | ||
LogFieldNotReadOnlyEventSource eventSource = new LogFieldNotReadOnlyEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
|
||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
|
||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Error>(); | ||
} | ||
|
||
/* | ||
todo: figure out why this test leads to StackOverflowException | ||
[Fact(DisplayName = "Apply: Should return an error if log field is not static")] | ||
public void Apply_LogFieldNotStatic() | ||
{ | ||
// arrange | ||
LogFieldNotStaticEventSource eventSource = new LogFieldNotStaticEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Error>(); | ||
} | ||
*/ | ||
|
||
[Fact(DisplayName = "Apply: Should return an error if log field returns no value")] | ||
public void Apply_LogFieldNull() | ||
{ | ||
// arrange | ||
LogFieldNullEventSource eventSource = new LogFieldNullEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
|
||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
|
||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Error>(); | ||
} | ||
|
||
[Fact(DisplayName = "Apply: Should return a success if the log field was found as expected")] | ||
public void Apply_LogFieldAsExpected() | ||
{ | ||
// arrange | ||
LogFieldEventSource eventSource = new LogFieldEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
|
||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
|
||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Success>(); | ||
} | ||
|
||
[Fact(DisplayName = "Apply: Should return an error if log property is not public")] | ||
public void Apply_LogPropertyNotPublic() | ||
{ | ||
// arrange | ||
LogPropertyNotPublicEventSource eventSource = new LogPropertyNotPublicEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
|
||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
|
||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Error>(); | ||
} | ||
|
||
[Fact(DisplayName = "Apply: Should return an error if log property is not readonly")] | ||
public void Apply_LogPropertyNotReadOnly() | ||
{ | ||
// arrange | ||
LogPropertyNotReadOnlyEventSource eventSource = new LogPropertyNotReadOnlyEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
|
||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
|
||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Error>(); | ||
} | ||
|
||
/* | ||
todo: figure out why this test leads to StackOverflowException | ||
[Fact(DisplayName = "Apply: Should return an error if log property is not static")] | ||
public void Apply_LogPropertyNotStatic() | ||
{ | ||
// arrange | ||
LogPropertyNotStaticEventSource eventSource = new LogPropertyNotStaticEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Error>(); | ||
} | ||
*/ | ||
|
||
[Fact(DisplayName = "Apply: Should return an error if log property returns no value")] | ||
public void Apply_LogPropertyNull() | ||
{ | ||
// arrange | ||
LogPropertyNullEventSource eventSource = new LogPropertyNullEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
|
||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
|
||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Error>(); | ||
} | ||
|
||
[Fact(DisplayName = "Apply: Should return a success if the log property was found as expected")] | ||
public void Apply_LogPropertyAsExpected() | ||
{ | ||
// arrange | ||
LogPropertyEventSource eventSource = new LogPropertyEventSource(); | ||
SchemaReader reader = new SchemaReader(eventSource); | ||
EventSourceSchema schema = reader.Read(); | ||
IRuleSet ruleSet = new Mock<IRuleSet>().Object; | ||
IEventSourceRule rule = CreateRule(ruleSet); | ||
|
||
// act | ||
IResult result = rule.Apply(schema, eventSource); | ||
|
||
// assert | ||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<Success>(); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.