public void SpecifyOneValueInferTheOthers()
        {
            // arrange
            var descriptor = EnumTypeDescriptor.New(Context, typeof(FooEnum));

            // act
            IEnumTypeDescriptor desc = descriptor;

            desc.Item(FooEnum.Bar1).Name("FOOBAR");

            // assert
            EnumTypeDefinition description = descriptor.CreateDefinition();

            Assert.Collection(description.Values,
                              t =>
            {
                Assert.Equal("FOOBAR", t.Name);
                Assert.Equal(FooEnum.Bar1, t.Value);
            },
                              t =>
            {
                Assert.Equal("BAR2", t.Name);
                Assert.Equal(FooEnum.Bar2, t.Value);
            });
        }
        public void AddDirectiveWithArgument()
        {
            // arrange
            var descriptor = EnumTypeDescriptor.New(Context);

            // act
            IEnumTypeDescriptor desc = descriptor;

            desc.Directive("Bar",
                           new ArgumentNode("a", new StringValueNode("b")));

            // assert
            EnumTypeDefinition description = descriptor.CreateDefinition();

            Assert.Collection(description.Directives,
                              t =>
            {
                Assert.Equal("Bar", t.ParsedDirective.Name.Value);
                Assert.Collection(t.ParsedDirective.Arguments,
                                  x =>
                {
                    Assert.Equal("a", x.Name.Value);
                    Assert.IsType <StringValueNode>(x.Value);
                    Assert.Equal("b", ((StringValueNode)x.Value).Value);
                });
            });
        }
        public void NoTypeProvided()
        {
            // act
            Action a = () => EnumTypeDescriptor.New(Context, (Type)null);

            // assert
            Assert.Throws <ArgumentNullException>(a);
        }
        public void InferNameFromType()
        {
            // act
            var descriptor = EnumTypeDescriptor.New(Context, typeof(FooEnum));

            // assert
            Assert.Equal("FooEnum", descriptor.CreateDefinition().Name);
        }
Пример #5
0
        protected override EnumTypeDefinition CreateDefinition(
            IInitializationContext context)
        {
            var descriptor = EnumTypeDescriptor.New(
                context.DescriptorContext);

            _configure(descriptor);
            return(descriptor.CreateDefinition());
        }
Пример #6
0
        protected override EnumTypeDefinition CreateDefinition(
            ITypeDiscoveryContext context)
        {
            var descriptor = EnumTypeDescriptor.New <T>(
                context.DescriptorContext);

            _configure(descriptor);
            return(descriptor.CreateDefinition());
        }
        public void AddDirectiveWithDirectiveNode()
        {
            // arrange
            var descriptor = EnumTypeDescriptor.New(Context);

            // act
            IEnumTypeDescriptor desc = descriptor;

            desc.Directive(new DirectiveNode("Bar"));

            // assert
            EnumTypeDefinition description = descriptor.CreateDefinition();

            Assert.Collection(description.Directives,
                              t => Assert.Equal("Bar", t.ParsedDirective.Name.Value));
        }
        public void InferValuesFromType()
        {
            // act
            var descriptor = EnumTypeDescriptor.New(Context, typeof(FooEnum));

            // assert
            EnumTypeDefinition description = descriptor.CreateDefinition();

            Assert.Collection(description.Values,
                              t =>
            {
                Assert.Equal("BAR1", t.Name);
                Assert.Equal(FooEnum.Bar1, t.Value);
            },
                              t =>
            {
                Assert.Equal("BAR2", t.Name);
                Assert.Equal(FooEnum.Bar2, t.Value);
            });
        }
        public void ExplicitValueBinding()
        {
            // arrange
            var descriptor = EnumTypeDescriptor.New(Context, typeof(FooEnum));

            // act
            IEnumTypeDescriptor desc = descriptor;

            desc.Item(FooEnum.Bar1).Name("FOOBAR");
            desc.BindItems(BindingBehavior.Explicit);

            // assert
            EnumTypeDefinition description = descriptor.CreateDefinition();

            Assert.Collection(description.Values,
                              t =>
            {
                Assert.Equal("FOOBAR", t.Name);
                Assert.Equal(FooEnum.Bar1, t.Value);
            });
        }