forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests for some auxiliary classes (neo-project#1192)
- Loading branch information
Showing
11 changed files
with
1,135 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO; | ||
|
||
namespace Neo.UnitTests.IO | ||
{ | ||
[TestClass] | ||
public class UT_ByteArrayComparer | ||
{ | ||
[TestMethod] | ||
public void TestCompare() | ||
{ | ||
ByteArrayComparer comparer = new ByteArrayComparer(); | ||
byte[] x = new byte[0], y = new byte[0]; | ||
comparer.Compare(x, y).Should().Be(0); | ||
|
||
x = new byte[] { 1 }; | ||
comparer.Compare(x, y).Should().Be(1); | ||
y = x; | ||
comparer.Compare(x, y).Should().Be(0); | ||
|
||
x = new byte[] { 1 }; | ||
y = new byte[] { 2 }; | ||
comparer.Compare(x, y).Should().Be(-1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Neo.Plugins; | ||
|
||
namespace Neo.UnitTests.Plugins | ||
{ | ||
public class TestLogPlugin : Plugin, ILogPlugin | ||
{ | ||
public TestLogPlugin() : base() { } | ||
|
||
public string Output { set; get; } | ||
|
||
public override void Configure() { } | ||
|
||
public new void Log(string source, LogLevel level, string message) | ||
{ | ||
Output = source + "_" + level.ToString() + "_" + message; | ||
} | ||
|
||
public void LogMessage(string message) | ||
{ | ||
Log(message); | ||
} | ||
|
||
public bool TestOnMessage(object message) | ||
{ | ||
return OnMessage(message); | ||
} | ||
|
||
public IConfigurationSection TestGetConfiguration() | ||
{ | ||
return GetConfiguration(); | ||
} | ||
|
||
protected override bool OnMessage(object message) => true; | ||
|
||
public static bool TestResumeNodeStartup() | ||
{ | ||
return ResumeNodeStartup(); | ||
} | ||
|
||
public static void TestSuspendNodeStartup() | ||
{ | ||
SuspendNodeStartup(); | ||
} | ||
|
||
public static void TestLoadPlugins(NeoSystem system) | ||
{ | ||
LoadPlugins(system); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Plugins; | ||
using System; | ||
|
||
namespace Neo.UnitTests.Plugins | ||
{ | ||
[TestClass] | ||
public class UT_Plugin | ||
{ | ||
private static readonly object locker = new object(); | ||
|
||
[TestMethod] | ||
public void TestGetConfigFile() | ||
{ | ||
var pp = new TestLogPlugin(); | ||
var file = pp.ConfigFile; | ||
file.EndsWith("config.json").Should().BeTrue(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetName() | ||
{ | ||
var pp = new TestLogPlugin(); | ||
pp.Name.Should().Be("TestLogPlugin"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetVersion() | ||
{ | ||
var pp = new TestLogPlugin(); | ||
Action action = () => pp.Version.ToString(); | ||
action.Should().NotThrow(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestLog() | ||
{ | ||
var lp = new TestLogPlugin(); | ||
lp.LogMessage("Hello"); | ||
lp.Output.Should().Be("Plugin:TestLogPlugin_Info_Hello"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestSendMessage() | ||
{ | ||
lock (locker) | ||
{ | ||
Plugin.Plugins.Clear(); | ||
Plugin.SendMessage("hey1").Should().BeFalse(); | ||
|
||
var lp = new TestLogPlugin(); | ||
Plugin.SendMessage("hey2").Should().BeTrue(); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void TestNotifyPluginsLoadedAfterSystemConstructed() | ||
{ | ||
var pp = new TestLogPlugin(); | ||
Action action = () => Plugin.NotifyPluginsLoadedAfterSystemConstructed(); | ||
action.Should().NotThrow(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestResumeNodeStartupAndSuspendNodeStartup() | ||
{ | ||
var system = TestBlockchain.InitializeMockNeoSystem(); | ||
TestLogPlugin.TestLoadPlugins(system); | ||
TestLogPlugin.TestSuspendNodeStartup(); | ||
TestLogPlugin.TestSuspendNodeStartup(); | ||
TestLogPlugin.TestResumeNodeStartup().Should().BeFalse(); | ||
TestLogPlugin.TestResumeNodeStartup().Should().BeTrue(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetConfiguration() | ||
{ | ||
var pp = new TestLogPlugin(); | ||
pp.TestGetConfiguration().Key.Should().Be("PluginConfiguration"); | ||
} | ||
} | ||
} |
Oops, something went wrong.