コード例 #1
0
ファイル: CodeUnionType.cs プロジェクト: microsoft/kiota
    public override object Clone()
    {
        var value = new CodeUnionType {
        }.BaseClone <CodeUnionType>(this);

        return(value);
    }
コード例 #2
0
        public void ConvertsUnionTypesToWrapper()
        {
            var model = root.AddClass(new CodeClass(root)
            {
                Name      = "model",
                ClassKind = CodeClassKind.Model
            }).First();
            var union = new CodeUnionType(model)
            {
                Name = "union",
            };

            union.AddType(new (model) {
                Name = "type1",
            }, new(model) {
コード例 #3
0
ファイル: CodeUnionTypeTests.cs プロジェクト: microsoft/kiota
        public void ClonesProperly()
        {
            var root = CodeNamespace.InitRootNamespace();
            var type = new CodeUnionType {
                Name = "type1",
            };

            type.AddType(new CodeType {
                Name = "subtype"
            });
            var clone = type.Clone() as CodeUnionType;

            Assert.NotNull(clone);
            Assert.Single(clone.AllTypes);
            Assert.Single(clone.Types);
            Assert.Equal(type.AllTypes.First().Name, clone.AllTypes.First().Name);
        }
コード例 #4
0
    public void ConvertsUnionTypesToWrapper()
    {
        var model = root.AddClass(new CodeClass {
            Name = "model",
            Kind = CodeClassKind.Model
        }).First();
        var union = new CodeUnionType {
            Name = "union",
        };

        union.AddType(new () {
            Name = "type1",
        }, new() {
            Name = "type2"
        });
        var property = model.AddProperty(new CodeProperty {
            Name = "deserialize",
            Kind = CodePropertyKind.Custom,
            Type = union.Clone() as CodeTypeBase,
        }).First();
        var method = model.AddMethod(new CodeMethod {
            Name       = "method",
            ReturnType = union.Clone() as CodeTypeBase
        }).First();
        var parameter = new CodeParameter {
            Name = "param1",
            Type = union.Clone() as CodeTypeBase
        };
        var indexer = new CodeIndexer {
            Name       = "idx",
            ReturnType = union.Clone() as CodeTypeBase,
        };

        model.SetIndexer(indexer);
        method.AddParameter(parameter);
        ILanguageRefiner.Refine(new GenerationConfiguration {
            Language = GenerationLanguage.CSharp
        }, root);                                                                                            //using CSharp so the indexer doesn't get removed
        Assert.True(property.Type is CodeType);
        Assert.True(parameter.Type is CodeType);
        Assert.True(method.ReturnType is CodeType);
        Assert.True(indexer.ReturnType is CodeType);
    }
コード例 #5
0
        public void TranslatesType()
        {
            var service         = new CSharpConventionService();
            var root            = CodeNamespace.InitRootNamespace();
            var unknownTypeMock = new Mock <CodeTypeBase>();

            unknownTypeMock.Setup(x => x.Name).Returns("unkownType");
            Assert.Throws <InvalidOperationException>(() => service.TranslateType(unknownTypeMock.Object));
            var stringType = new CodeType {
                Name = "string"
            };

            Assert.Equal("string", service.TranslateType(stringType));
            var unionStringType = new CodeUnionType {
                Name = "unionString"
            };

            unionStringType.AddType(stringType);
            Assert.Equal("string", service.TranslateType(unionStringType));
        }