Skip to content

Commit

Permalink
xUnit 기반 유닛 테스트 초안 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
rkttu committed Nov 9, 2023
1 parent d54f5f1 commit c5bf5ea
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/TableCloth.Test/ContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace TableCloth.Test;

using Microsoft.Extensions.DependencyInjection;
using TableCloth.Components;
using TableCloth.Resources;

public class ContainerFixture
{
public ContainerFixture()
{
var svcCollection = new ServiceCollection();
svcCollection
.AddLogging()
.AddHttpClient(nameof(TableCloth), c =>
{
c.DefaultRequestHeaders.Add("User-Agent", StringResources.UserAgentText);
});

svcCollection.AddSingleton<ResourceResolver>();
ServiceProvider = svcCollection.BuildServiceProvider();
}

public ServiceProvider ServiceProvider { get; private set; }
}
38 changes: 38 additions & 0 deletions src/TableCloth.Test/ResourceResolverTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TableCloth.Components;

namespace TableCloth.Test
{
public class ResourceResolverTest : IClassFixture<ContainerFixture>
{
public ResourceResolverTest(ContainerFixture fixture)
{
serviceProvider = fixture.ServiceProvider;
resourceResolver = serviceProvider.GetService<ResourceResolver>() ??
throw new Exception("Cannot obtain resource resolver due to configuration");
}

private IServiceProvider serviceProvider;
private ResourceResolver resourceResolver;

[Fact]
public async Task TestGetLatestVersion()
{
// Arrange
const string repoOwner = "yourtablecloth";
const string repoName = "TableCloth";

// Act
var result = await resourceResolver.GetLatestVersion(repoOwner, repoName);

// Assert
Assert.NotNull(result);
Assert.NotEmpty(result);
}
}
}
32 changes: 32 additions & 0 deletions src/TableCloth.Test/TableCloth.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0-windows10.0.18362.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>

<Platforms>x64;ARM64</Platforms>
</PropertyGroup>

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

<ItemGroup>
<ProjectReference Include="..\TableCloth\TableCloth.csproj" />
</ItemGroup>

<Import Project="..\TableCloth.Shared\TableCloth.Shared.projitems" Label="Shared" />

</Project>
1 change: 1 addition & 0 deletions src/TableCloth.Test/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
11 changes: 11 additions & 0 deletions src/TableCloth.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TableCloth.ResourceBuilder"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Loom", "Loom\Loom.csproj", "{25CA9322-D817-4F66-AC5A-8A88794162AF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TableCloth.Test", "TableCloth.Test\TableCloth.Test.csproj", "{00E9E604-57A3-41DF-AF08-F0436D4FF9BA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Expand Down Expand Up @@ -92,6 +94,14 @@ Global
{25CA9322-D817-4F66-AC5A-8A88794162AF}.Release|ARM64.Build.0 = Release|ARM64
{25CA9322-D817-4F66-AC5A-8A88794162AF}.Release|x64.ActiveCfg = Release|x64
{25CA9322-D817-4F66-AC5A-8A88794162AF}.Release|x64.Build.0 = Release|x64
{00E9E604-57A3-41DF-AF08-F0436D4FF9BA}.Debug|ARM64.ActiveCfg = Debug|ARM64
{00E9E604-57A3-41DF-AF08-F0436D4FF9BA}.Debug|ARM64.Build.0 = Debug|ARM64
{00E9E604-57A3-41DF-AF08-F0436D4FF9BA}.Debug|x64.ActiveCfg = Debug|x64
{00E9E604-57A3-41DF-AF08-F0436D4FF9BA}.Debug|x64.Build.0 = Debug|x64
{00E9E604-57A3-41DF-AF08-F0436D4FF9BA}.Release|ARM64.ActiveCfg = Release|ARM64
{00E9E604-57A3-41DF-AF08-F0436D4FF9BA}.Release|ARM64.Build.0 = Release|ARM64
{00E9E604-57A3-41DF-AF08-F0436D4FF9BA}.Release|x64.ActiveCfg = Release|x64
{00E9E604-57A3-41DF-AF08-F0436D4FF9BA}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -100,6 +110,7 @@ Global
SolutionGuid = {7EAF7AB7-15CC-4504-8D15-C631B0996E8F}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
TableCloth.Shared\TableCloth.Shared.projitems*{00e9e604-57a3-41df-af08-f0436d4ff9ba}*SharedItemsImports = 5
TableCloth.Shared\TableCloth.Shared.projitems*{0f58b6a7-cca8-471a-b767-01c7b8f6e839}*SharedItemsImports = 13
TableCloth.Shared\TableCloth.Shared.projitems*{25ca9322-d817-4f66-ac5a-8a88794162af}*SharedItemsImports = 5
TableCloth.Shared\TableCloth.Shared.projitems*{2d6cd03c-52b2-46f2-8ec1-7480e7a92e5e}*SharedItemsImports = 5
Expand Down

0 comments on commit c5bf5ea

Please sign in to comment.