public void ExecuteThrowsWhenContextIsNull()
 {
     // Fixture setup
     var specimen = new Mock<object>();
     var sut = new AutoMockPropertiesCommand();
     // Exercise system and verify outcome
     Assert.Throws<ArgumentNullException>(() => sut.Execute(specimen, null));
 }
 public void ExecuteDoesNotThrowsWhenSpecimenIsValidNonMockSpecimen(object validNonMockSpecimen)
 {
     // Fixture setup
     var context = new Mock<ISpecimenContext>().Object;
     var sut = new AutoMockPropertiesCommand();
     // Exercise system and verify outcome
     Assert.DoesNotThrow(() => sut.Execute(validNonMockSpecimen, context));
 }
        public void ExecuteThrowsWhenContextIsNull()
        {
            // Fixture setup
            var specimen = new Mock <object>();
            var sut      = new AutoMockPropertiesCommand();

            // Exercise system and verify outcome
            Assert.Throws <ArgumentNullException>(() => sut.Execute(specimen, null));
        }
 public void IgnoresNonMockSpecimens()
 {
     // Fixture setup
     var specimen = new object();
     var context = new Mock<ISpecimenContext>().Object;
     var sut = new AutoMockPropertiesCommand();
     // Exercise system and verify outcome
     Assert.DoesNotThrow(() => sut.Execute(specimen, context));
 }
Exemplo n.º 5
0
        public void ExecuteThrowsWhenContextIsNull()
        {
            // Arrange
            var specimen = new Mock <object>();
            var sut      = new AutoMockPropertiesCommand();

            // Act & Assert
            Assert.Throws <ArgumentNullException>(() => sut.Execute(specimen, null));
        }
Exemplo n.º 6
0
        public void ExecuteDoesNotThrowsWhenSpecimenIsValidNonMockSpecimen(object validNonMockSpecimen)
        {
            // Arrange
            var context = new Mock <ISpecimenContext>().Object;
            var sut     = new AutoMockPropertiesCommand();

            // Act & Assert
            Assert.Null(Record.Exception(() => sut.Execute(validNonMockSpecimen, context)));
        }
        public void ExecuteDoesNotThrowsWhenSpecimenIsValidNonMockSpecimen(object validNonMockSpecimen)
        {
            // Fixture setup
            var context = new Mock <ISpecimenContext>().Object;
            var sut     = new AutoMockPropertiesCommand();

            // Exercise system and verify outcome
            Assert.DoesNotThrow(() => sut.Execute(validNonMockSpecimen, context));
        }
        public void IgnoresNonMockSpecimens()
        {
            // Fixture setup
            var specimen = new object();
            var context  = new Mock <ISpecimenContext>().Object;
            var sut      = new AutoMockPropertiesCommand();

            // Exercise system and verify outcome
            Assert.DoesNotThrow(() => sut.Execute(specimen, context));
        }
Exemplo n.º 9
0
        public void IgnoresNonMockSpecimens()
        {
            // Arrange
            var specimen = new object();
            var context  = new Mock <ISpecimenContext>().Object;
            var sut      = new AutoMockPropertiesCommand();

            // Act & Assert
            Assert.Null(Record.Exception(() => sut.Execute(specimen, context)));
        }
        public void PopulatesFields()
        {
            // Fixture setup
            var specimen = new Mock<TypeWithPublicField>();

            const string frozenString = "a string";
            var contextStub = new Mock<ISpecimenContext>();
            contextStub.Setup(ctx => ctx.Resolve(specimen.Object.GetType().GetField("Field"))).Returns(frozenString);

            var sut = new AutoMockPropertiesCommand();
            // Exercise system
            sut.Execute(specimen, contextStub.Object);
            // Verify outcome
            Assert.Equal(frozenString, specimen.Object.Field);
        }
        public void PopulatesPropertiesUsingContext()
        {
            // Fixture setup
            var specimen = new Mock<IInterfaceWithProperty>();

            const string frozenString = "a string";
            var contextStub = new Mock<ISpecimenContext>();
            contextStub.Setup(ctx => ctx.Resolve(specimen.Object.GetType().GetProperty("Property"))).Returns(frozenString);

            var sut = new AutoMockPropertiesCommand();
            // Exercise system
            sut.Execute(specimen, contextStub.Object);
            // Verify outcome
            specimen.VerifySet(s => s.Property = frozenString, Times.Once());
        }
        public void PopulatesFields()
        {
            // Fixture setup
            var specimen = new Mock <TypeWithPublicField>();

            const string frozenString = "a string";
            var          contextStub  = new Mock <ISpecimenContext>();

            contextStub.Setup(ctx => ctx.Resolve(specimen.Object.GetType().GetField("Field"))).Returns(frozenString);

            var sut = new AutoMockPropertiesCommand();

            // Exercise system
            sut.Execute(specimen, contextStub.Object);
            // Verify outcome
            Assert.Equal(frozenString, specimen.Object.Field);
        }
        public void PopulatesPropertiesUsingContext()
        {
            // Fixture setup
            var specimen = new Mock <IInterfaceWithProperty>();

            const string frozenString = "a string";
            var          contextStub  = new Mock <ISpecimenContext>();

            contextStub.Setup(ctx => ctx.Resolve(specimen.Object.GetType().GetProperty("Property"))).Returns(frozenString);

            var sut = new AutoMockPropertiesCommand();

            // Exercise system
            sut.Execute(specimen, contextStub.Object);
            // Verify outcome
            specimen.VerifySet(s => s.Property = frozenString, Times.Once());
        }
        public void IgnoresProxyMembers(string proxyFieldName)
        {
            // Fixture setup
            var specimen               = new Mock <IInterfaceWithoutMembers>();
            var proxyField             = specimen.Object.GetType().GetField(proxyFieldName);
            var initialProxyFieldValue = proxyField.GetValue(specimen.Object);

            var contextStub = new Mock <ISpecimenContext>();

            contextStub.Setup(ctx => ctx.Resolve(It.IsAny <FieldInfo>()))
            .Returns((FieldInfo fi) => fi.FieldType.IsArray ?
                     Array.CreateInstance(fi.FieldType.GetElementType(), 0) :
                     Activator.CreateInstance(fi.FieldType));

            var sut = new AutoMockPropertiesCommand();

            // Exercise system
            sut.Execute(specimen, contextStub.Object);
            // Verify outcome
            var finalProxyFieldValue = proxyField.GetValue(specimen.Object);

            Assert.Same(initialProxyFieldValue, finalProxyFieldValue);
        }
        public void IgnoresProxyMembers(string proxyFieldName)
        {
            // Fixture setup
            var specimen = new Mock<IInterfaceWithoutMembers>();
            var proxyField = specimen.Object.GetType().GetField(proxyFieldName);
            var initialProxyFieldValue = proxyField.GetValue(specimen.Object);

            var contextStub = new Mock<ISpecimenContext>();
            contextStub.Setup(ctx => ctx.Resolve(It.IsAny<FieldInfo>()))
                .Returns((FieldInfo fi) => fi.FieldType.IsArray ?
                    Array.CreateInstance(fi.FieldType.GetElementType(), 0) :
                    Activator.CreateInstance(fi.FieldType));

            var sut = new AutoMockPropertiesCommand();
            // Exercise system
            sut.Execute(specimen, contextStub.Object);
            // Verify outcome
            var finalProxyFieldValue = proxyField.GetValue(specimen.Object);
            Assert.Same(initialProxyFieldValue, finalProxyFieldValue);
        }