markus / ConvertService / ServiceBase / ServiceUnitTest / WcfServiceTest.cs @ bc28fe10
이력 | 보기 | 이력해설 | 다운로드 (2.03 KB)
1 | 53c9637d | taeseongkim | using System; |
---|---|---|---|
2 | using System.ServiceModel; |
||
3 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
||
4 | |||
5 | namespace ServiceUnitTest |
||
6 | { |
||
7 | [TestClass] |
||
8 | public class WcfServiceTest |
||
9 | { |
||
10 | [TestMethod] |
||
11 | public void ServiceOpenTest() |
||
12 | { |
||
13 | Markus.Service.ServiceStation serviceStation = new Markus.Service.ServiceStation(); |
||
14 | PrivateObject station = new PrivateObject(serviceStation); |
||
15 | CommunicationState result = (CommunicationState)station.Invoke("StartWcfService"); |
||
16 | |||
17 | Console.WriteLine($"Service State : {result}"); |
||
18 | Assert.IsTrue(result == System.ServiceModel.CommunicationState.Opened); |
||
19 | |||
20 | result = (CommunicationState)station.Invoke("StopWcfService"); |
||
21 | |||
22 | Console.WriteLine($"Service State : {result}"); |
||
23 | Assert.IsTrue(result == System.ServiceModel.CommunicationState.Closed); |
||
24 | } |
||
25 | |||
26 | [TestMethod] |
||
27 | public void CallConvertAddTest() |
||
28 | { |
||
29 | Markus.Service.ServiceStation serviceStation = new Markus.Service.ServiceStation(); |
||
30 | PrivateObject station = new PrivateObject(serviceStation); |
||
31 | CommunicationState state = (CommunicationState)station.Invoke("StartWcfService"); |
||
32 | |||
33 | Console.WriteLine($"Service State : {state}"); |
||
34 | |||
35 | if (state == System.ServiceModel.CommunicationState.Opened) |
||
36 | { |
||
37 | ConvertService.ConvertServiceClient serviceClient = new ConvertService.ConvertServiceClient(); |
||
38 | var result = serviceClient.ConvertAdd(1); |
||
39 | |||
40 | Console.WriteLine(result); |
||
41 | Assert.IsNotNull(result); |
||
42 | |||
43 | |||
44 | state = (CommunicationState)station.Invoke("StopWcfService"); |
||
45 | |||
46 | Console.WriteLine($"Service State : {state}"); |
||
47 | Assert.IsTrue(state == System.ServiceModel.CommunicationState.Closed); |
||
48 | } |
||
49 | else |
||
50 | { |
||
51 | Console.WriteLine($"Error ServiceState{state}"); |
||
52 | Assert.IsTrue(state == System.ServiceModel.CommunicationState.Opened); |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | } |