Skip to content

Commit 27a7168

Browse files
authored
TestProject (#44)
1 parent 63bed59 commit 27a7168

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="bunit" Version="1.12.4-preview" />
13+
<PackageReference Include="CodecovUploader" Version="0.3.2" />
14+
<PackageReference Include="FluentAssertions" Version="6.8.0" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
16+
<PackageReference Include="NUnit" Version="3.13.3" />
17+
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
18+
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
19+
<PackageReference Include="coverlet.collector" Version="3.1.2" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\CodeBeam.MudExtensions\CodeBeam.MudExtensions.csproj" />
24+
</ItemGroup>
25+
26+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) MudBlazor 2021
2+
// MudBlazor licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Threading.Tasks;
7+
using NUnit.Framework;
8+
9+
namespace CodeBeam.MudExtensions.UnitTests.Components
10+
{
11+
public abstract class BunitTest
12+
{
13+
protected Bunit.TestContext Context { get; private set; }
14+
15+
[SetUp]
16+
public virtual void Setup()
17+
{
18+
Context = new();
19+
//Context.AddTestServices();
20+
}
21+
22+
[TearDown]
23+
public void TearDown()
24+
{
25+
try
26+
{
27+
Context.Dispose();
28+
}
29+
catch (Exception)
30+
{
31+
/*ignore*/
32+
}
33+
}
34+
35+
protected async Task ImproveChanceOfSuccess(Func<Task> testAction)
36+
{
37+
for (int i = 0; i < 10; i++)
38+
{
39+
try
40+
{
41+
await testAction();
42+
return;
43+
}
44+
catch(Exception) { /*we don't care here*/ }
45+
}
46+
await testAction();
47+
}
48+
}
49+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Bunit;
7+
using CodeBeam.MudExtensions.UnitTests.Components;
8+
using FluentAssertions;
9+
using MudBlazor;
10+
using MudExtensions;
11+
12+
namespace CodeBeam.MudExtensions.UnitTest.Components
13+
{
14+
[TestFixture]
15+
public class StepperTests : BunitTest
16+
{
17+
[Test]
18+
public void StepperRenderTest()
19+
{
20+
var comp = Context.RenderComponent<MudStepper>();
21+
comp.Instance.Steps.Count.Should().Be(0);
22+
}
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace CodeBeam.MudExtensions.UnitTest
2+
{
3+
public class Tests
4+
{
5+
[SetUp]
6+
public void Setup()
7+
{
8+
}
9+
10+
[Test]
11+
public void Test1()
12+
{
13+
Assert.Pass();
14+
}
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using NUnit.Framework;

CodeBeamMudExtensions.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentViewer", "Componen
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentViewer.Wasm", "ComponentViewer.Wasm\ComponentViewer.Wasm.csproj", "{924E72FF-1B0D-4465-9805-AB7B9D114113}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComponentViewer.Docs", "ComponentViewer.Docs\ComponentViewer.Docs.csproj", "{D4DCAB94-89CB-414A-A153-B32830C42682}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentViewer.Docs", "ComponentViewer.Docs\ComponentViewer.Docs.csproj", "{D4DCAB94-89CB-414A-A153-B32830C42682}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeBeam.MudExtensions.UnitTest", "CodeBeam.MudExtensions.UnitTest\CodeBeam.MudExtensions.UnitTest.csproj", "{75F2BF6B-9046-4E68-BA97-ED1CA2C1D572}"
1315
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -33,6 +35,10 @@ Global
3335
{D4DCAB94-89CB-414A-A153-B32830C42682}.Debug|Any CPU.Build.0 = Debug|Any CPU
3436
{D4DCAB94-89CB-414A-A153-B32830C42682}.Release|Any CPU.ActiveCfg = Release|Any CPU
3537
{D4DCAB94-89CB-414A-A153-B32830C42682}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{75F2BF6B-9046-4E68-BA97-ED1CA2C1D572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{75F2BF6B-9046-4E68-BA97-ED1CA2C1D572}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{75F2BF6B-9046-4E68-BA97-ED1CA2C1D572}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{75F2BF6B-9046-4E68-BA97-ED1CA2C1D572}.Release|Any CPU.Build.0 = Release|Any CPU
3642
EndGlobalSection
3743
GlobalSection(SolutionProperties) = preSolution
3844
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)