コード例 #1
0
 /// <summary>
 ///     Creates an <see cref="Assertion" /> that ensure object properties/fields of the specified instance did not change,
 ///     except the specified ones,
 ///     in the Act part of your test.
 /// </summary>
 /// <param name="_">The dummy place holder for all Smart Assertions.</param>
 /// <param name="instance">The instance for which to test public property changes.</param>
 /// <param name="kind">The kind of members and visibility to check for changes.</param>
 /// <param name="exceptions">The names of the properties/fields that can change during the Act.</param>
 /// <returns>The newly created <see cref="Assertion" />.</returns>
 /// <exception cref="BadTestException">
 ///     If <paramref name="exceptions" /> are not properties/fields of <paramref name="instance" />.
 /// </exception>
 /// <exception cref="SmartTestException">
 ///     If any property/field checked (see <paramref name="kind" />) of <paramref name="instance" />, except the
 ///     <paramref name="exceptions" /> have changed.
 /// </exception>
 /// <remarks>
 ///     This <see cref="Assertion" /> ensures that:
 ///     <list type="number">
 ///         <item>
 ///             <term>Before the Act</term>
 ///             <description>
 ///                 <para>
 ///                     If names in <paramref name="exceptions" /> are not properties/fields of
 ///                     <paramref name="instance" />, a <see cref="BadTestException" /> is thrown.
 ///                 </para>
 ///             </description>
 ///         </item>
 ///         <item>
 ///             <term>After the Act</term>
 ///             <description>
 ///                 <para>
 ///                     If a property/field of <paramref name="instance" /> changed during the Act (except
 ///                     <paramref name="exceptions" />), a
 ///                     <see cref="SmartTestException" /> is thrown.
 ///                 </para>
 ///             </description>
 ///         </item>
 ///     </list>
 /// </remarks>
 /// <example>
 ///     In this example, the Smart Assertion verifies that no property nor field of <c>other</c>, except <c>CopyCount</c>,
 ///     changed while calling <c>CopyPropertiesFrom</c>.
 ///     <code>
 /// [Test]
 /// public void CopyFromTest()
 /// {
 ///     var mc = new MyClass();
 ///     var other = new MyClass();
 ///
 ///     RunTest( ValidValue.IsValid,
 ///              () => mc.CopyPropertiesFrom( other ),
 ///              SmartAssert.NotChangedExcept( other, NotChangedKind.All, "CopyCount" ) );
 /// }
 /// </code>
 /// </example>
 // ReSharper disable once UnusedParameter.Global
 public static Assertion NotChangedExcept(this SmartAssertPlaceHolder _, object instance, NotChangedKind kind, params string[] exceptions) => new NotChangedAssertion(instance, kind, exceptions);
コード例 #2
0
 /// <summary>
 ///     Creates an <see cref="Assertion" /> that ensure object properties/fields did not change in the Act part of your
 ///     test.
 /// </summary>
 /// <param name="_">The dummy place holder for all Smart Assertions.</param>
 /// <param name="instance">The instance for which the properties/fields should not change.</param>
 /// <param name="kind">
 ///     The kind of tested members and their visibility. Default value is
 ///     <see cref="NotChangedKind.PublicProperties" />
 /// </param>
 /// <returns>The newly created <see cref="Assertion" />.</returns>
 /// <exception cref="SmartTestException">
 ///     If any member, of <paramref name="instance" />, described by <paramref name="kind" /> has changed.
 /// </exception>
 /// <remarks>
 ///     This <see cref="Assertion" /> ensures that:
 ///     <list type="number">
 ///         <item>
 ///             <term>Before the Act</term>
 ///             <description>
 ///                 <para>Nothing special.</para>
 ///             </description>
 ///         </item>
 ///         <item>
 ///             <term>After the Act</term>
 ///             <description>
 ///                 <para>
 ///                     If any of the specified members (using <paramref name="kind" />) has changed, a
 ///                     <see cref="SmartTestException" /> is thrown.
 ///                 </para>
 ///             </description>
 ///         </item>
 ///     </list>
 /// </remarks>
 /// <example>
 ///     In this example, the Smart Assertion verifies that no property nor field of <c>other</c> changed while invoking
 ///     <c>CopyFrom</c>.
 ///     <code>
 /// [Test]
 /// public void CopyFromTest()
 /// {
 ///     var mc = new MyClass();
 ///     var other = new MyClass();
 ///     RunTest( ValidValue.IsValid,
 ///              () => mc.CopyFrom( other ),
 ///              SmartAssert.NotChanged( other, NotChangedKind.All ) );
 /// }
 /// </code>
 /// </example>
 // ReSharper disable once UnusedParameter.Global
 public static Assertion NotChanged(this SmartAssertPlaceHolder _, object instance, NotChangedKind kind = NotChangedKind.PublicProperties) => new NotChangedAssertion(instance, kind, null);
コード例 #3
0
 public NotChangedAssertion(object instance, NotChangedKind kind, string[] exceptions)
 {
     _Instance   = instance;
     _Kind       = kind;
     _Exceptions = exceptions;
 }
コード例 #4
0
        /// <summary>
        ///     Creates an <see cref="Assertion" /> that ensure object properties/fields of the specified instance did not change, except the specified ones,
        ///     in the Act part of your test.
        /// </summary>
        /// <typeparam name="T">The <see cref="Type"/> of the expression that can change.</typeparam>
        /// <param name="this">The dummy place holder for all Smart Assertions.</param>
        /// <param name="expression">The expression of an instance and a property/field.</param>
        /// <param name="kind">The kind of members and visibility to check for changes. Default value is <see cref="NotChangedKind.PublicProperties"/>.</param>
        /// <returns>The newly created <see cref="Assertion" />.</returns>
        /// <exception cref="SmartTestException">
        ///     If any property/field checked (see <paramref name="kind" />) of the instance in <paramref name="expression"/>, except the
        ///     property/field in <paramref name="expression" /> has changed.
        /// </exception>
        /// <remarks>
        ///     This <see cref="Assertion" /> ensures that:
        ///     <list type="number">
        ///         <item>
        ///             <term>Before the Act</term>
        ///             <description>
        ///                 <para>
        ///                     Nothing special.
        ///                 </para>
        ///             </description>
        ///         </item>
        ///         <item>
        ///             <term>After the Act</term>
        ///             <description>
        ///                 <para>
        ///                     If a property/field of the instance in <paramref name="expression"/> changed during the Act (except the property/field in <paramref name="expression" />), a
        ///                     <see cref="SmartTestException" /> is thrown.
        ///                 </para>
        ///             </description>
        ///         </item>
        ///     </list>
        /// </remarks>
        /// <example>
        ///     In this example, the Smart Assertion verifies that no property nor field of <c>other</c>, except <c>CopyCount</c>,
        ///     changed while calling <c>CopyPropertiesFrom</c>.
        ///     <code>
        /// [Test]
        /// public void CopyPropertiesFromTest()
        /// {
        ///     var mc = new MyClass();
        ///     var other = new MyClass();
        ///
        ///     RunTest( ValidValue.IsValid,
        ///              () => mc.CopyPropertiesFrom( other ),
        ///              SmartAssert.NotChangedExcept( () => other.CopyCount, NotChangedKind.All ) );
        /// }
        /// </code>
        /// </example>
        public static Assertion NotChangedExcept <T>(this SmartAssertPlaceHolder @this, Expression <Func <T> > expression, NotChangedKind kind = NotChangedKind.PublicProperties)
        {
            object       instance;
            PropertyInfo property;

            GetInstanceAndProperty(expression, out instance, out property);
            return(new NotChangedAssertion(instance, kind, new[] { property.Name }));
        }
コード例 #5
0
 /// <summary>
 ///     Creates an <see cref="Assertion" /> that ensure object properties/fields did not change, except the specified ones,
 ///     in the Act part of your test.
 /// </summary>
 /// <param name="this">The dummy place holder for all Smart Assertions.</param>
 /// <param name="kind">The kind of members and visibility to check for changes.</param>
 /// <param name="exceptions">The names of the properties/fields that can change during the Act.</param>
 /// <returns>The newly created <see cref="Assertion" />.</returns>
 /// <exception cref="BadTestException">
 ///     If <paramref name="exceptions" /> are not properties/fields of the instance involve in the Act.
 /// </exception>
 /// <exception cref="SmartTestException">
 ///     If any property/field checked (see <paramref name="kind" />), of the instance involved in the Act, except the
 ///     <paramref name="exceptions" />
 ///     have changed.
 /// </exception>
 /// <remarks>
 ///     This <see cref="Assertion" /> ensures that:
 ///     <list type="number">
 ///         <item>
 ///             <term>Before the Act</term>
 ///             <description>
 ///                 <para>
 ///                     If names in <paramref name="exceptions" /> are not properties/fields of the instance involved in
 ///                     the Act, a <see cref="BadTestException" /> is thrown.
 ///                 </para>
 ///             </description>
 ///         </item>
 ///         <item>
 ///             <term>After the Act</term>
 ///             <description>
 ///                 <para>
 ///                     If a property/field changed during the Act (except <paramref name="exceptions" />), a
 ///                     <see cref="SmartTestException" /> is thrown.
 ///                 </para>
 ///             </description>
 ///         </item>
 ///     </list>
 /// </remarks>
 /// <example>
 ///     In this example, the Smart Assertion verifies that no property nor field of <c>mc</c>, except <c>MyProperty</c> and
 ///     <c>OtherProperty</c>
 ///     changed while calling <c>MyMethod</c>.
 ///     <code>
 /// [Test]
 /// public void CopyFromTest()
 /// {
 ///     var mc = new MyClass();
 ///     RunTest( ValidValue.IsValid,
 ///              () => mc.MyMethod(),
 ///              SmartAssert.NotChangedExcept( NotChangedKind.All, "MyProperty", "OtherProperty" ) );
 /// }
 /// </code>
 /// </example>
 public static Assertion NotChangedExcept(this SmartAssertPlaceHolder @this, NotChangedKind kind, params string[] exceptions) => new NotChangedAssertion(null, kind, exceptions);
コード例 #6
0
 /// <summary>
 ///     Creates an <see cref="Assertion" /> that ensure object properties/fields did not change in the Act part of your
 ///     test.
 /// </summary>
 /// <param name="this">The dummy place holder for all Smart Assertions.</param>
 /// <param name="kind">
 ///     The kind of tested members and their visibility. Default value is
 ///     <see cref="NotChangedKind.PublicProperties" />
 /// </param>
 /// <returns>The newly created <see cref="Assertion" />.</returns>
 /// <exception cref="SmartTestException">
 ///     If any member, of the instance involved in the Act, described by <paramref name="kind" /> has changed.
 /// </exception>
 /// <remarks>
 ///     This <see cref="Assertion" /> ensures that:
 ///     <list type="number">
 ///         <item>
 ///             <term>Before the Act</term>
 ///             <description>
 ///                 <para>Nothing special.</para>
 ///             </description>
 ///         </item>
 ///         <item>
 ///             <term>After the Act</term>
 ///             <description>
 ///                 <para>
 ///                     If any of the specified members (using <paramref name="kind" />) has changed, a
 ///                     <see cref="SmartTestException" /> is thrown.
 ///                 </para>
 ///             </description>
 ///         </item>
 ///     </list>
 /// </remarks>
 /// <example>
 ///     In this example, the Smart Assertion verifies that no property nor field of <c>mc</c> changed while invoking
 ///     <c>MyMethod</c>.
 ///     <code>
 /// [Test]
 /// public void CopyFromTest()
 /// {
 ///     var mc = new MyClass();
 ///     RunTest( ValidValue.IsValid,
 ///              () => mc.MyMethod(),
 ///              SmartAssert.NotChanged( NotChangedKind.All ) );
 /// }
 /// </code>
 /// </example>
 public static Assertion NotChanged(this SmartAssertPlaceHolder @this, NotChangedKind kind = NotChangedKind.PublicProperties) => new NotChangedAssertion(null, kind, null);