PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/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. //===================================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Reflection;
  20. using System.Windows.Controls;
  21. using Microsoft.VisualStudio.TestTools.UnitTesting;
  22. using StockTraderRI.Infrastructure.Converters;
  23. namespace StockTraderRI.Infrastructure.Tests.Converters
  24. {
  25. [TestClass]
  26. public class ErrorConverterFixture
  27. {
  28. [TestMethod]
  29. public void ShouldReturnEmptyStringIfValueIsNull()
  30. {
  31. ErrorConverter converter = new ErrorConverter();
  32. object errors = null;
  33. object result = converter.Convert(errors, null, null, null);
  34. Assert.AreEqual(string.Empty, result);
  35. }
  36. [TestMethod]
  37. public void ShouldReturnEmptyStringIfCollectionIsEmpty()
  38. {
  39. ErrorConverter converter = new ErrorConverter();
  40. List<ValidationError> errors = new List<ValidationError>();
  41. object result = converter.Convert(errors.AsReadOnly(), null, null, null);
  42. Assert.AreEqual(string.Empty, result);
  43. }
  44. [TestMethod]
  45. public void ShouldReturnTheExceptionMessageOfTheFirstItemInTheCollection()
  46. {
  47. ErrorConverter converter = new ErrorConverter();
  48. List<ValidationError> errors = new List<ValidationError>();
  49. ValidationError error = new ValidationError(new ExceptionValidationRule(), new object());
  50. error.Exception = new Exception("TestError");
  51. errors.Add(error);
  52. object result = converter.Convert(errors.AsReadOnly(), null, null, null);
  53. Assert.AreEqual("TestError", result);
  54. }
  55. [TestMethod]
  56. public void ShouldReturnTheInnerExceptionMessageOfATargetInvocationException()
  57. {
  58. ErrorConverter converter = new ErrorConverter();
  59. List<ValidationError> errors = new List<ValidationError>();
  60. ValidationError error = new ValidationError(new ExceptionValidationRule(), new object());
  61. error.Exception = new TargetInvocationException(null, new Exception("TestError"));
  62. errors.Add(error);
  63. object result = converter.Convert(errors.AsReadOnly(), null, null, null);
  64. Assert.AreEqual("TestError", result);
  65. }
  66. [TestMethod]
  67. public void ShouldReturnTheErrorContentOfTheFirstItemInTheCollection()
  68. {
  69. ErrorConverter converter = new ErrorConverter();
  70. List<ValidationError> errors = new List<ValidationError>();
  71. ValidationError error = new ValidationError(new ExceptionValidationRule(), new object());
  72. error.ErrorContent = "TestError";
  73. errors.Add(error);
  74. object result = converter.Convert(errors.AsReadOnly(), null, null, null);
  75. Assert.AreEqual("TestError", result);
  76. }
  77. }
  78. }