-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDuplicateMapperRuleTests.cs
More file actions
44 lines (34 loc) · 1.39 KB
/
DuplicateMapperRuleTests.cs
File metadata and controls
44 lines (34 loc) · 1.39 KB
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
using FluentAssertions;
using Microsoft.CodeAnalysis;
namespace CSharpFunctionalExtensions.HttpResults.Generators.Tests.Rules;
public class DuplicateMapperRuleTests
{
[Fact]
public void TestDuplicateMappers()
{
var sourceCode = """
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using CSharpFunctionalExtensions.HttpResults;
public class DocumentCreationError
{
public required string DocumentId { get; init; }
}
public class DocumentCreationErrorMapper : IResultErrorMapper<DocumentCreationError, Conflict<string>>
{
public Conflict<string> Map(DocumentCreationError error) => TypedResults.Conflict(error.DocumentId);
}
public class DocumentCreationErrorMapper2 : IResultErrorMapper<DocumentCreationError, Conflict<string>>
{
public Conflict<string> Map(DocumentCreationError error) => TypedResults.Conflict(error.DocumentId);
}
""";
var (diagnostics, _) = GeneratorTestHelper.RunGenerator(sourceCode);
var diagnosticsList = diagnostics.ToList();
diagnosticsList.Should().HaveCount(1);
var diagnostic = diagnosticsList[0];
diagnostic.Id.Should().Be("CFEHTTPR002");
diagnostic.Severity.Should().Be(DiagnosticSeverity.Error);
diagnostic.GetMessage().Should().Be("Class 'DocumentCreationError' does have multiple IResultErrorMapper");
}
}