Class CopyAndUpdateAssertion
Namespace: AutoFixture.Idioms
Assembly: AutoFixture.Idioms.dll
Encapsulates a unit test which verifies a method correctly makes a copy of an object while updating one or more public properties or fields.
public class CopyAndUpdateAssertion : IdiomaticAssertion, IIdiomaticAssertionInheritance
object ← IdiomaticAssertion ← CopyAndUpdateAssertion
Implements
Inherited Members
IdiomaticAssertion.Verify(params Assembly[]), IdiomaticAssertion.Verify(IEnumerable<Assembly>), IdiomaticAssertion.Verify(Assembly), IdiomaticAssertion.Verify(params Type[]), IdiomaticAssertion.Verify(IEnumerable<Type>), IdiomaticAssertion.Verify(Type), IdiomaticAssertion.Verify(params MemberInfo[]), IdiomaticAssertion.Verify(IEnumerable<MemberInfo>), IdiomaticAssertion.Verify(MemberInfo), IdiomaticAssertion.Verify(params ConstructorInfo[]), IdiomaticAssertion.Verify(IEnumerable<ConstructorInfo>), IdiomaticAssertion.Verify(FieldInfo), IdiomaticAssertion.Verify(params FieldInfo[]), IdiomaticAssertion.Verify(IEnumerable<FieldInfo>), IdiomaticAssertion.Verify(ConstructorInfo), IdiomaticAssertion.Verify(params MethodInfo[]), IdiomaticAssertion.Verify(IEnumerable<MethodInfo>), IdiomaticAssertion.Verify(MethodInfo), IdiomaticAssertion.Verify(params PropertyInfo[]), IdiomaticAssertion.Verify(IEnumerable<PropertyInfo>), IdiomaticAssertion.Verify(PropertyInfo), object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
When dealing with immutable types, it can be useful to add a convenience method to change a single field/property in a more complex object; e.g.
public Foo WithBar(Bar newBar)
{
return new Foo(this.baz, newBar, this.qux);
}
Testing this not only requires verification that newBar was properly used (and exposed as a field or Inspection Property), but that all other values contained by Foo are held constant.
Constructors
CopyAndUpdateAssertion(ISpecimenBuilder, IEqualityComparer, IEqualityComparer<IReflectionElement>)
Initializes a new instance of the CopyAndUpdateAssertion class.
public CopyAndUpdateAssertion(ISpecimenBuilder builder, IEqualityComparer comparer, IEqualityComparer<IReflectionElement> parameterMemberMatcher)Parameters
builder ISpecimenBuilder
A composer which can create instances required to implement the idiomatic unit test.
comparer IEqualityComparer
A comparer that compares public member values from the specimen with public member values from the 'copied' and updated' instance.
parameterMemberMatcher IEqualityComparer<IReflectionElement>
Allows customizing the way 'updated' parameters
are matched to members. The boolean value returned from
Equals(%600%2c%600) indicates if the parameter and member
are matched.
Remarks
builder will typically be a `Fixture` instance.
CopyAndUpdateAssertion(ISpecimenBuilder, IEqualityComparer)
Initializes a new instance of the CopyAndUpdateAssertion class.
public CopyAndUpdateAssertion(ISpecimenBuilder builder, IEqualityComparer comparer)Parameters
builder ISpecimenBuilder
A composer which can create instances required to implement the idiomatic unit test.
comparer IEqualityComparer
A comparer that compares public member values from the specimen with public member values from the 'copied' and updated' instance.
Remarks
builder will typically be a `Fixture` instance.
CopyAndUpdateAssertion(ISpecimenBuilder)
Initializes a new instance of the CopyAndUpdateAssertion class.
public CopyAndUpdateAssertion(ISpecimenBuilder builder)Parameters
builder ISpecimenBuilder
A composer which can create instances required to implement the idiomatic unit test.
Remarks
builder will typically be a `Fixture` instance.
Properties
Builder
Gets the builder supplied by the constructor.
public ISpecimenBuilder Builder { get; }Property Value
ISpecimenBuilder
Comparer
Gets the comparer that tests for equality of the values on the specimen and the 'copied and updated' specimen.
public IEqualityComparer Comparer { get; }Property Value
ParameterMemberMatcher
Gets the comparer instance which is used to determine if a 'copy and update' method parameter matches a given public member (property or field).
public IEqualityComparer<IReflectionElement> ParameterMemberMatcher { get; }Property Value
IEqualityComparer<IReflectionElement>
Remarks
If the parameter and member are matched, the member is expected to be initialized
from the value given to the parameter. A return value of true from
the Equals(%600%2c%600) method means the parameter and
member are 'matched'.
Methods
Verify(MethodInfo)
Verifies that a method correctly makes a copy of an object while changing one or more public properties or fields.
public override void Verify(MethodInfo methodInfo)Parameters
methodInfo MethodInfo
The 'copy and update' method to verify.