public void CustomizeWithNullFixtureShouldThrowArgumentNullException() { // Fixture setup var sut = new FreezeOnMatchCustomization(typeof(object)); // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(() => sut.Customize(null)); // Teardown }
public void SutShouldBeCustomization() { // Fixture setup // Exercise system var sut = new FreezeOnMatchCustomization(typeof(object)); // Verify outcome Assert.IsAssignableFrom<ICustomization>(sut); // Teardown }
public void InitializeWithMatcherShouldSetCorrespondingProperty() { // Fixture setup var matcher = new TrueRequestSpecification(); // Exercise system var sut = new FreezeOnMatchCustomization(typeof(object), matcher); // Verify outcome Assert.Equal(matcher, sut.Matcher); }
public void InitializeWithTargetTypeShouldSetCorrespondingProperty() { // Fixture setup var targetType = typeof(object); // Exercise system var sut = new FreezeOnMatchCustomization(typeof(object)); // Verify outcome Assert.Equal(targetType, sut.TargetType); }
public void InitializeWithTargetTypeShouldSetMatcherToMatchThatExactType() { // Fixture setup var targetType = typeof(object); // Exercise system var sut = new FreezeOnMatchCustomization(targetType); // Verify outcome var matcher = Assert.IsType<ExactTypeSpecification>(sut.Matcher); Assert.Equal(targetType, matcher.TargetType); }
public void CustomizeWithCompetingSpecimenBuilderForTheSameTypeShouldReturnTheFrozenSpecimen() { // Fixture setup var fixture = new Fixture(); var context = new SpecimenContext(fixture); var frozenType = typeof(object); var competingBuilder = new DelegatingSpecimenBuilder { OnCreate = (request, ctx) => request.Equals(frozenType) ? new object() #pragma warning disable 618 : new NoSpecimen(request) #pragma warning restore 618 }; var sut = new FreezeOnMatchCustomization( frozenType, new ExactTypeSpecification(frozenType)); // Exercise system fixture.Customizations.Add(competingBuilder); sut.Customize(fixture); // Verify outcome Assert.Equal(context.Resolve(frozenType), context.Resolve(frozenType)); }
public void FreezeByMatchingMemberNameShouldReturnSameSpecimenForMembersOfMatchingNameAndCompatibleTypes() { // Fixture setup var frozenType = typeof(ConcreteType); var fixture = new Fixture(); var sut = new FreezeOnMatchCustomization( frozenType, new OrRequestSpecification( new ParameterSpecification(frozenType, "parameter"), new PropertySpecification(frozenType, "Property"), new FieldSpecification(frozenType, "Field"))); // Exercise system sut.Customize(fixture); // Verify outcome var parameter = fixture.Create<SingleParameterType<ConcreteType>>().Parameter; var property = fixture.Create<PropertyHolder<ConcreteType>>().Property; var field = fixture.Create<FieldHolder<ConcreteType>>().Field; Assert.Same(parameter, property); Assert.Same(property, field); // Teardown }
public void FreezeByMatchingFieldNameShouldReturnDifferentSpecimensForFieldsOfSameNameAndIncompatibleTypes() { // Fixture setup var frozenType = typeof(string); var fieldName = "Field"; var fixture = new Fixture(); var sut = new FreezeOnMatchCustomization( frozenType, new FieldSpecification(frozenType, fieldName)); // Exercise system sut.Customize(fixture); // Verify outcome var frozen = fixture.Create<FieldHolder<ConcreteType>>().Field; var requested = fixture.Create<FieldHolder<ConcreteType>>().Field; Assert.NotSame(frozen, requested); // Teardown }
public void FreezeByMatchingParameterNameShouldReturnDifferentSpecimensForParametersOfSameNameAndIncompatibleTypes() { // Fixture setup var frozenType = typeof(string); var parameterName = "parameter"; var fixture = new Fixture(); var sut = new FreezeOnMatchCustomization( frozenType, new ParameterSpecification(frozenType, parameterName)); // Exercise system sut.Customize(fixture); // Verify outcome var frozen = fixture.Create<SingleParameterType<ConcreteType>>().Parameter; var requested = fixture.Create<SingleParameterType<ConcreteType>>().Parameter; Assert.NotSame(frozen, requested); // Teardown }
public void FreezeByMatchingPropertyNameShouldReturnDifferentSpecimensForPropertiesOfDifferentNamesAndSameType() { // Fixture setup var frozenType = typeof(ConcreteType); var propertyName = "SomeOtherProperty"; var fixture = new Fixture(); var sut = new FreezeOnMatchCustomization( frozenType, new PropertySpecification(frozenType, propertyName)); // Exercise system sut.Customize(fixture); // Verify outcome var frozen = fixture.Create<PropertyHolder<ConcreteType>>().Property; var requested = fixture.Create<PropertyHolder<ConcreteType>>().Property; Assert.NotSame(frozen, requested); // Teardown }
public void FreezeByMatchingPropertyNameShouldReturnSameSpecimenForPropertiesOfSameNameAndCompatibleTypes() { // Fixture setup var frozenType = typeof(ConcreteType); var propertyName = "Property"; var fixture = new Fixture(); var sut = new FreezeOnMatchCustomization( frozenType, new PropertySpecification(frozenType, propertyName)); // Exercise system sut.Customize(fixture); // Verify outcome var frozen = fixture.Create<PropertyHolder<ConcreteType>>().Property; var requested = fixture.Create<PropertyHolder<AbstractType>>().Property; Assert.Same(frozen, requested); // Teardown }
public void FreezeByMatchingImplementedInterfacesShouldReturnTheRightSpecimen( Type frozenType, Type requestedType) { // Fixture setup var fixture = new Fixture(); var context = new SpecimenContext(fixture); var sut = new FreezeOnMatchCustomization( frozenType, new ImplementedInterfaceSpecification(frozenType)); // Exercise system sut.Customize(fixture); // Verify outcome var frozen = context.Resolve(frozenType); var requested = context.Resolve(requestedType); Assert.Same(frozen, requested); // Teardown }
public void FreezeByMatchingBaseTypeShouldReturnTheRightSpecimen( Type frozenType, Type requestedType, bool areEqual) { // Fixture setup var fixture = new Fixture(); var context = new SpecimenContext(fixture); var sut = new FreezeOnMatchCustomization( frozenType, new DirectBaseTypeSpecification(frozenType)); // Exercise system sut.Customize(fixture); // Verify outcome var frozen = context.Resolve(frozenType); var requested = context.Resolve(requestedType); Assert.Equal(areEqual, frozen.Equals(requested)); // Teardown }