comparison Stocks/Stocks.Service.Tests.Unit/StockServiceTests.cs @ 6:c812bca7b1ac

"Restore packages on build" enabled by Nuget 1.6 General refactoring based on code analysis
author stevenh7776 stevenhollidge@hotmail.com
date Tue, 21 Feb 2012 01:00:34 +0700
parents 57f20ba55884
children
comparison
equal deleted inserted replaced
5:877d70fb8176 6:c812bca7b1ac
1 using System; 1 using System.Net;
2 using System.Collections.Generic; 2 using System.Threading;
3 using System.Linq; 3 using System.Threading.Tasks;
4 using System.Text; 4 using Stocks.Common;
5 using Xunit; 5 using Xunit;
6 using Stocks.Common;
7 using System.Threading.Tasks;
8 using System.Threading;
9 using System.Net;
10 6
11 namespace Stocks.Service.Tests.Unit 7 namespace Stocks.Service.Tests.Unit
12 { 8 {
13 public class StockServiceTests 9 public class StockServiceTests
14 { 10 {
15 [Fact] 11 [Fact]
16 public void Service_IsActive_property() 12 public void Service_IsActive_property()
17 { 13 {
18 var file = "../../../Stocks.Service/companyData.json"; 14 var file = "../../../Stocks.Service/companyData.json";
19 var configurationService = new ConfigurationService(file); 15 var configurationService = new ConfigurationService(file);
20 var webClientShim = new WebClientShim(new WebClient()); 16 using (var webClientShim = new WebClientShim(new WebClient()))
21 17 {
22 var service = new StocksService(
23 configurationService,
24 webClientShim);
25 18
26 Assert.Equal(false, service.IsActive); 19 var service = new StocksService(
20 configurationService,
21 webClientShim);
27 22
28 using (var task = Task.Factory.StartNew(() => 23 Assert.Equal(false, service.IsActive);
24
25 using (var task = Task.Factory.StartNew(() =>
26 {
27 service.Start();
28 Assert.Equal(true, service.IsActive);
29
30 using (var task2 = Task.Factory.StartNew(() => Thread.Sleep(50)))
31 { task2.Wait(); }
32 service.Stop();
33 Assert.Equal(false, service.IsActive);
34 }))
29 { 35 {
30 service.Start(); 36 task.Wait();
31 Assert.Equal(true, service.IsActive); 37 }
32
33 using (var task2 = Task.Factory.StartNew(() => Thread.Sleep(50)))
34 { task2.Wait(); }
35 service.Stop();
36 Assert.Equal(false, service.IsActive);
37 }))
38 {
39 task.Wait();
40 } 38 }
41 } 39 }
42 } 40 }
43 } 41 }