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);
        }
Example #3
0
        public void CustomizeWithNullFixtureShouldThrowArgumentNullException()
        {
            // Fixture setup
            var sut = new FreezeOnMatchCustomization(typeof(object));

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.Customize(null));
            // Teardown
        }
Example #4
0
        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
        }
Example #6
0
        public void InitializeWithTargetTypeShouldSetCorrespondingProperty()
        {
            // Fixture setup
            var targetType = typeof(object);
            // Exercise system
            var sut = new FreezeOnMatchCustomization(typeof(object));

            // Verify outcome
            Assert.Equal(targetType, sut.TargetType);
        }
Example #7
0
        public void SutShouldBeCustomization()
        {
            // Fixture setup
            // Exercise system
            var sut = new FreezeOnMatchCustomization(typeof(object));

            // Verify outcome
            Assert.IsAssignableFrom <ICustomization>(sut);
            // Teardown
        }
Example #8
0
        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);
        }
Example #13
0
        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
        }
Example #14
0
        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
        }
Example #15
0
        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
        }
Example #16
0
        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
        }
Example #17
0
        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));
        }
Example #20
0
        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
        }
Example #21
0
        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));
        }
Example #22
0
        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);
        }
Example #25
0
        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));
        }