Skip to content

Commit

Permalink
More tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanLarsson committed Dec 3, 2019
1 parent 49502b9 commit be30397
Showing 1 changed file with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ReflectionAnalyzers.Tests.REFL013MemberIsOfWrongTypeTests
namespace ReflectionAnalyzers.Tests.REFL013MemberIsOfWrongTypeTests
{
using Gu.Roslyn.Asserts;
using Microsoft.CodeAnalysis;
Expand All @@ -25,6 +25,75 @@ void M(Type[] types)
typeof(C<,>).MakeGenericType(types);
}
}
}";
RoslynAssert.Valid(Analyzer, Descriptor, code);
}

[Test]
public static void Issue206WhenGettingField()
{
var code = @"
namespace ValidCode.Repros
{
using System;
using System.Reflection;
using NUnit.Framework;
public delegate void OnModelHandler(object e);
public interface IThing
{
event OnModelHandler OnModel;
}
public class Thing : IThing
{
public event OnModelHandler OnModel;
}
public class C
{
public static MulticastDelegate GetOnModel(IThing sender)
{
return (MulticastDelegate)sender.GetType()
.GetField(""OnModel"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)
.GetValue(sender);
}
}
}";
RoslynAssert.Valid(Analyzer, Descriptor, code);
}

[Test]
public static void Issue206WhenGettingEvent()
{
var code = @"
namespace ValidCode.Repros
{
using System;
using System.Reflection;
using NUnit.Framework;
public delegate void OnModelHandler(object e);
public interface IThing
{
event OnModelHandler OnModel;
}
public class Thing : IThing
{
public event OnModelHandler OnModel;
}
public class C
{
public static EventInfo GetOnModel(IThing sender)
{
return sender.GetType()
.GetEvent(""OnModel"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
}
}
}";
RoslynAssert.Valid(Analyzer, Descriptor, code);
}
Expand Down

0 comments on commit be30397

Please sign in to comment.