|
| 1 | +using DotNetMcp; |
| 2 | +using FluentAssertions; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace DotNetMcp.Tests; |
| 6 | + |
| 7 | +public class TemplateEngineHelperTests |
| 8 | +{ |
| 9 | + [Fact] |
| 10 | + public async Task GetInstalledTemplatesAsync_ReturnsSuccessfully() |
| 11 | + { |
| 12 | + // Act |
| 13 | + var result = await TemplateEngineHelper.GetInstalledTemplatesAsync(); |
| 14 | + |
| 15 | + // Assert |
| 16 | + result.Should().NotBeNull(); |
| 17 | + // Note: The result may indicate no templates found if the template cache hasn't been |
| 18 | + // populated yet. This is expected behavior - templates are discovered when dotnet new |
| 19 | + // commands are first run in the environment. The important thing is that the method |
| 20 | + // executes without throwing exceptions. |
| 21 | + } |
| 22 | + |
| 23 | + [Fact] |
| 24 | + public async Task SearchTemplatesAsync_ReturnsSuccessfully() |
| 25 | + { |
| 26 | + // Act |
| 27 | + var result = await TemplateEngineHelper.SearchTemplatesAsync("console"); |
| 28 | + |
| 29 | + // Assert |
| 30 | + result.Should().NotBeNull(); |
| 31 | + // The search should return successfully, even if no templates are found |
| 32 | + } |
| 33 | + |
| 34 | + [Fact] |
| 35 | + public async Task GetTemplateDetailsAsync_ReturnsSuccessfully() |
| 36 | + { |
| 37 | + // Act |
| 38 | + var result = await TemplateEngineHelper.GetTemplateDetailsAsync("console"); |
| 39 | + |
| 40 | + // Assert |
| 41 | + result.Should().NotBeNull(); |
| 42 | + // The method should return successfully with an appropriate message |
| 43 | + } |
| 44 | + |
| 45 | + [Fact] |
| 46 | + public async Task ValidateTemplateExistsAsync_ReturnsBoolean() |
| 47 | + { |
| 48 | + // Act |
| 49 | + var result = await TemplateEngineHelper.ValidateTemplateExistsAsync("console"); |
| 50 | + |
| 51 | + // Assert |
| 52 | + // Should return a boolean value without throwing - no specific assertion needed |
| 53 | + // The test passes if no exception is thrown |
| 54 | + } |
| 55 | + |
| 56 | + [Fact] |
| 57 | + public async Task ValidateTemplateExistsAsync_HandlesNonExistentTemplate() |
| 58 | + { |
| 59 | + // Act |
| 60 | + var result = await TemplateEngineHelper.ValidateTemplateExistsAsync("non-existent-template-xyz123"); |
| 61 | + |
| 62 | + // Assert |
| 63 | + // Should return false for non-existent templates |
| 64 | + result.Should().BeFalse(); |
| 65 | + } |
| 66 | + |
| 67 | + [Fact] |
| 68 | + public async Task ClearCacheAsync_ExecutesSuccessfully() |
| 69 | + { |
| 70 | + // Arrange - Load templates into cache (or try to) |
| 71 | + await TemplateEngineHelper.GetInstalledTemplatesAsync(); |
| 72 | + |
| 73 | + // Act - Clear the cache |
| 74 | + await TemplateEngineHelper.ClearCacheAsync(); |
| 75 | + |
| 76 | + // Assert - Should be able to query again after clearing |
| 77 | + var result = await TemplateEngineHelper.GetInstalledTemplatesAsync(); |
| 78 | + result.Should().NotBeNull(); |
| 79 | + } |
| 80 | +} |
0 commit comments