PageRenderTime 29ms CodeModel.GetById 14ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/V2/trunk/RI/Desktop/StockTraderRI.Infrastructure.Tests/Converters/ErrorConverterFixture.cs

#
C# | 97 lines | 62 code | 19 blank | 16 comment | 0 complexity | 2935eac32faad4612b1fe4187651961f MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using System.Collections.Generic;
19using System.Reflection;
20using System.Windows.Controls;
21using Microsoft.VisualStudio.TestTools.UnitTesting;
22using StockTraderRI.Infrastructure.Converters;
23
24namespace StockTraderRI.Infrastructure.Tests.Converters
25{
26    [TestClass]
27    public class ErrorConverterFixture
28    {
29        [TestMethod]
30        public void ShouldReturnEmptyStringIfValueIsNull()
31        {
32            ErrorConverter converter = new ErrorConverter();
33            object errors = null;
34
35            object result = converter.Convert(errors, null, null, null);
36
37            Assert.AreEqual(string.Empty, result);
38        }
39
40        [TestMethod]
41        public void ShouldReturnEmptyStringIfCollectionIsEmpty()
42        {
43            ErrorConverter converter = new ErrorConverter();
44
45            List<ValidationError> errors = new List<ValidationError>();
46
47            object result = converter.Convert(errors.AsReadOnly(), null, null, null);
48
49            Assert.AreEqual(string.Empty, result);
50        }
51
52        [TestMethod]
53        public void ShouldReturnTheExceptionMessageOfTheFirstItemInTheCollection()
54        {
55            ErrorConverter converter = new ErrorConverter();
56
57            List<ValidationError> errors = new List<ValidationError>();
58            ValidationError error = new ValidationError(new ExceptionValidationRule(), new object());
59            error.Exception = new Exception("TestError");
60            errors.Add(error);
61
62            object result = converter.Convert(errors.AsReadOnly(), null, null, null);
63
64            Assert.AreEqual("TestError", result);
65        }
66
67        [TestMethod]
68        public void ShouldReturnTheInnerExceptionMessageOfATargetInvocationException()
69        {
70            ErrorConverter converter = new ErrorConverter();
71
72            List<ValidationError> errors = new List<ValidationError>();
73            ValidationError error = new ValidationError(new ExceptionValidationRule(), new object());
74            error.Exception = new TargetInvocationException(null, new Exception("TestError"));
75            errors.Add(error);
76
77            object result = converter.Convert(errors.AsReadOnly(), null, null, null);
78
79            Assert.AreEqual("TestError", result);
80        }
81
82        [TestMethod]
83        public void ShouldReturnTheErrorContentOfTheFirstItemInTheCollection()
84        {
85            ErrorConverter converter = new ErrorConverter();
86
87            List<ValidationError> errors = new List<ValidationError>();
88            ValidationError error = new ValidationError(new ExceptionValidationRule(), new object());
89            error.ErrorContent = "TestError";
90            errors.Add(error);
91
92            object result = converter.Convert(errors.AsReadOnly(), null, null, null);
93
94            Assert.AreEqual("TestError", result);
95        }
96    }
97}