コード例 #1
0
        public void ShouldCreateNewInstanceCreateParameters(
            [Substitute] ISpecimenBuilder specimenBuilder)
        {
            var sut = new ConstructorArgumentsTracker(specimenBuilder, typeof(SimpleType).GetConstructors().Single());

            sut.CreateNewInstance();

            specimenBuilder.Received(1).Create(Arg.Is(typeof(int)), Arg.Any <ISpecimenContext>());
        }
コード例 #2
0
        public void ShouldCreateNewInstanceCreateParameters(
            [Substitute]ISpecimenBuilder specimenBuilder)
        {
            var sut = new ConstructorArgumentsTracker(specimenBuilder, typeof(SimpleType).GetConstructors().Single());

            sut.CreateNewInstance();

            specimenBuilder.Received(1).Create(Arg.Is(typeof(int)), Arg.Any<ISpecimenContext>());
        }
コード例 #3
0
        public void ShouldCreateInstanceWithTheSameCtorArgs(
            [Substitute] ISpecimenBuilder specimenBuilder)
        {
            var sut = new ConstructorArgumentsTracker(specimenBuilder,
                                                      typeof(decimal).GetConstructor(new[] { typeof(double) }));

            var instance    = sut.CreateNewInstance();
            var newInstance = sut.CreateNewInstanceWithTheSameCtorArgsAsIn(instance);

            Assert.False(ReferenceEquals(instance, newInstance));
            Assert.True(instance.Equals(newInstance));
        }
コード例 #4
0
        public void ShouldCreateInstanceWithTheSameCtorArgs(
            [Substitute]ISpecimenBuilder specimenBuilder)
        {
            var sut = new ConstructorArgumentsTracker(specimenBuilder,
                typeof(decimal).GetConstructor(new[] { typeof(double) }));

            var instance = sut.CreateNewInstance();
            var newInstance = sut.CreateNewInstanceWithTheSameCtorArgsAsIn(instance);

            Assert.False(ReferenceEquals(instance, newInstance));
            Assert.True(instance.Equals(newInstance));
        }
コード例 #5
0
        public void ShouldCreateAsManyDistinctInstancesAsCtorParameters(
            [Substitute] ISpecimenBuilder specimenBuilder)
        {
            specimenBuilder.Create(Arg.Any <object>(), Arg.Any <ISpecimenContext>()).Returns(1);

            var sut = new ConstructorArgumentsTracker(specimenBuilder, typeof(SimpleType).GetConstructors().Single());

            var instance = sut.CreateNewInstance() as SimpleType;

            specimenBuilder.ClearReceivedCalls();

            var instances = sut.CreateDistinctInstancesByChaningOneByOneCtorArgIn(instance).ToList();

            specimenBuilder.Received(1).Create(Arg.Is(typeof(int)), Arg.Any <ISpecimenContext>());
            Assert.Equal(1, instances.Count);
        }
コード例 #6
0
        public void ShouldCreateAsManyDistinctInstancesAsCtorParameters(
            [Substitute]ISpecimenBuilder specimenBuilder)
        {
            specimenBuilder.Create(Arg.Any<object>(), Arg.Any<ISpecimenContext>()).Returns(1);

            var sut = new ConstructorArgumentsTracker(specimenBuilder, typeof(SimpleType).GetConstructors().Single());

            var instance = sut.CreateNewInstance() as SimpleType;
            specimenBuilder.ClearReceivedCalls();

            var instances = sut.CreateDistinctInstancesByChaningOneByOneCtorArgIn(instance).ToList();

            specimenBuilder.Received(1).Create(Arg.Is(typeof(int)), Arg.Any<ISpecimenContext>());
            Assert.Equal(1, instances.Count);
        }