Skip to content

Commit a844101

Browse files
authored
Merge pull request #2 from MagnetForensics/dev/roslyn
Refactor to Roslyn for code formatting, remove JetBrains cleanup
2 parents b33ec4f + 912d6b8 commit a844101

12 files changed

Lines changed: 446 additions & 472 deletions

DotSchema.Tests/CodePostProcessorTests.cs

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,173 @@ public partial class MyType
173173
Assert.Contains("public sealed class MyType", result);
174174
Assert.DoesNotContain("public partial class MyType", result);
175175
}
176+
177+
[Fact]
178+
public void Process_RemovesAdditionalPropertiesBoilerplate()
179+
{
180+
var code = """
181+
namespace Test;
182+
183+
public partial class MyType
184+
{
185+
public string Name { get; set; }
186+
187+
private System.Collections.Generic.IDictionary<string, object>? _additionalProperties;
188+
189+
[System.Text.Json.Serialization.JsonExtensionData]
190+
public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
191+
{
192+
get { return _additionalProperties ?? (_additionalProperties = new System.Collections.Generic.Dictionary<string, object>()); }
193+
set { _additionalProperties = value; }
194+
}
195+
}
196+
""";
197+
198+
var result = CodePostProcessor.Process(
199+
code,
200+
GenerationMode.All,
201+
"",
202+
EmptySet,
203+
EmptySet,
204+
EmptySet,
205+
"Config");
206+
207+
Assert.DoesNotContain("_additionalProperties", result);
208+
Assert.DoesNotContain("AdditionalProperties", result);
209+
Assert.DoesNotContain("JsonExtensionData", result);
210+
Assert.Contains("Name", result);
211+
}
212+
213+
[Fact]
214+
public void Process_PreservesBaseClassesAsNonSealed()
215+
{
216+
var code = """
217+
namespace Test;
218+
219+
public partial class BaseType
220+
{
221+
public string Name { get; set; }
222+
}
223+
224+
public partial class DerivedType : BaseType
225+
{
226+
public int Value { get; set; }
227+
}
228+
""";
229+
230+
var result = CodePostProcessor.Process(
231+
code,
232+
GenerationMode.All,
233+
"",
234+
EmptySet,
235+
EmptySet,
236+
EmptySet,
237+
"Config");
238+
239+
// BaseType should NOT be sealed (it's inherited from)
240+
Assert.DoesNotContain("public sealed class BaseType", result);
241+
242+
// DerivedType should be sealed
243+
Assert.Contains("public sealed class DerivedType", result);
244+
}
245+
246+
[Fact]
247+
public void Process_SharedMode_RemovesRootType()
248+
{
249+
var code = """
250+
namespace Test;
251+
252+
public partial class SharedType
253+
{
254+
public string Name { get; set; }
255+
}
256+
257+
public partial class Config
258+
{
259+
public int Value { get; set; }
260+
}
261+
""";
262+
263+
var result = CodePostProcessor.Process(
264+
code,
265+
GenerationMode.Shared,
266+
"",
267+
EmptySet,
268+
EmptySet,
269+
EmptySet,
270+
"Config");
271+
272+
Assert.Contains("SharedType", result);
273+
Assert.DoesNotContain("public sealed class Config", result);
274+
}
275+
276+
[Fact]
277+
public void Process_DoesNotSealAbstractClasses()
278+
{
279+
var code = """
280+
namespace Test;
281+
282+
public abstract partial class AbstractBase
283+
{
284+
public abstract string Name { get; set; }
285+
}
286+
287+
public partial class ConcreteType : AbstractBase
288+
{
289+
public override string Name { get; set; }
290+
}
291+
""";
292+
293+
var result = CodePostProcessor.Process(
294+
code,
295+
GenerationMode.All,
296+
"",
297+
EmptySet,
298+
EmptySet,
299+
EmptySet,
300+
"Config");
301+
302+
// AbstractBase should remain abstract (not sealed)
303+
Assert.Contains("public abstract class AbstractBase", result);
304+
Assert.DoesNotContain("sealed abstract", result);
305+
306+
// ConcreteType should NOT be sealed either (it's a base class for AbstractBase inheritance)
307+
// Actually, ConcreteType inherits from AbstractBase, so AbstractBase is the base class
308+
// ConcreteType should be sealed since it's not inherited from
309+
Assert.Contains("public sealed class ConcreteType", result);
310+
}
311+
312+
[Fact]
313+
public void Process_DoesNotSealStaticClasses()
314+
{
315+
var code = """
316+
namespace Test;
317+
318+
public static partial class StaticHelper
319+
{
320+
public static string GetValue() => "test";
321+
}
322+
323+
public partial class NormalType
324+
{
325+
public string Name { get; set; }
326+
}
327+
""";
328+
329+
var result = CodePostProcessor.Process(
330+
code,
331+
GenerationMode.All,
332+
"",
333+
EmptySet,
334+
EmptySet,
335+
EmptySet,
336+
"Config");
337+
338+
// StaticHelper should remain static (not sealed)
339+
Assert.Contains("public static class StaticHelper", result);
340+
Assert.DoesNotContain("sealed static", result);
341+
342+
// NormalType should be sealed
343+
Assert.Contains("public sealed class NormalType", result);
344+
}
176345
}

0 commit comments

Comments
 (0)