public void AddMemberSelectionRuleTest()
 {
     var target = new ExpressionInstanceFactory( x => String.Empty );
     target.AddSelectionRule( new AllMemberSelectionRule( MemberSelectionMode.Include ) );
     target.Should()
           .NotBeNull();
 }
        public void AddMemberSelectionRuleTestArgumentNullException()
        {
            var target = new ExpressionInstanceFactory(x => String.Empty);
            // ReSharper disable once AssignNullToNotNullAttribute
            Action test = () => target.AddSelectionRule(null);

            test.ShouldThrow <ArgumentNullException>();
        }
        public void AddMemberSelectionRuleTest()
        {
            var target = new ExpressionInstanceFactory(x => String.Empty);

            target.AddSelectionRule(new AllMemberSelectionRule(MemberSelectionMode.Include));
            target.Should()
            .NotBeNull();
        }
        public void ToStringIncludeAllTest()
        {
            var target = new ExpressionInstanceFactory( x => "", "name", "description" );
            const String expected = "[name] = (description).";

            target
                .ToString()
                .Should()
                .Be( expected );
        }
        public void ToStringIncludeAllTest()
        {
            var          target   = new ExpressionInstanceFactory(x => "", "name", "description");
            const String expected = "[name] = (description).";

            target
            .ToString()
            .Should()
            .Be(expected);
        }
        public void CtorTest()
        {
            var expectedName = RandomValueEx.GetRandomString();
            var expectedDescription = RandomValueEx.GetRandomString();
            var target = new ExpressionInstanceFactory( x => "", expectedName, expectedDescription );

            target.FactoryName.Should()
                  .Be( expectedName );
            target.FactoryDescription.Should()
                  .Be( expectedDescription );
        }
        public void CtorTest()
        {
            var expectedName        = RandomValueEx.GetRandomString();
            var expectedDescription = RandomValueEx.GetRandomString();
            var target = new ExpressionInstanceFactory(x => "", expectedName, expectedDescription);

            target.FactoryName.Should()
            .Be(expectedName);
            target.FactoryDescription.Should()
            .Be(expectedDescription);
        }
        public void DefaultFactoriesTest()
        {
            var factory = new ExpressionInstanceFactory(x => "");

            InstanceCreator.DefaultFactories.Add(factory);

            InstanceCreator.DefaultFactories.Contains(factory)
            .Should()
            .BeTrue();

            InstanceCreator.DefaultFactories.Remove(factory);
            InstanceCreator.DefaultFactories.Contains(factory)
            .Should()
            .BeFalse();
        }
        public void CreateValueTest()
        {
            var expectedValue = RandomValueEx.GetRandomInt32();
            var expectedMemberInformation = new MemberInformation();
            IMemberInformation actualParameter = null;
            var target = new ExpressionInstanceFactory( x =>
            {
                actualParameter = x;
                return expectedValue;
            } );

            var actual = target.CreateValue( expectedMemberInformation );
            actual.Should()
                  .Be( expectedValue );
            actualParameter.Should()
                           .BeSameAs( expectedMemberInformation );
        }
        public void CreateValueTest()
        {
            var expectedValue                  = RandomValueEx.GetRandomInt32();
            var expectedMemberInformation      = new MemberInformation();
            IMemberInformation actualParameter = null;
            var target = new ExpressionInstanceFactory(x =>
            {
                actualParameter = x;
                return(expectedValue);
            });

            var actual = target.CreateValue(expectedMemberInformation);

            actual.Should()
            .Be(expectedValue);
            actualParameter.Should()
            .BeSameAs(expectedMemberInformation);
        }
Beispiel #11
0
        public void MultipleMatchingFactoriesInGlobalConfigTest()
        {
            var options = InstanceCreator.CreateInstanceOptions <TestModel>();

            var factory = new ExpressionInstanceFactory(x => 100)
                          .AddSelectionRule(new TypeMemberSelectionRule(typeof(Double), MemberSelectionMode.Include, CompareMode.Is));

            InstanceCreator.DefaultFactories.Add(factory);

            Action test = () => options.Complete()
                          // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
                          .CreateInstance();
            var exception = Assert.Throws <CreateInstanceException>(test);

            Assert.Equal("Found multiple matching factories for member (in global configuration). Type is 'System.Double'.  Please make sure only one factory matches the member.", exception.Message);

            InstanceCreator.DefaultFactories.Remove(factory);
            InstanceCreator.DefaultFactories.Contains(factory)
            .Should()
            .BeFalse();
        }
        public void DefaultFactoriesTest()
        {
            var factory = new ExpressionInstanceFactory( x => "" );
            InstanceCreator.DefaultFactories.Add( factory );

            InstanceCreator.DefaultFactories.Contains( factory )
                           .Should()
                           .BeTrue();

            InstanceCreator.DefaultFactories.Remove( factory );
            InstanceCreator.DefaultFactories.Contains( factory )
                           .Should()
                           .BeFalse();
        }
        public void MultipleMatchingFactoriesInGlobalConfigTest()
        {
            var options = InstanceCreator.CreateInstanceOptions<TestModel>();

            var factory = new ExpressionInstanceFactory( x => 100 )
                .AddSelectionRule( new TypeMemberSelectionRule( typeof (Double), MemberSelectionMode.Include, CompareMode.Is ) );
            InstanceCreator.DefaultFactories.Add( factory );

            Action test = () => options.Complete()
                                       .CreateInstance();
            test.ShouldThrow<CreateInstanceException>()
                .WithMessage(
                    "Found multiple matching factories for member (in global configuration). Type is 'System.Double'.  Please make sure only one factory matches the member." );

            InstanceCreator.DefaultFactories.Remove( factory );
            InstanceCreator.DefaultFactories.Contains( factory )
                           .Should()
                           .BeFalse();
        }
 public void AddMemberSelectionRuleTestArgumentNullException()
 {
     var target = new ExpressionInstanceFactory( x => String.Empty );
     Action test = () => target.AddSelectionRule( null );
     test.ShouldThrow<ArgumentNullException>();
 }