public void CustomizeWithNullFixtureShouldThrowArgumentNullException() { // Arrange var sut = new FreezeOnMatchCustomization(typeof(object)); // Act & assert Assert.Throws <ArgumentNullException>(() => sut.Customize(null)); }
public void InitializeWithMatcherShouldSetCorrespondingProperty() { // Arrange var matcher = new TrueRequestSpecification(); // Act var sut = new FreezeOnMatchCustomization(typeof(object), matcher); // Assert Assert.Equal(matcher, sut.Matcher); }
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 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 InitializeWithTargetTypeAndMatcherShouldSetCorrespondingProperty() { var targetType = typeof(object); var matcher = new TrueRequestSpecification(); var sut = new FreezeOnMatchCustomization(typeof(object), matcher); #pragma warning disable 618 Assert.Equal(targetType, sut.TargetType); #pragma warning restore 618 }
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 SutShouldBeCustomization() { // Fixture setup // Exercise system var sut = new FreezeOnMatchCustomization(typeof(object)); // Verify outcome Assert.IsAssignableFrom <ICustomization>(sut); // Teardown }
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 InitializeWithTargetTypeShouldSetCorrespondingProperty() { // Arrange var targetType = typeof(object); // Act var sut = new FreezeOnMatchCustomization(typeof(object)); // Assert #pragma warning disable 618 Assert.Equal(targetType, sut.TargetType); #pragma warning restore 618 }
public void FreezeByMatchingPropertyNameShouldReturnDifferentSpecimensForPropertiesOfSameNameAndIncompatibleTypes() { // Arrange var frozenType = typeof(string); var propertyName = "Property"; var fixture = new Fixture(); var sut = new FreezeOnMatchCustomization( frozenType, new PropertySpecification(frozenType, propertyName)); // Act sut.Customize(fixture); // Assert var frozen = fixture.Create <PropertyHolder <ConcreteType> >().Property; var requested = fixture.Create <PropertyHolder <ConcreteType> >().Property; Assert.NotSame(frozen, requested); }
public void FreezeByMatchingFieldNameShouldReturnDifferentSpecimensForFieldsOfSameNameAndIncompatibleTypes() { // Arrange var frozenType = typeof(string); var fieldName = "Field"; var fixture = new Fixture(); var sut = new FreezeOnMatchCustomization( frozenType, new FieldSpecification(frozenType, fieldName)); // Act sut.Customize(fixture); // Assert var frozen = fixture.Create <FieldHolder <ConcreteType> >().Field; var requested = fixture.Create <FieldHolder <ConcreteType> >().Field; Assert.NotSame(frozen, requested); }
public void FreezeByMatchingParameterNameShouldReturnDifferentSpecimensForParametersOfSameNameAndIncompatibleTypes() { // Arrange var frozenType = typeof(string); var parameterName = "parameter"; var fixture = new Fixture(); var sut = new FreezeOnMatchCustomization( frozenType, new ParameterSpecification(frozenType, parameterName)); // Act sut.Customize(fixture); // Assert var frozen = fixture.Create <SingleParameterType <ConcreteType> >().Parameter; var requested = fixture.Create <SingleParameterType <ConcreteType> >().Parameter; Assert.NotSame(frozen, requested); }
public void FreezeByMatchingFieldNameShouldReturnDifferentSpecimensForFieldsOfDifferentNamesAndSameType() { // Fixture setup var frozenType = typeof(ConcreteType); var fieldName = "SomeOtherField"; 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 FreezeByMatchingFieldNameShouldReturnSameSpecimenForFieldsOfSameNameAndCompatibleTypes() { // Fixture setup var frozenType = typeof(ConcreteType); 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 <AbstractType> >().Field; Assert.Same(frozen, requested); // Teardown }
public void FreezeByMatchingParameterNameShouldReturnDifferentSpecimensForParametersOfDifferentNamesAndSameType() { // Fixture setup var frozenType = typeof(ConcreteType); var parameterName = "SomeOtherParameter"; 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 FreezeByMatchingParameterNameShouldReturnSameSpecimenForParametersOfSameNameAndCompatibleTypes() { // Fixture setup var frozenType = typeof(ConcreteType); 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 <AbstractType> >().Parameter; Assert.Same(frozen, requested); // Teardown }
public void FreezeByMatchingPropertyNameShouldReturnSameSpecimenForPropertiesOfSameNameAndType() { // 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 <ConcreteType> >().Property; Assert.Same(frozen, requested); // Teardown }
public void FreezeByMatchingImplementedInterfacesShouldReturnTheRightSpecimen( Type frozenType, Type requestedType) { // Arrange var fixture = new Fixture(); var context = new SpecimenContext(fixture); var sut = new FreezeOnMatchCustomization( frozenType, new ImplementedInterfaceSpecification(frozenType)); // Act sut.Customize(fixture); // Assert var frozen = context.Resolve(frozenType); var requested = context.Resolve(requestedType); Assert.Same(frozen, requested); }
public void FreezeByMatchingBaseTypeShouldReturnTheRightSpecimen( Type frozenType, Type requestedType, bool areEqual) { // Arrange var fixture = new Fixture(); var context = new SpecimenContext(fixture); var sut = new FreezeOnMatchCustomization( frozenType, new DirectBaseTypeSpecification(frozenType)); // Act sut.Customize(fixture); // Assert var frozen = context.Resolve(frozenType); var requested = context.Resolve(requestedType); Assert.Equal(areEqual, frozen.Equals(requested)); }
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 CustomizeWithEqualRequestsShouldFreezeSpecimen() { // Fixture setup var fixture = new Fixture(); var context = new SpecimenContext(fixture); var freezingRequest = typeof(ConcreteType).GetProperty( nameof(ConcreteType.Property1)); var equalRequest = typeof(ConcreteType).GetProperty( nameof(ConcreteType.Property1)); var sut = new FreezeOnMatchCustomization(freezingRequest); // Exercise system sut.Customize(fixture); // Verify outcome var frozen = context.Resolve(freezingRequest); var requested = context.Resolve(equalRequest); Assert.True(frozen.Equals(requested)); }
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 }
public void CustomizeWithNotEqualRequestsShouldNotFreezeSpecimen() { // Arrange var fixture = new Fixture(); var context = new SpecimenContext(fixture); var freezingRequest = typeof(ConcreteType).GetProperty( nameof(ConcreteType.Property1)); var anotherRequest = typeof(ConcreteType).GetProperty( nameof(ConcreteType.Property2)); var sut = new FreezeOnMatchCustomization(freezingRequest); // Act sut.Customize(fixture); // Assert var frozen = context.Resolve(freezingRequest); var requested = context.Resolve(anotherRequest); Assert.False(frozen.Equals(requested)); }
public void FreezeByMatchingMemberNameShouldReturnSameSpecimenForMembersOfMatchingNameAndCompatibleTypes() { // Arrange 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"))); // Act sut.Customize(fixture); // Assert 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); }
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() : new NoSpecimen(request) }; 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 CustomizeWithCompetingSpecimenBuilderForTheSameRequestShouldReturnTheFrozenSpecimen() { // Arrange var fixture = new Fixture(); var context = new SpecimenContext(fixture); var request = new object(); var requestType = typeof(object); var competingBuilder = new DelegatingSpecimenBuilder { OnCreate = (req, ctx) => req.Equals(request) ? new object() : new NoSpecimen() }; var sut = new FreezeOnMatchCustomization( request, new ExactTypeSpecification(requestType)); // Act fixture.Customizations.Add(competingBuilder); sut.Customize(fixture); // Assert Assert.Equal(context.Resolve(requestType), context.Resolve(requestType)); }