-
Notifications
You must be signed in to change notification settings - Fork 50
/
TrayTOTP_PluginTests.cs
70 lines (55 loc) · 2.21 KB
/
TrayTOTP_PluginTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using FluentAssertions;
using KeePass.App.Configuration;
using KeePass.Forms;
using KeePass.Plugins;
using KeePass.UI;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace KeeTrayTOTP.Tests
{
[TestClass]
public class TrayTOTP_PluginTests
{
[TestMethod]
public void InitializePlugin_ShouldNotThrow()
{
var plugin = CreatePluginHostMock(out var host);
Action act = () => plugin.Initialize(host.Object);
act.Should().NotThrow();
}
[TestMethod]
public void InitializePlugin_ShouldAddOneColumnProvider()
{
var plugin = CreatePluginHostMock(out var host);
var numberOfColumnsBeforeInitialize = host.Object.ColumnProviderPool.Count;
plugin.Initialize(host.Object);
host.Object.ColumnProviderPool.Should().HaveCount(numberOfColumnsBeforeInitialize + 1);
}
[TestMethod]
public void Terminate_ShouldOnlyRemoveOurColumns()
{
var plugin = CreatePluginHostMock(out var host);
// add a fake column that does not belong to our plugin
var otherColumn = new Mock<ColumnProvider>().Object;
host.Object.ColumnProviderPool.Add(otherColumn);
plugin.Initialize(host.Object);
plugin.Terminate();
// only the fake column should be in the pool after the plugin terminates
host.Object.ColumnProviderPool.Should().HaveCount(1);
host.Object.ColumnProviderPool.Should().OnlyContain(c => c == otherColumn);
}
private static KeeTrayTOTPExt CreatePluginHostMock(out Mock<IPluginHost> host)
{
var plugin = new KeeTrayTOTPExt();
host = new Mock<IPluginHost>(MockBehavior.Strict);
var keepassForm = new MainForm();
host.SetupGet(c => c.MainWindow).Returns(keepassForm);
var customConfig = new AceCustomConfig();
host.SetupGet(c => c.CustomConfig).Returns(customConfig);
var columnProviderPool = new ColumnProviderPool();
host.SetupGet(c => c.ColumnProviderPool).Returns(columnProviderPool);
return plugin;
}
}
}