예제 #1
0
        public void Delegate_type_activator_throws_if_the_underlying_function_returns_null()
        {
            // Arrange
            var activator = new DelegateTypeActivator(_ => null);

            // Act & assert
            Assert.Throws <CliFxException>(() =>
                                           activator.CreateInstance(typeof(WithDependenciesCommand)));
        }
예제 #2
0
        public void CreateInstance_Negative_Test(Func <Type, object> activatorFunc, Type type)
        {
            // Arrange
            var activator = new DelegateTypeActivator(activatorFunc);

            // Act & Assert
            var ex = Assert.Throws <CliFxException>(() => activator.CreateInstance(type));

            Console.WriteLine(ex.Message);
        }
예제 #3
0
        public void CreateInstance_Test(Func <Type, object> activatorFunc, Type type)
        {
            // Arrange
            var activator = new DelegateTypeActivator(activatorFunc);

            // Act
            var obj = activator.CreateInstance(type);

            // Assert
            obj.Should().BeOfType(type);
        }
예제 #4
0
        public void Delegate_type_activator_can_initialize_a_command_using_a_custom_function()
        {
            // Arrange
            var activator = new DelegateTypeActivator(_ =>
                                                      new WithDependenciesCommand(new DependencyA(), new DependencyB()));

            // Act
            var obj = activator.CreateInstance(typeof(WithDependenciesCommand));

            // Assert
            obj.Should().BeOfType <WithDependenciesCommand>();
        }