aboutsummaryrefslogtreecommitdiff
path: root/Tools/Hazel-Networking/Hazel.UnitTests/UPnPTests.cs
blob: 3bee91191fe48de8a270696cc84209b7bbaf3ede (plain)
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
using System;
using Hazel.UPnP;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Hazel.UnitTests
{
    // [TestClass]
    // TODO: These tests are super flaky because of hardware differences. Not sure what can be done.
    public class UPnPTests
    {
        [TestMethod]
        public void CanForwardPort()
        {
            using (UPnPHelper dut = new UPnPHelper(Logger.Instance))
            {
                Assert.IsTrue(dut.ForwardPort(22023, "Hazel Test"));
            }
        }

        [TestMethod]
        public void CanDeletePort()
        {
            using (UPnPHelper dut = new UPnPHelper(Logger.Instance))
            {
                Assert.IsTrue(dut.DeleteForwardingRule(22023));
            }
        }
    }

    public class Logger : ILogger
    {
        public static readonly ILogger Instance = new Logger();

        public void WriteVerbose(string msg)
        {
            Console.WriteLine(msg);
        }

        public void WriteWarning(string msg)
        {
            Console.WriteLine(msg);
        }

        public void WriteError(string msg)
        {
            Console.WriteLine(msg);
        }

        public void WriteInfo(string msg)
        {
            Console.WriteLine(msg);
        }
    }
}