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); }
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); }