-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathWindowsFirewallTests.cs
More file actions
55 lines (46 loc) · 1.95 KB
/
WindowsFirewallTests.cs
File metadata and controls
55 lines (46 loc) · 1.95 KB
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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using TechnitiumLibrary.Net.Firewall;
namespace TechnitiumLibrary.UnitTests.TechnitiumLibrary.Net.Firewall
{
[TestClass]
public sealed class WindowsFirewallTests
{
[TestMethod]
public void AddPort_ShouldThrow_WhenUnsupportedProtocol()
{
// Protocol ICMPv4 cannot be added using AddPort
Assert.ThrowsExactly<Exception>(() => WindowsFirewall.AddPort("bad", Protocol.ICMPv4, port: 55, enable: true));
}
[TestMethod]
public void RemovePort_ShouldThrow_WhenUnsupportedProtocol()
{
// RemovePort validates only TCP, UDP, ANY
Assert.ThrowsExactly<Exception>(() => WindowsFirewall.RemovePort(Protocol.IGMP, 123));
}
[TestMethod]
public void PortExists_ShouldThrow_WhenUnsupportedProtocol()
{
Assert.ThrowsExactly<Exception>(() => WindowsFirewall.PortExists(Protocol.IGMP, 44));
}
[TestMethod]
public void RuleExistsVista_ShouldReturnDoesNotExist_WhenInputsClearlyNotMatchingAnything()
{
// Since firewall is not guaranteed to have this rule,
// safest expected response is DoesNotExists.
RuleStatus result = WindowsFirewall.RuleExistsVista(
name: "__Definitely_Not_A_Real_Rule__",
applicationPath: "__Fake__");
Assert.AreEqual(RuleStatus.DoesNotExists, result);
}
[TestMethod]
public void ApplicationExists_ShouldReturnDoesNotExist_WhenApplicationIsNotRegistered()
{
// Public observable guarantee:
// if the system has no such application entry → DoesNotExists
const string fakePath = "C:\\DefinitelyNotExisting\\app.exe";
RuleStatus status = WindowsFirewall.ApplicationExists(fakePath);
Assert.AreEqual(RuleStatus.DoesNotExists, status);
}
}
}