Class ConstructorInitializedMemberAssertion
Namespace: AutoFixture.Idioms
Assembly: AutoFixture.Idioms.dll
Encapsulates a unit test that verifies that a member (property or field) is correctly initialized by the constructor.
public class ConstructorInitializedMemberAssertion : IdiomaticAssertion, IIdiomaticAssertionInheritance
object ← IdiomaticAssertion ← ConstructorInitializedMemberAssertion
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()
Constructors
ConstructorInitializedMemberAssertion(ISpecimenBuilder, IEqualityComparer, IEqualityComparer<IReflectionElement>)
Initializes a new instance of the ConstructorInitializedMemberAssertion class.
public ConstructorInitializedMemberAssertion(ISpecimenBuilder builder, IEqualityComparer comparer, IEqualityComparer<IReflectionElement> parameterMemberMatcher)Parameters
builder ISpecimenBuilder
A composer which can create instances required to implement the idiomatic unit test, such as the owner of the property, as well as the value to be assigned and read from the member.
comparer IEqualityComparer
An IEqualityComparer instance, which is used
to determine if each member has the same value which was passed to the matching
constructor parameter.
parameterMemberMatcher IEqualityComparer<IReflectionElement>
Provides a way to customize the way 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.
ConstructorInitializedMemberAssertion(ISpecimenBuilder)
Initializes a new instance of the ConstructorInitializedMemberAssertion class.
public ConstructorInitializedMemberAssertion(ISpecimenBuilder builder)Parameters
builder ISpecimenBuilder
A composer which can create instances required to implement the idiomatic unit test, such as the owner of the property, as well as the value to be assigned and read from the member.
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 supplied to the constructor.
public IEqualityComparer Comparer { get; }Property Value
Remarks
This comparer instance is used to determine if all of the value retrieved from the members are equal to their corresponding 'matched' constructor parameter.
ParameterMemberMatcher
Gets the IEqualityComparer%601 instance which is
used to determine if a constructor parameter matches a given 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 passed into the matching constructor parameter.
Methods
Verify(ConstructorInfo)
Verifies that all constructor arguments are properly exposed as either fields or properties.
public override void Verify(ConstructorInfo constructorInfo)Parameters
constructorInfo ConstructorInfo
The constructor.
Verify(PropertyInfo)
Verifies that a property is correctly initialized by the constructor.
public override void Verify(PropertyInfo propertyInfo)Parameters
propertyInfo PropertyInfo
The property.
Remarks
This method verifies that the propertyInfo is correctly initialized with
the value given to the same-named constructor parameter. It uses the `Builder` to
supply values to the constructor(s) of the Type on which the field is implemented, and then
reads from the field. The assertion passes if the value read from the property is the same as
the value passed to the constructor. If more than one constructor has an argument with the
same name and type, all constructors are checked. If any constructor (with a matching argument)
does not initialise the property with the correct value, a
`ConstructorInitializedMemberException` is thrown.
Exceptions
The verification fails.
Verify(FieldInfo)
Verifies that a field is correctly initialized by the constructor.
public override void Verify(FieldInfo fieldInfo)Parameters
fieldInfo FieldInfo
The field.
Remarks
This method verifies that fieldInfo is correctly initialized with the
value given to the same-named constructor parameter. It uses the `Builder` to
supply values to the constructor(s) of the Type on which the field is implemented, and then
reads from the field. The assertion passes if the value read from the field is the same as
the value passed to the constructor. If more than one constructor has an argument with the
same name and type, all constructors are checked. If any constructor does not initialise
the field with the correct value, a `ConstructorInitializedMemberException`
is thrown.
Exceptions
ConstructorInitializedMemberException
The verification fails.