This repository was archived by the owner on Jun 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathServiceControllerTests.cs
More file actions
68 lines (62 loc) · 1.89 KB
/
ServiceControllerTests.cs
File metadata and controls
68 lines (62 loc) · 1.89 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
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using NUnit.Framework;
using ServiceStack.Service;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface.Tests.Support.Version100.Operations;
namespace ServiceStack.ServiceInterface.Tests
{
[TestFixture]
public class ServiceControllerTests : TestBase
{
[Port(typeof(InternalOnly), EndpointAttributes.Internal)]
public class InternalOnlyHandler
{
}
[Port(typeof(HttpGet), EndpointAttributes.External | EndpointAttributes.HttpGet)]
public class HttpGetHandler
{
}
[Test]
public void Internal_only_handler_can_be_called_internally()
{
ServiceControllerContext.AssertServiceRestrictions(
new InternalOnlyHandler(), EndpointAttributes.Internal, "name");
}
[Test]
public void Internal_only_handler_cannot_be_called_externally()
{
try
{
ServiceControllerContext.AssertServiceRestrictions(
new InternalOnlyHandler(), EndpointAttributes.External, "name");
}
catch (UnauthorizedAccessException uae)
{
Assert.That(uae.Message.Contains(string.Format("'{0}'", EndpointAttributes.Internal)));
return;
}
Assert.Fail("UnauthorizedAccessException should've been thrown");
}
[Test]
public void Can_call_HttpGetHandler_with_HttpGet_request()
{
ServiceControllerContext.AssertServiceRestrictions(
new HttpGetHandler(), EndpointAttributes.External | EndpointAttributes.HttpGet | EndpointAttributes.InSecure, "name");
}
[Test]
public void Cannot_call_HttpGetHandler_with_HttpPost_request()
{
try
{
ServiceControllerContext.AssertServiceRestrictions(
new HttpGetHandler(), EndpointAttributes.External | EndpointAttributes.HttpPost | EndpointAttributes.InSecure, "name");
}
catch (UnauthorizedAccessException uae)
{
Assert.That(uae.Message.Contains(string.Format("'{0}'", EndpointAttributes.HttpGet)));
return;
}
Assert.Fail("UnauthorizedAccessException should've been thrown");
}
}
}