Skip to content

Commit

Permalink
add some tests for records
Browse files Browse the repository at this point in the history
  • Loading branch information
JKronberger committed May 10, 2023
1 parent 4533daf commit e0c3fca
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Weingartner.Json.Migration.Roslyn.Spec/DataContractAnalyzerSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Weingartner.Json.Migration.Roslyn.Spec
{
public class DataContractAnalyzerSpec : CodeFixVerifier
{

[Fact]
public void ShouldNotCreateDiagnosticIfTypeIsNotMigratable()
{
Expand Down Expand Up @@ -117,5 +118,32 @@ protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new DataContractAnalyzer();
}

[Fact]
public void ShouldCreateDiagnosticIfRecord()
{
var source = @"
using Weingartner.Json.Migration;
using System.Runtime.Serialization;
[Migratable("""")]
record TypeName
{
[DataMember]
public int A { get; set; }
}";
var expected = new DiagnosticResult
{
Id = DataContractAnalyzer.DiagnosticId,
Message = string.Format(DataContractAnalyzer.MessageFormat.ToString(CultureInfo.InvariantCulture), "TypeName"),
Severity = DiagnosticSeverity.Error,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 5, 7)
}
};

VerifyCSharpDiagnostic(source, expected);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,41 @@ class TypeName
VerifyCSharpFix(source, expected);
}

[Fact]
public void ShouldFixRecordIfInCorrectIsSpecified()
{
var source = @"
using Weingartner.Json.Migration;
using System.Runtime.Serialization;
[Migratable(""758832573"")]
[DataContract]
record TypeName
{
[DataMember]
public int A { get; set; }
[DataMember]
public double B { get; set; }
}";

var expected = @"
using Weingartner.Json.Migration;
using System.Runtime.Serialization;
[Migratable(""687340935"")]
[DataContract]
record TypeName
{
[DataMember]
public int A { get; set; }
[DataMember]
public double B { get; set; }
}";

VerifyCSharpFix(source, expected);
}


protected override CodeFixProvider GetCSharpCodeFixProvider()
{
return new MigrationHashAnalyzerCodeFixProvider();
Expand Down

0 comments on commit e0c3fca

Please sign in to comment.