-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from SteveDunn/disallow-vos-in-non-partial-types
Analyzer should fail build if ValueObject decorated type is not partial
- Loading branch information
Showing
5 changed files
with
56 additions
and
6 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
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
37 changes: 37 additions & 0 deletions
37
tests/SmallTests/DiagnosticsTests/DisallowNonPartialTests.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,37 @@ | ||
using System.Linq; | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using Microsoft.CodeAnalysis; | ||
using Vogen; | ||
using Xunit; | ||
|
||
namespace SmallTests.DiagnosticsTests; | ||
|
||
public class DisallowNonPartialTests | ||
{ | ||
[Theory] | ||
[InlineData("abstract class")] | ||
[InlineData("abstract record class")] | ||
public void Disallows_non_partial_types(string type) | ||
{ | ||
var source = $@"using Vogen; | ||
namespace Whatever; | ||
[ValueObject] | ||
public {type} CustomerId {{ }} | ||
"; | ||
|
||
var (diagnostics, _) = TestHelper.GetGeneratedOutput<ValueObjectGenerator>(source); | ||
|
||
using (new AssertionScope()) | ||
{ | ||
diagnostics.Should().HaveCount(1); | ||
Diagnostic diagnostic = diagnostics.Single(); | ||
|
||
diagnostic.Id.Should().Be("VOG021"); | ||
diagnostic.ToString().Should() | ||
.Match("*: error VOG021: Type CustomerId is decorated as a Value Object and should be in a partial type."); | ||
} | ||
} | ||
} |
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