-
Notifications
You must be signed in to change notification settings - Fork 874
Added Code Examples links to class and interface pages. #4242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
boblodgett
wants to merge
3
commits into
development
Choose a base branch
from
boblod-examples-v4
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
docgenerator/SDKDocGenerator.UnitTests/ExampleMetadataParserTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using Xunit; | ||
|
|
||
| namespace SDKDocGenerator.UnitTests | ||
| { | ||
| public class ExampleMetadataParserTests | ||
| { | ||
| private readonly string _testMetaJsonPath; | ||
|
|
||
| public ExampleMetadataParserTests() | ||
| { | ||
| _testMetaJsonPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "..", "SDKDocGenerator", "example_meta.json"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GenerateExampleFragments_WithValidFile_ShouldSetFragmentsPath() | ||
| { | ||
| ExampleMetadataParser.GenerateExampleFragments(_testMetaJsonPath); | ||
|
|
||
| try | ||
| { | ||
| Assert.False(string.IsNullOrEmpty(ExampleMetadataParser.ExampleFragmentsFullPath)); | ||
| Assert.True(Directory.Exists(ExampleMetadataParser.ExampleFragmentsFullPath)); | ||
| } | ||
| finally | ||
| { | ||
| ExampleMetadataParser.CleanupExampleFragments(); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GenerateExampleFragments_WithValidFile_ShouldCreateControlTowerFragment() | ||
| { | ||
| ExampleMetadataParser.GenerateExampleFragments(_testMetaJsonPath); | ||
| try | ||
| { | ||
| var fragmentPath = Path.Combine(ExampleMetadataParser.ExampleFragmentsFullPath, "ControlTower.fragment.html"); | ||
| Assert.True(File.Exists(fragmentPath)); | ||
|
|
||
| var content = File.ReadAllText(fragmentPath); | ||
| Assert.Contains("<a href=\"https://docs.aws.amazon.com/code-library/latest/ug/dotnet_4_controltower_code_examples.html\" target=\"_blank\">AWS SDK Code Examples Code Library</a>", content); | ||
| Assert.Contains("<h3 class=\"\">Api</h3>", content); | ||
| Assert.Contains("Use DisableBaseline", content); | ||
| Assert.Contains("Use DisableControl", content); | ||
| Assert.Contains("Use EnableBaseline", content); | ||
| Assert.Contains("Use EnableControl", content); | ||
| Assert.Contains("Use GetBaselineOperation", content); | ||
| Assert.Contains("Use GetControlOperation", content); | ||
| Assert.Contains("Use ListBaselines", content); | ||
| Assert.Contains("Use ListEnabledBaselines", content); | ||
| Assert.Contains("Use ListEnabledControls", content); | ||
| Assert.Contains("Use ListLandingZones", content); | ||
| Assert.Contains("Use ResetEnabledBaseline", content); | ||
| } | ||
| finally | ||
| { | ||
| ExampleMetadataParser.CleanupExampleFragments(); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GenerateExampleFragments_WithNonExistentFile_ShouldNotThrow() | ||
| { | ||
| var nonExistentPath = Path.Combine(Path.GetTempPath(), "nonexistent.json"); | ||
| try | ||
| { | ||
| var exception = Record.Exception(() => ExampleMetadataParser.GenerateExampleFragments(nonExistentPath)); | ||
| Assert.Null(exception); | ||
| } | ||
| finally | ||
| { | ||
| ExampleMetadataParser.CleanupExampleFragments(); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CleanupExampleFragments_ShouldRemoveDirectory() | ||
| { | ||
| ExampleMetadataParser.GenerateExampleFragments(_testMetaJsonPath); | ||
| var fragmentsPath = ExampleMetadataParser.ExampleFragmentsFullPath; | ||
| try | ||
| { | ||
| Assert.True(Directory.Exists(fragmentsPath)); | ||
| } | ||
| finally | ||
| { | ||
| ExampleMetadataParser.CleanupExampleFragments(); | ||
| } | ||
|
|
||
| Assert.False(Directory.Exists(fragmentsPath)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CleanupExampleFragments_WithNullPath_ShouldNotThrow() | ||
| { | ||
| var exception = Record.Exception(() => ExampleMetadataParser.CleanupExampleFragments()); | ||
| Assert.Null(exception); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void SanitizeStringForClassName_ShouldRemoveAWSAndAmazon() | ||
| { | ||
| var result = ExampleMetadataParser.SanitizeStringForClassName("AWS Control Tower"); | ||
| Assert.Equal("ControlTower", result); | ||
|
|
||
| result = ExampleMetadataParser.SanitizeStringForClassName("Amazon S3"); | ||
| Assert.Equal("S3", result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToUpperFirstCharacter_ShouldCapitalizeFirstLetter() | ||
| { | ||
| var result = ExampleMetadataParser.ToUpperFirstCharacter("controlTower"); | ||
| Assert.Equal("ControlTower", result); | ||
|
|
||
| result = ExampleMetadataParser.ToUpperFirstCharacter("s"); | ||
| Assert.Equal("S", result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GenerateExampleFragments_WithInvalidJson_ShouldCreateFailureFile() | ||
| { | ||
| var tempJsonFile = Path.GetTempFileName(); | ||
| var failureFile = Path.GetTempFileName(); | ||
|
|
||
| try | ||
| { | ||
| File.WriteAllText(tempJsonFile, "{ \"bad file\": \"test\"}"); | ||
|
|
||
| if (File.Exists(failureFile)) | ||
| File.Delete(failureFile); | ||
|
|
||
| ExampleMetadataParser.GenerateExampleFragments(tempJsonFile, failureFile); | ||
|
|
||
| Assert.True(File.Exists(failureFile)); | ||
| var content = File.ReadAllText(failureFile); | ||
| Assert.Contains("Failed to generate example fragments: System.Exception: Examples could not be found.", content); | ||
| } | ||
| finally | ||
| { | ||
| if (File.Exists(tempJsonFile)) | ||
| File.Delete(tempJsonFile); | ||
| if (File.Exists(failureFile)) | ||
| File.Delete(failureFile); | ||
| ExampleMetadataParser.CleanupExampleFragments(); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GenerateExampleFragments_WithNullPath_ShouldCreateFailureFile() | ||
| { | ||
| var failureFile = Path.GetTempFileName(); | ||
|
|
||
| try | ||
| { | ||
| if (File.Exists(failureFile)) | ||
| File.Delete(failureFile); | ||
|
|
||
| ExampleMetadataParser.GenerateExampleFragments(null, failureFile); | ||
|
|
||
| Assert.True(File.Exists(failureFile)); | ||
| var content = File.ReadAllText(failureFile); | ||
| Assert.Contains("Example metadata file has not been specified.", content); | ||
| } | ||
| finally | ||
| { | ||
| if (File.Exists(failureFile)) | ||
| File.Delete(failureFile); | ||
| ExampleMetadataParser.CleanupExampleFragments(); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GenerateExampleFragments_WithEmptyPath_ShouldCreateFailureFile() | ||
| { | ||
| var failureFile = Path.GetTempFileName(); | ||
|
|
||
| try | ||
| { | ||
| if (File.Exists(failureFile)) | ||
| File.Delete(failureFile); | ||
|
|
||
| ExampleMetadataParser.GenerateExampleFragments("", failureFile); | ||
|
|
||
| Assert.True(File.Exists(failureFile)); | ||
| var content = File.ReadAllText(failureFile); | ||
| Assert.Contains("Example metadata file has not been specified.", content); | ||
| } | ||
| finally | ||
| { | ||
| if (File.Exists(failureFile)) | ||
| File.Delete(failureFile); | ||
| ExampleMetadataParser.CleanupExampleFragments(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.