Exemple #1
0
        public void SpecifyOneValueInferTheOthers()
        {
            // arrange
            var descriptor = new EnumTypeDescriptor(typeof(FooEnum));

            // act
            IEnumTypeDescriptor desc = descriptor;

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

            // assert
            EnumTypeDescription description = descriptor.CreateDescription();

            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);
            });
        }
Exemple #2
0
        public void AddDirectiveWithArgument()
        {
            // arrange
            var descriptor = new EnumTypeDescriptor("Foo");

            // act
            IEnumTypeDescriptor desc = descriptor;

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

            // assert
            EnumTypeDescription description = descriptor.CreateDescription();

            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);
                });
            });
        }
        private void Initialize(Action <IEnumTypeDescriptor> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            EnumTypeDescriptor descriptor = CreateDescriptor();

            configure(descriptor);

            EnumTypeDescription description = descriptor.CreateDescription();

            foreach (EnumValue enumValue in description.Values
                     .Select(t => new EnumValue(t)))
            {
                _nameToValues[enumValue.Name]   = enumValue;
                _valueToValues[enumValue.Value] = enumValue;
            }

            SyntaxNode = description.SyntaxNode;
            ClrType    = description.ClrType;

            Initialize(description.Name, description.Description,
                       new DirectiveCollection(
                           this,
                           DirectiveLocation.Enum,
                           description.Directives));
        }
Exemple #4
0
        public void AddDirectiveWithDirectiveNode()
        {
            // arrange
            var descriptor = new EnumTypeDescriptor("Foo");

            // act
            IEnumTypeDescriptor desc = descriptor;

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

            // assert
            EnumTypeDescription description = descriptor.CreateDescription();

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

            // assert
            EnumTypeDescription description = descriptor.CreateDescription();

            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);
            });
        }
Exemple #6
0
        public void ExplicitValueBinding()
        {
            // arrange
            var descriptor = new EnumTypeDescriptor(typeof(FooEnum));

            // act
            IEnumTypeDescriptor desc = descriptor;

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

            // assert
            EnumTypeDescription description = descriptor.CreateDescription();

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