Skip to content

Commit

Permalink
🔀 Merge pull request #20 from cheesasaurus/main
Browse files Browse the repository at this point in the history
resolve issue occuring when scanned assembly contains an interface
  • Loading branch information
decaprime authored Jan 4, 2024
2 parents ecad29a + d128b60 commit d3e33b8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
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
{

}

}

0 comments on commit d3e33b8

Please sign in to comment.