Fix lodestone character id extraction

This commit is contained in:
Stefan Berg
2022-08-03 22:43:11 +02:00
parent aebb7fdbb0
commit 60439535e7
5 changed files with 93 additions and 6 deletions

View File

@@ -0,0 +1,53 @@
using FluentAssertions;
using MareSynchronosServer.Discord;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace MareSynchronosServerTest.Discord {
public class DiscordBotTest {
[Test]
[TestCase("", null)]
[TestCase("abcd", null)]
[TestCase("www.google.de", null)]
[TestCase("https://www.google.de", null)]
[TestCase("de.finalfantasyxiv.com/lodestone/character/1234", null)]
[TestCase("https://cn.finalfantasyxiv.com/lodestone/character/1234", null)]
[TestCase("http://jp.finalfantasyxiv.com/lodestone/character/1234", null)]
[TestCase("https://jp.finalfantasyxiv.com/character/1234", null)]
[TestCase("https://jp.finalfantasyxiv.com/lodestone/1234", null)]
[TestCase("https://www.finalfantasyxiv.com/lodestone/character/1234", null)]
[TestCase("https://jp.finalfantasyxiv.com/lodestone/character/1234", 1234)]
[TestCase("https://fr.finalfantasyxiv.com/lodestone/character/1234", 1234)]
[TestCase("https://eu.finalfantasyxiv.com/lodestone/character/1234/", 1234)]
[TestCase("https://eu.finalfantasyxiv.com/lodestone/character/1234?myurlparameter=500", 1234)]
[TestCase("https://de.finalfantasyxiv.com/lodestone/character/1234/whatever/3456", 1234)]
[TestCase("https://na.finalfantasyxiv.com/lodestone/character/1234abcd4321/whatever/3456", 1234)]
public void Test1(string url, int? expectedId) {
var inMemorySettings = new Dictionary<string, string> {
{"DiscordBotToken", "1234"}
};
IConfiguration configuration = new ConfigurationBuilder()
.AddInMemoryCollection(inMemorySettings)
.Build();
var spMock = new Mock<IServiceProvider>();
var loggerMock = new Mock<ILogger<DiscordBot>>();
var sut = new DiscordBot(spMock.Object, configuration, loggerMock.Object);
MethodInfo methodInfo = sut.GetType().GetMethod("ParseCharacterIdFromLodestoneUrl", BindingFlags.NonPublic | BindingFlags.Instance);
var actualId = methodInfo.Invoke(sut, new object[] { url });
actualId.Should().Be(expectedId);
}
}
}

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MareSynchronosServer\MareSynchronosServer.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1 @@
global using NUnit.Framework;