comparison Stocks/Stocks.Common.Tests.Unit/FactoryTests.cs @ 0:e5d46bb6cdb0

Initial commit
author adminSH stevenhollidge@hotmail.com
date Mon, 20 Feb 2012 13:52:35 +0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e5d46bb6cdb0
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Xunit;
6 using Stocks.Common.Models;
7 using Stocks.Common.Exceptions;
8
9 namespace Stocks.Common.Tests.Unit
10 {
11 public class FactoryTests
12 {
13 [Fact]
14 private void Create_for_success()
15 {
16 // "GOOG","Google Inc.",604.64
17 string value = @"""GOOG"",""Google Inc."",604.64";
18
19 var actual = Factory.CreatePrice(value);
20 var expected = new Price()
21 {
22 Symbol = "GOOG",
23 CurrentPrice = (decimal) 604.64,
24 PreviousPrice = (decimal) 604.64
25 };
26
27 Assert.Equal<Price>(expected, actual);
28 }
29
30 [Fact]
31 private void Create_for_success_with_comma_in_name()
32 {
33 // "AAPL","Apple Corp, Inc.",0.79
34 string value = @"""AAPL"",""Apple Corp, Inc"",0.79";
35
36 var actual = Factory.CreatePrice(value);
37 var expected = new Price()
38 {
39 Symbol = "AAPL",
40 CurrentPrice = (decimal) 0.79,
41 PreviousPrice = (decimal) 0.79
42 };
43
44 Assert.Equal<Price>(expected, actual);
45 }
46
47
48 [Fact]
49 private void Create_for_success_with_single_char_symbol()
50 {
51 // "X","Tiny",0
52 string value = @"""X"",""Tiny"",0";
53
54 var actual = Factory.CreatePrice(value);
55 var expected = new Price()
56 {
57 Symbol = "X",
58 CurrentPrice = (decimal)0,
59 PreviousPrice = 0
60 };
61
62 Assert.Equal<Price>(expected, actual);
63 }
64 [Fact]
65 private void Create_for_success_with_zero_price()
66 {
67 // "XXXX","Beer Co",0
68 string value = @"""XXXX"",""Beer Co"",0";
69
70 var actual = Factory.CreatePrice(value);
71 var expected = new Price()
72 {
73 Symbol = "XXXX",
74 CurrentPrice = (decimal)0,
75 PreviousPrice = 0
76 };
77
78 Assert.Equal<Price>(expected, actual);
79 }
80 [Fact]
81 private void Create_with_missing_format_variable_raises_exception()
82 {
83 string value = "Missing Format Variable.";
84 Assert.Throws<InvalidWebPriceDataException>(
85 () => Factory.CreatePrice(value));
86 }
87
88 [Fact]
89 private void Create_with_empty_raises_exception()
90 {
91 string value = string.Empty;
92 Assert.Throws<InvalidWebPriceDataException>(
93 () => Factory.CreatePrice(value));
94 }
95
96 [Fact]
97 private void Create_with_null_raises_exception()
98 {
99 string value = null;
100 Assert.Throws<InvalidWebPriceDataException>(
101 () => Factory.CreatePrice(value));
102 }
103 }
104 }