unit tests

This commit is contained in:
John Andrews
2024-08-26 18:16:07 +12:00
parent f92b8bbc5d
commit 444d46bf62
92 changed files with 1108 additions and 4700 deletions

View File

@@ -21,6 +21,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.4.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.4.3" />
<ProjectReference Include="..\PluginTestLibrary\PluginTestLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="FileFlows.Plugin">

View File

@@ -1,11 +1,12 @@
#if(DEBUG)
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PluginTestLibrary;
namespace FileFlows.Telegram.Tests;
[TestClass]
public class TelegramTests
public class TelegramTests : TestBase
{
[TestMethod]
public void SendMessage()

View File

@@ -1,59 +0,0 @@
#if(DEBUG)
namespace FileFlows.Telegram.Tests;
using FileFlows.Plugin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
internal class TestLogger : ILogger
{
private List<string> Messages = new List<string>();
public void DLog(params object[] args) => Log("DBUG", args);
public void ELog(params object[] args) => Log("ERRR", args);
public void ILog(params object[] args) => Log("INFO", args);
public void WLog(params object[] args) => Log("WARN", args);
private void Log(string type, object[] args)
{
if (args == null || args.Length == 0)
return;
string message = type + " -> " +
string.Join(", ", args.Select(x =>
x == null ? "null" :
x.GetType().IsPrimitive || x is string ? x.ToString() :
System.Text.Json.JsonSerializer.Serialize(x)));
Messages.Add(message);
}
public bool Contains(string message)
{
if (string.IsNullOrWhiteSpace(message))
return false;
string log = string.Join(Environment.NewLine, Messages);
return log.Contains(message);
}
public override string ToString()
{
return String.Join(Environment.NewLine, this.Messages.ToArray());
}
public string GetTail(int length = 50)
{
if (length <= 0)
length = 50;
if (Messages.Count <= length)
return string.Join(Environment.NewLine, Messages);
return string.Join(Environment.NewLine, Messages.TakeLast(length));
}
}
#endif