Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve issue occuring when scanned assembly contains an interface #20

Merged
merged 7 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<packageSources>
<add key="BepInEx" value="https://nuget.bepinex.dev/v3/index.json" />
<add key="Samboy Feed" value="https://nuget.samboy.dev/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
4 changes: 2 additions & 2 deletions VCF.Core/Registry/CommandRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ public static void UnregisterConverter(Type converter)
}
}

internal static bool IsGenericConverterContext(Type rootType) => rootType.BaseType.Name == typeof(CommandArgumentConverter<>).Name;
internal static bool IsSpecificConverterContext(Type rootType) => rootType.BaseType.Name == typeof(CommandArgumentConverter<,>).Name;
internal static bool IsGenericConverterContext(Type rootType) => rootType?.BaseType?.Name == typeof(CommandArgumentConverter<>).Name;
internal static bool IsSpecificConverterContext(Type rootType) => rootType?.BaseType?.Name == typeof(CommandArgumentConverter<,>).Name;

public static void RegisterConverter(Type converter)
{
Expand Down
13 changes: 10 additions & 3 deletions VCF.Tests/AssertReplyContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@ public void Reply(string v)

public void AssertReply(string expected)
{
Assert.That(_sb.ToString().TrimEnd(Environment.NewLine.ToCharArray()), Is.EqualTo(expected));
Assert.That(RepliedTextLfAndTrimmed(), Is.EqualTo(expected));
}
public void AssertReplyContains(string expected)
{
var repliedText = _sb.ToString().TrimEnd(Environment.NewLine.ToCharArray());
var repliedText = RepliedTextLfAndTrimmed();
Assert.That(repliedText.Contains(expected), Is.True, $"Expected {expected} to be contained in replied: {repliedText}");
}

public void AssertInternalError()
{
Assert.That(_sb.ToString().TrimEnd(Environment.NewLine.ToCharArray()), Is.EqualTo("[vcf] An internal error has occurred."));
Assert.That(RepliedTextLfAndTrimmed(), Is.EqualTo("[vcf] An internal error has occurred."));
}

private string RepliedTextLfAndTrimmed()
{
return _sb.ToString()
.Replace("\r\n", "\n") // LF instead of CRLF for line endings
.TrimEnd(Environment.NewLine.ToCharArray());
}
}
47 changes: 47 additions & 0 deletions VCF.Tests/InitializationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Reflection;
using FakeItEasy;
using NUnit.Framework;
using VampireCommandFramework;

namespace VCF.Tests;

public class InitializationTests
{
[SetUp]
public void Setup()
{
CommandRegistry.Reset();
}

[TearDown]
public void TearDown()
{
CommandRegistry.Reset();
}

[Test]
public void ScanningInterfaceDoesNotCauseException()
{
Assert.DoesNotThrow(ScanAssemblyContainingInterface);
}

private void ScanAssemblyContainingInterface()
{
CommandRegistry.RegisterAll(AssemblyContainingInterface());
}

private Assembly AssemblyContainingInterface()
{
var mockAssembly = A.Fake<Assembly>();
A.CallTo(() => mockAssembly.GetTypes()).Returns(new Type[]{
typeof(ISomeInterface),
});
return mockAssembly;
}

private interface ISomeInterface
{

}

}
Loading