コード例 #1
0
 public void ConstructObject_GivenNonZeroParameter_ShouldConstructCorrectly()
 {
     //---------------Set up test pack-------------------
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     Assert.DoesNotThrow(() => ConstructorTestHelper.ConstructObject <FakeTestClass4>());
     //---------------Test Result -----------------------
 }
コード例 #2
0
 public void ConstructObject_GivenArray_ShouldNotThrowException()
 {
     //---------------Set up test pack-------------------
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     Assert.DoesNotThrow(() => ConstructorTestHelper.ConstructObject <FakeTestClass2>());
     //---------------Test Result -----------------------
 }
コード例 #3
0
 public void ConstructObject_GivenAllParametersMustMatch_ShouldConstructCorrectly()
 {
     //---------------Set up test pack-------------------
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     Assert.DoesNotThrow(() => ConstructorTestHelper.ConstructObject <FakeTestClass4>(null, null, true,
                                                                                      ("someTestValue", 200)));
     //---------------Test Result -----------------------
 }
コード例 #4
0
        public void ConstructObject_GivenTypeAndParameterAndNoValue_ShouldConstructObjectWithNullValue()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var testClass = (FakeTestClass)ConstructorTestHelper.ConstructObject(typeof(FakeTestClass), "allFakes");

            //---------------Test Result -----------------------
            testClass.Should().NotBeNull();
            testClass.FakeList.Should().BeNullOrEmpty();
        }
コード例 #5
0
        public void ConstructObject_GivenType_ShouldNotThrowExceptionAndConstructObject()
        {
            //---------------Set up test pack-------------------
            FakeTestClass testClass = null;

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            Assert.DoesNotThrow(() => testClass = (FakeTestClass)ConstructorTestHelper.ConstructObject(typeof(FakeTestClass)));
            //---------------Test Result -----------------------
            testClass.Should().NotBeNull();
        }
コード例 #6
0
        public void ConstructObject_GivenTypeAndParameterAndValue_ShouldConstructObjectWithExpectedValue()
        {
            //---------------Set up test pack-------------------
            var parameterValue = "FakeTestName";
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var testClass = (FakeTestClass)ConstructorTestHelper.ConstructObject(typeof(FakeTestClass), "testName", parameterValue);

            //---------------Test Result -----------------------
            testClass.Should().NotBeNull();
            testClass.Name.Should().Be(parameterValue);
        }
コード例 #7
0
        public void ConstructObject_GivenObjectWithMultipleConstructors_ShouldConstructUsingMatchingConstructor(string parameterName)
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var exception = Assert.Throws <TargetInvocationException>(() => ConstructorTestHelper.ConstructObject <FakeTestClass3>(parameterName));

            //---------------Test Result -----------------------
            exception.Should().NotBeNull();
            exception.InnerException.Should().BeOfType <ArgumentNullException>();
            ((ArgumentNullException)exception.InnerException)?.ParamName.Should().Be(parameterName);
        }
コード例 #8
0
 public void ConstructObject_GivenException_ShouldConstructObjectAndNotThrowException()
 {
     //---------------Set up test pack-------------------
     //---------------Assert Precondition----------------
     //---------------Execute Test ----------------------
     Assert.DoesNotThrow(() =>
     {
         var fakeException = ConstructorTestHelper.ConstructObject <FakeException>();
         //---------------Test Result -----------------------
         fakeException.Should().NotBeNull();
     });
 }
コード例 #9
0
        public void ConstructObject_GivenGenericType_ShouldNotThrowExceptionAndConstructObjectWithValuesAsExpected(string propertyName, Type expectedType)
        {
            //---------------Set up test pack-------------------
            FakeTestClass testClass = null;

            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            Assert.DoesNotThrow(() => testClass = ConstructorTestHelper.ConstructObject <FakeTestClass>());
            //---------------Test Result -----------------------
            testClass.Should().NotBeNull();

            var propertyValue = testClass.GetPropertyValue(propertyName);

            propertyValue.Should().NotBeNull();
            propertyValue.Should().BeOfType(expectedType);
        }
コード例 #10
0
        public void ConstructObject_GivenParameterValues_ShouldConstructObjectWithParameterValues()
        {
            //---------------Set up test pack-------------------
            var testDateTime = DateTime.Now;
            var fakeComplex  = new FakeComplex();

            var parameterValues = new List <(string paramName, object paramValue)>
            {
                ("testDateTime", testDateTime), ("complexObject", fakeComplex)
            };
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            var testClass = ConstructorTestHelper.ConstructObject <FakeTestClass>(constructorParams: parameterValues.ToArray());

            //---------------Test Result -----------------------
            testClass.TestDateTime.Should().BeSameDateAs(testDateTime);
            testClass.ComplexObject2.Should().Be(fakeComplex);
        }