annotate Stocks/Stocks.Service.Tests.Unit/StockServiceTests.cs @ 0:e5d46bb6cdb0

Initial commit
author adminSH stevenhollidge@hotmail.com
date Mon, 20 Feb 2012 13:52:35 +0700
parents
children 29ed98d659e9
rev   line source
0
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
1 using System;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
2 using System.Collections.Generic;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
3 using System.Linq;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
4 using System.Text;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
5 using Xunit;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
6 using Stocks.Common;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
7 using System.Threading.Tasks;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
8 using System.Threading;
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
9
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
10 namespace Stocks.Service.Tests.Unit
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
11 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
12 public class StockServiceTests
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
13 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
14 [Fact]
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
15 public void Service_IsActive_property()
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
16 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
17 var file = "../../../Stocks.Service/companyData.json";
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
18 var service = new StocksService(new ConfigurationService(file));
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
19
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
20 using (var task = Task.Factory.StartNew(() =>
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
21 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
22 Assert.Equal(false, service.IsActive);
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
23 service.Start();
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
24 Assert.Equal(true, service.IsActive);
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
25 using (var task2 = Task.Factory.StartNew(() => Thread.Sleep(500)))
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
26 { task2.Wait(); }
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
27 service.Stop();
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
28 Assert.Equal(false, service.IsActive);
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
29 }))
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
30 {
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
31 task.Wait();
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
32 }
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
33 }
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
34 }
e5d46bb6cdb0 Initial commit
adminSH stevenhollidge@hotmail.com
parents:
diff changeset
35 }