Skip to content

Commit

Permalink
Add tests for Unity custom serializable class
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-marichal committed Jul 11, 2024
1 parent 0825155 commit 350fd89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void FieldsShouldBeEncapsulatedInProperties_Unity3D_Ignored() =>
builder.AddPaths("FieldsShouldBeEncapsulatedInProperties.Unity3D.cs")
// Concurrent analysis puts fake Unity3D class into the Concurrent namespace
.WithConcurrentAnalysis(false)
.VerifyNoIssues();
.Verify();

#if NET

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// https://github.com/SonarSource/sonar-dotnet/issues/7522
using System;

// https://github.com/SonarSource/sonar-dotnet/issues/7522
public class UnityMonoBehaviour : UnityEngine.MonoBehaviour
{
public int Field1; // Compliant
Expand All @@ -9,10 +11,22 @@ public class UnityScriptableObject : UnityEngine.ScriptableObject
public int Field1; // Compliant
}

public class InvalidCustomSerializableClass1 : UnityEngine.Object
{
public int Field1; // Noncompliant
}

[Serializable]
public class ValidCustomSerializableClass : UnityEngine.Object
{
public int Field1; // Compliant
}

// Unity3D does not seem to be available as a nuget package and we cannot use the original classes
// Cannot run this test case in Concurrent mode because of the Concurrent namespace
namespace UnityEngine
{
public class MonoBehaviour { }
public class ScriptableObject { }
public class Object { }
}

0 comments on commit 350fd89

Please sign in to comment.