Skip to content

Commit

Permalink
Merge pull request #69 from codecentric/verify_for_testing
Browse files Browse the repository at this point in the history
feat: Reorganize tests to use Verify.
  • Loading branch information
ChristianSauer authored Jan 28, 2025
2 parents 2e92fb3 + 47e322e commit 1afa5e3
Show file tree
Hide file tree
Showing 73 changed files with 2,903 additions and 3,016 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//--------------------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------------------------------

namespace AutomaticInterfaceExample
{
/// <summary>
/// Bla bla
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.ShapeChanged" />
event global::System.EventHandler ShapeChanged;

}
}
23 changes: 23 additions & 0 deletions AutomaticInterface/Tests/Events/Events.NullableEvent.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//--------------------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------------------------------

#nullable enable
namespace AutomaticInterfaceExample
{
/// <summary>
/// Bla bla
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.ShapeChangedNullable" />
event global::System.EventHandler? ShapeChangedNullable;

}
}
#nullable restore
23 changes: 23 additions & 0 deletions AutomaticInterface/Tests/Events/Events.NullableEvent2.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//--------------------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------------------------------

#nullable enable
namespace AutomaticInterfaceExample
{
/// <summary>
/// Bla bla
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.ShapeChangedNullable" />
event global::System.EventHandler<string?> ShapeChangedNullable;

}
}
#nullable restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//--------------------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------------------------------

namespace AutomaticInterfaceExample
{
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AnEvent" />
event global::System.EventHandler AnEvent;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//--------------------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------------------------------

namespace AutomaticInterfaceExample
{
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AnEvent" />
event global::System.EventHandler AnEvent;

}
}
145 changes: 145 additions & 0 deletions AutomaticInterface/Tests/Events/Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
namespace Tests.Events;

public class Events
{
[Fact]
public async Task CopiesEventsToInterface()
{
const string code = """
using AutomaticInterface;
using System;
namespace AutomaticInterfaceExample
{
/// <summary>
/// Bla bla
/// </summary>
[GenerateAutomaticInterface]
class DemoClass
{
/// <summary>
/// Bla bla
/// </summary>
public event EventHandler ShapeChanged; // included
private event EventHandler ShapeChanged2; // ignored because not public
}
}
""";

await Verify(Infrastructure.GenerateCode(code));
}

[Fact]
public async Task NullableEvent()
{
const string code = """
using AutomaticInterface;
using System;
namespace AutomaticInterfaceExample
{
/// <summary>
/// Bla bla
/// </summary>
[GenerateAutomaticInterface]
class DemoClass
{
/// <summary>
/// Bla bla
/// </summary>
public event EventHandler? ShapeChangedNullable;
}
}
""";

await Verify(Infrastructure.GenerateCode(code));
}

[Fact]
public async Task NullableEvent2()
{
const string code = """
using AutomaticInterface;
using System;
namespace AutomaticInterfaceExample
{
/// <summary>
/// Bla bla
/// </summary>
[GenerateAutomaticInterface]
class DemoClass
{
/// <summary>
/// Bla bla
/// </summary>
public event EventHandler<string?> ShapeChangedNullable;
}
}
""";

await Verify(Infrastructure.GenerateCode(code));
}

[Fact]
public async Task WorksWithEventOverrides()
{
const string code = """
using AutomaticInterface;
using System;
namespace AutomaticInterfaceExample;
public class BaseClass
{
public virtual event EventHandler AnEvent;
}
[GenerateAutomaticInterface]
public class DemoClass : BaseClass
{
public override event EventHandler AnEvent;
}
""";

await Verify(Infrastructure.GenerateCode(code));
}

[Fact]
public async Task WorksWithEventShadowing()
{
const string code = """
using AutomaticInterface;
using System;
namespace AutomaticInterfaceExample;
public class BaseClass
{
public event EventHandler AnEvent;
}
[GenerateAutomaticInterface]
public class DemoClass : BaseClass
{
public new event EventHandler AnEvent;
}
""";

await Verify(Infrastructure.GenerateCode(code));
}
}
Loading

0 comments on commit 1afa5e3

Please sign in to comment.