Skip to content

Commit

Permalink
GH-74 :: TrainingGuides.Web.Tests folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikag2 committed Oct 7, 2024
1 parent 9120a4f commit c237395
Show file tree
Hide file tree
Showing 8 changed files with 1,439 additions and 0 deletions.
File renamed without changes.
52 changes: 52 additions & 0 deletions test/TrainingGuides.Web.Tests/ArticlePageServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Xunit;
using CMS.Websites;
using Moq;
using TrainingGuides.Web.Features.Articles.Services;
using TrainingGuides.Web.Features.Articles;
using Microsoft.AspNetCore.Html;

namespace TrainingGuides.Web.Tests;

public class ArticlePageServiceTests
{
private readonly Mock<ArticlePageService> articlePageServiceMock;
private readonly Mock<IWebPageUrlRetriever> webPageUrlRetrieverMock;

private const string TEST_URL = "test";

public ArticlePageServiceTests()
{
webPageUrlRetrieverMock = new Mock<IWebPageUrlRetriever>();
webPageUrlRetrieverMock.Setup(x => x.Retrieve(It.IsAny<ArticlePage>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new WebPageUrl(TEST_URL));

articlePageServiceMock = new Mock<ArticlePageService>(webPageUrlRetrieverMock.Object);
}

[Fact]
public async Task GetArticlePageViewModel_ShouldReturnArticleWithUrl()
{
ArticlePageViewModel referenceViewModel = new()
{
Title = string.Empty,
Summary = HtmlString.Empty,
Text = HtmlString.Empty,
Url = TEST_URL
};

var articlePage = new ArticlePage()
{
ArticlePageArticleContent = [new GeneralArticle()
{
ArticleSchemaTitle = "Title",
ArticleSchemaSummary = "Summary",
ArticleSchemaText = "Text",
ArticleSchemaTeaser = []
}],
ArticlePagePublishDate = DateTime.Now
};
var viewModelWithUrl = await articlePageServiceMock.Object.GetArticlePageViewModel(articlePage);

Assert.Equal(referenceViewModel.Url, viewModelWithUrl.Url);
}
}
32 changes: 32 additions & 0 deletions test/TrainingGuides.Web.Tests/ArticlePageViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Html;
using TrainingGuides.Web.Features.Articles;
using TrainingGuides.Web.Features.Shared.Models;
using Xunit;
using Xunit.Abstractions;

namespace TrainingGuides.Web.Tests;

public class ArticlePageViewModelTests
{
private readonly ArticlePageViewModel viewModel = new();

[Fact]
public void ViewModel_Initialized_TitleIsEmpty()
{
ArticlePageViewModel referenceViewModel = new()
{
Title = string.Empty,
Summary = HtmlString.Empty,
Text = HtmlString.Empty,
TeaserImage = new AssetViewModel(),
Url = string.Empty
};
Assert.Equal(referenceViewModel.Title, viewModel.Title);
}

[Fact]
public void ViewModel_Initialized_TeaserIsNull()
{
Assert.Null(viewModel.TeaserImage);
}
}
32 changes: 32 additions & 0 deletions test/TrainingGuides.Web.Tests/TrainingGuides.Web.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TrainingGuides.Web\TrainingGuides.Web.csproj" />
<ProjectReference Include="..\TrainingGuides.Entities\TrainingGuides.Entities.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.abstractions" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
Loading

0 comments on commit c237395

Please sign in to comment.