public override SaveResult Save(FileModel model) { if (model.Type != DocumentType.Article) { throw new NotSupportedException(); } var vm = (PageViewModel)model.Content; model.Content = ApiBuildOutput.FromModel(vm); // Fill in details return(new SaveResult { DocumentType = "ManagedReference", ModelFile = model.File, LinkToFiles = ((HashSet <string>)model.Properties.LinkToFiles).ToImmutableArray(), LinkToUids = ((HashSet <string>)model.Properties.LinkToUids).ToImmutableHashSet(), XRefSpecs = (from item in vm.Items select GetXRefInfo(item, model.Key)).ToImmutableArray(), }); }
protected virtual void UpdateModelContent(FileModel model) { var apiModel = ApiBuildOutput.FromModel((PageViewModel)model.Content); // Fill in details model.Content = apiModel; // Fill in bookmarks if template doesn't generate them. // TODO: remove these if (apiModel.Type == MemberType.Namespace) { return; } model.Bookmarks[apiModel.Uid] = string.Empty; // Reference's first level bookmark should have no anchor apiModel.Children?.ForEach(c => { model.Bookmarks[c.Uid] = c.Id; if (!string.IsNullOrEmpty(c.Overload?.Uid)) { model.Bookmarks[c.Overload.Uid] = c.Overload.Id; } }); }
protected virtual void UpdateModelContent(FileModel model) { var apiModel = ApiBuildOutput.FromModel((PageViewModel)model.Content); // Fill in details model.Content = apiModel; }
public void MapToApiBuildOutputWithoutReferenceShouldSucceed() { // Arrange var input = new ItemViewModel { Uid = "uid", Parent = "parent", Href = "href", Name = "name", NameWithType = "nameWithType", FullName = "fullName", Type = MemberType.Class, Source = new SourceDetail { Remote = new GitDetail { RelativePath = "sourcePath" }, BasePath = "sourceBasePath", StartLine = 0, EndLine = 0 }, Documentation = new SourceDetail { Remote = new GitDetail { RelativePath = "documentPath" }, BasePath = "documentBasePath", StartLine = 0, EndLine = 0 }, PackageNameList = new List <string> { "package" }, NamespaceName = "namespace", Summary = "summary", Remarks = "remarks", Examples = new List <string> { "example" }, Syntax = new SyntaxDetailViewModel { Content = "syntax", Parameters = new List <ApiParameter> { new ApiParameter { Description = "this is a param", Type = new List <string> { "string" }, Optional = false } } }, Overridden = "overridden", Exceptions = new List <ExceptionInfo> { new ExceptionInfo { Type = "exceptionType", Description = "exceptionDescription" } }, SeeAlsos = new List <LinkInfo> { new LinkInfo { LinkType = LinkType.HRef, LinkId = "linkid.com", AltText = "linkText" }, new LinkInfo { LinkType = LinkType.CRef, LinkId = "type" } }, Inheritance = new List <string> { "inheritance" }, Metadata = { ["metaKey"] = "metaValue" } }; var expected = new ApiBuildOutput { Uid = "uid", Parent = new ApiReferenceBuildOutput { Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "parent" } } }, Href = "href", Name = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "name" } }, NameWithType = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "nameWithType" } }, FullName = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "fullName" } }, Type = MemberType.Class, Source = new SourceDetail { Remote = new GitDetail { RelativePath = "sourcePath" }, BasePath = "sourceBasePath", StartLine = 0, EndLine = 0 }, Documentation = new SourceDetail { Remote = new GitDetail { RelativePath = "documentPath" }, BasePath = "documentBasePath", StartLine = 0, EndLine = 0 }, PackageNameList = new List <string> { "package" }, NamespaceName = new ApiReferenceBuildOutput { Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "namespace" } } }, Summary = "summary", Remarks = "remarks", Examples = new List <string> { "example" }, Syntax = new ApiSyntaxBuildOutput { Content = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "syntax" } }, Parameters = new List <ApiParameterBuildOutput> { new ApiParameterBuildOutput { Description = "this is a param", Type = new List <ApiReferenceBuildOutput> { new ApiReferenceBuildOutput { Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "string" } } } }, Optional = false } } }, Overridden = new ApiReferenceBuildOutput { Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "overridden" } } }, Exceptions = new List <ApiExceptionInfoBuildOutput> { new ApiExceptionInfoBuildOutput { Type = new ApiReferenceBuildOutput { Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "exceptionType" } } }, Description = "exceptionDescription" } }, SeeAlsos = new List <ApiLinkInfoBuildOutput> { new ApiLinkInfoBuildOutput { LinkType = LinkType.HRef, Url = "<span><a href=\"linkid.com\">linkText</a></span>" }, new ApiLinkInfoBuildOutput { LinkType = LinkType.CRef, Type = new ApiReferenceBuildOutput { Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "type" } } } } }, Inheritance = new List <ApiReferenceBuildOutput> { new ApiReferenceBuildOutput { Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "inheritance" } } } }, Metadata = { ["metaKey"] = "metaValue" } }; // Act Mapper.Initialize(cfg => { cfg.AddProfile(new ApiBuildOutputProfile(SupportedLanguages)); }); Mapper.Configuration.AssertConfigurationIsValid(); var dto = Mapper.Map <ItemViewModel, ApiBuildOutput>(input); // Assert Assert.Equal(JsonUtility.Serialize(expected), JsonUtility.Serialize(dto)); }
public void MapToApiBuildOutputWithReferenceShouldSucceed() { // Arrange var input = new PageViewModel { Items = new List <ItemViewModel> { new ItemViewModel { Uid = "KeyVaultClient", Id = "KeyVaultClient", Name = "KeyVaultClient", Summary = "class summary", FullName = "KeyVaultClient", Type = MemberType.Class, Children = new List <string> { "KeyVaultClient.#ctor" }, Metadata = { ["key1"] = "will be overwritten", ["key3"] = "value3" } }, new ItemViewModel { Uid = "KeyVaultClient.#ctor", Id = "KeyVaultClient.#ctor", Parent = "KeyVaultClient", Name = "KeyVaultClient(credentials, options)", FullName = "KeyVaultClient.KeyVaultClient(credentials, options)", Summary = "Initializes a new instance of the KeyVaultClient class", Type = MemberType.Constructor, Syntax = new SyntaxDetailViewModel { Parameters = new List <ApiParameter> { new ApiParameter { Name = "credentials", Type = new List <string> { "credentials" }, Description = "Credentials needed for the client to connect to Azure." }, new ApiParameter { Name = "options", Type = new List <string> { "Array" }, Description = "The parameter options." } }, Content = "new KeyVaultClient(credentials, options)" } } }, References = new List <ReferenceViewModel> { new ReferenceViewModel { Uid = "credentials", Name = "credentials", FullName = "credentials", IsExternal = true }, new ReferenceViewModel { Uid = "Array", Name = "Array", FullName = "Array", IsExternal = true } }, Metadata = { ["key1"] = "value1", ["key2"] = "value2" } }; var expected = new ApiBuildOutput { Uid = "KeyVaultClient", Name = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "KeyVaultClient" } }, Summary = "class summary", FullName = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "KeyVaultClient" } }, Type = MemberType.Class, Children = new List <ApiBuildOutput> { new ApiBuildOutput { Uid = "KeyVaultClient.#ctor", Parent = new ApiReferenceBuildOutput { Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "KeyVaultClient", } } }, Name = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "KeyVaultClient(credentials, options)" } }, FullName = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "KeyVaultClient.KeyVaultClient(credentials, options)" } }, Summary = "Initializes a new instance of the KeyVaultClient class", Type = MemberType.Constructor, Syntax = new ApiSyntaxBuildOutput { Parameters = new List <ApiParameterBuildOutput> { new ApiParameterBuildOutput { Name = "credentials", Type = new List <ApiReferenceBuildOutput> { new ApiReferenceBuildOutput { Uid = "credentials", IsExternal = true, Name = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "credentials" } }, FullName = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "credentials" } }, Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "<xref href=\"credentials\" text=\"credentials\" alt=\"credentials\"/>" } } } }, Description = "Credentials needed for the client to connect to Azure." }, new ApiParameterBuildOutput { Name = "options", Type = new List <ApiReferenceBuildOutput> { new ApiReferenceBuildOutput { Uid = "Array", IsExternal = true, Name = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "Array" } }, FullName = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "Array" } }, Spec = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "<xref href=\"Array\" text=\"Array\" alt=\"Array\"/>" } } } }, Description = "The parameter options." } }, Content = new List <ApiLanguageValuePair> { new ApiLanguageValuePair { Language = JavaScriptDevLang, Value = "new KeyVaultClient(credentials, options)" } } }, Metadata = { ["key1"] = "value1", ["key2"] = "value2" } } }, Metadata = { ["key1"] = "value1", ["key2"] = "value2", ["key3"] = "value3" } }; // Act var dto = input.ToApiBuildOutput(); // Assert Assert.Equal(JsonUtility.Serialize(expected), JsonUtility.Serialize(dto)); }