コード例 #1
0
        public void TestThrowsOperationExceptionWhenMoreThanOneEquallyFitCtorFound()
        {
            // Arrange
            // Act
            var caught = Assert.Throws <InvalidOperationException>(
                () => ConstructorInvoke <ClassWithPrivateCtors>
                .UsingPrivateConstructor(1, 1, 1));

            // Assert
            Assert.Equal("Matching mechanism could not choose a best constructor to invoke.", caught.Message);
        }
コード例 #2
0
        public void TestThrowsOperationExceptionWhenNoMatchingFound()
        {
            // Arrange
            // Act
            var caught = Assert.Throws <InvalidOperationException>(
                () => ConstructorInvoke <ClassWithPrivateCtors>
                .UsingPrivateConstructor("s", "s", "s"));

            // Assert
            Assert.Equal("Didn't find a constructor mathing passed parameters.", caught.Message);
        }
コード例 #3
0
        public void TestCtorWithNoArgumentsIsAccessible()
        {
            // Arrange
            // Act
            var result = ConstructorInvoke <ClassWithPrivateCtors>
                         .UsingPrivateConstructor();

            // Assert
            Assert.NotNull(result);
            Assert.Null(result.O);
            Assert.Null(result.S);
        }
コード例 #4
0
        public void TestCtorWithStringArgumentIsAccessible()
        {
            // Arrange
            var o = new object();

            // Act
            var result = ConstructorInvoke <ClassWithPrivateCtors>
                         .UsingPrivateConstructor(o);

            // Assert
            Assert.NotNull(result);
            Assert.Same(o, result.O);
            Assert.Null(result.S);
        }
コード例 #5
0
        public void TestCtorWithObjectArgumentIsAccessible()
        {
            // Arrange
            var s = "a";

            // Act
            var result = ConstructorInvoke <ClassWithPrivateCtors>
                         .UsingPrivateConstructor(s);

            // Assert
            Assert.NotNull(result);
            Assert.Null(result.O);
            Assert.Equal(s, result.S);
        }
コード例 #6
0
 public T ToCreateInstance(params object[] parameters)
 {
     return(ConstructorInvoke <T> .UsingPrivateConstructor(parameters));
 }