diff --git a/Weingartner.Json.Migration.Roslyn.Spec/DataContractAnalyzerSpec.cs b/Weingartner.Json.Migration.Roslyn.Spec/DataContractAnalyzerSpec.cs index 3ea3abc..208c447 100644 --- a/Weingartner.Json.Migration.Roslyn.Spec/DataContractAnalyzerSpec.cs +++ b/Weingartner.Json.Migration.Roslyn.Spec/DataContractAnalyzerSpec.cs @@ -10,6 +10,7 @@ namespace Weingartner.Json.Migration.Roslyn.Spec { public class DataContractAnalyzerSpec : CodeFixVerifier { + [Fact] public void ShouldNotCreateDiagnosticIfTypeIsNotMigratable() { @@ -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); + } } } \ No newline at end of file diff --git a/Weingartner.Json.Migration.Roslyn.Spec/MigrationHashAnalyzerSpec.cs b/Weingartner.Json.Migration.Roslyn.Spec/MigrationHashAnalyzerSpec.cs index dc37f0b..17880f5 100644 --- a/Weingartner.Json.Migration.Roslyn.Spec/MigrationHashAnalyzerSpec.cs +++ b/Weingartner.Json.Migration.Roslyn.Spec/MigrationHashAnalyzerSpec.cs @@ -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();