/Release/Silverlight4/Source/Controls.Testing.Common/OverriddenMethod/OverriddenMethod.Quadruple.cs

# · C# · 101 lines · 52 code · 10 blank · 39 comment · 2 complexity · d7280d75da63246ae8135cfe39df3762 MD5 · raw file

  1. // (c) Copyright Microsoft Corporation.
  2. // This source is subject to the Microsoft Public License (Ms-PL).
  3. // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
  4. // All other rights reserved.
  5. using System;
  6. using System.Diagnostics.CodeAnalysis;
  7. namespace System.Windows.Controls.Testing
  8. {
  9. /// <summary>
  10. /// Overridden method tests for methods with 3 parameters.
  11. /// </summary>
  12. /// <typeparam name="T1">Type of the method's first parameter.</typeparam>
  13. /// <typeparam name="T2">Type of the method's second parameter.</typeparam>
  14. /// <typeparam name="T3">Type of the method's third parameter.</typeparam>
  15. /// <typeparam name="T4">Type of the method's fourth parameter.</typeparam>
  16. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "1", Justification = "Folling Action and Func pattern")]
  17. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "2", Justification = "Folling Action and Func pattern")]
  18. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "3", Justification = "Folling Action and Func pattern")]
  19. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "4", Justification = "Folling Action and Func pattern")]
  20. [SuppressMessage("Microsoft.Design", "CA1005:AvoidExcessiveParametersOnGenericTypes", Justification = "Folling Action and Func pattern")]
  21. public sealed partial class OverriddenMethod<T1, T2, T3, T4> : OverriddenMethodBase
  22. {
  23. /// <summary>
  24. /// Test action to perform before the base implementation is invoked.
  25. /// </summary>
  26. [SuppressMessage("Microsoft.Design", "CA1009:DeclareEventHandlersCorrectly", Justification = "Event used for testing.")]
  27. [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "Event used for testing.")]
  28. [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "PreTest", Justification = "The naming is intentional.")]
  29. public event Action<T1, T2, T3, T4> PreTest;
  30. /// <summary>
  31. /// Test action to perform after the base implementation was invoked.
  32. /// </summary>
  33. [SuppressMessage("Microsoft.Design", "CA1009:DeclareEventHandlersCorrectly", Justification = "Event used for testing.")]
  34. [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "Event used for testing.")]
  35. public event Action<T1, T2, T3, T4> Test;
  36. /// <summary>
  37. /// Initializes a new instance of the OverriddenMethod class.
  38. /// </summary>
  39. public OverriddenMethod()
  40. : this(null)
  41. {
  42. }
  43. /// <summary>
  44. /// Initializes a new instance of the OverriddenMethod class.
  45. /// </summary>
  46. /// <param name="invariantTest">
  47. /// Test action to perform before and after the other tests.
  48. /// </param>
  49. public OverriddenMethod(Action invariantTest)
  50. : base(invariantTest)
  51. {
  52. }
  53. /// <summary>
  54. /// Invoke the test action.
  55. /// </summary>
  56. /// <param name="test">Test action to invoke.</param>
  57. /// <param name="parameters">Parameters to the test action.</param>
  58. private void InvokeTest(Action<T1, T2, T3, T4> test, object[] parameters)
  59. {
  60. DoInvariantTest();
  61. ValidateParameters(parameters, 4);
  62. T1 first = GetParameter<T1>(parameters, 0);
  63. T2 second = GetParameter<T2>(parameters, 1);
  64. T3 third = GetParameter<T3>(parameters, 2);
  65. T4 fourth = GetParameter<T4>(parameters, 3);
  66. if (test != null)
  67. {
  68. test(first, second, third, fourth);
  69. }
  70. DoInvariantTest();
  71. }
  72. /// <summary>
  73. /// Perform the test action before the base implementation is invoked.
  74. /// </summary>
  75. /// <param name="parameters">Parameters to the test action.</param>
  76. public override void DoPreTest(params object[] parameters)
  77. {
  78. base.DoPreTest();
  79. InvokeTest(PreTest, parameters);
  80. }
  81. /// <summary>
  82. /// Perform the test action after the base implementation was invoked.
  83. /// </summary>
  84. /// <param name="parameters">Parameters to the test action.</param>
  85. public override void DoTest(params object[] parameters)
  86. {
  87. base.DoTest();
  88. InvokeTest(Test, parameters);
  89. }
  90. }
  91. }