view 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
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Stocks.Common;
using System.Threading.Tasks;
using System.Threading;

namespace Stocks.Service.Tests.Unit
{
  public class StockServiceTests
  {
    [Fact]
    public void Service_IsActive_property()
    {
      var file = "../../../Stocks.Service/companyData.json";
      var service = new StocksService(new ConfigurationService(file));

      using (var task = Task.Factory.StartNew(() =>
        {
          Assert.Equal(false, service.IsActive);
          service.Start();
          Assert.Equal(true, service.IsActive);
          using (var task2 = Task.Factory.StartNew(() => Thread.Sleep(500)))
            { task2.Wait(); }
          service.Stop();
          Assert.Equal(false, service.IsActive);
        })) 
      {
        task.Wait();
      }
    }
  }
}