/V1/trunk/Source/StockTraderRI/StockTraderRI.Infrastructure.Tests/Converters/TwoDecimalPlaceConverterFixture.cs

# · C# · 58 lines · 34 code · 8 blank · 16 comment · 0 complexity · 913a9a7097ec59963eb4660f2c45f2d7 MD5 · raw file

  1. //===============================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation
  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.Linq;
  20. using System.Text;
  21. using Microsoft.VisualStudio.TestTools.UnitTesting;
  22. using StockTraderRI.Infrastructure.Converters;
  23. namespace StockTraderRI.Infrastructure.Tests.Converters
  24. {
  25. [TestClass]
  26. public class TwoDecimalPlaceConverterFixture
  27. {
  28. [TestMethod]
  29. public void TwoDecimalPlaceConverterRoundsToTwoDecimals()
  30. {
  31. TwoDecimalPlaceConverter converter = new TwoDecimalPlaceConverter();
  32. object value = converter.Convert(123.45678M, typeof(decimal), 2, null);
  33. Assert.AreEqual<decimal>(123.46M, Convert.ToDecimal(value));
  34. }
  35. [ExpectedException(typeof(ArgumentException))]
  36. [TestMethod]
  37. public void OnlyAcceptsDecimalValueArgument()
  38. {
  39. TwoDecimalPlaceConverter converter = new TwoDecimalPlaceConverter();
  40. converter.Convert("hello", null, 2, null);
  41. }
  42. [ExpectedException(typeof(ArgumentException))]
  43. [TestMethod]
  44. public void OnlyAcceptsIntegerNumDigitsArgument()
  45. {
  46. TwoDecimalPlaceConverter converter = new TwoDecimalPlaceConverter();
  47. converter.Convert(123.4467M, null, "foo", null);
  48. }
  49. }
  50. }