-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from futurum-dev/feature/adding-tests
Adding tests and Result and Option WithValueAssertion methods
- Loading branch information
Showing
8 changed files
with
819 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# dotnet.futurum.test | ||
|
||
![CI](https://github.com/futurum-dev/dotnet.futurum.test/workflows/CI/badge.svg) | ||
[![Coverage Status](https://coveralls.io/repos/github/futurum-dev/dotnet.futurum.test/badge.svg?branch=main)](https://coveralls.io/github/futurum-dev/dotnet.futurum.test?branch=main) | ||
[![NuGet version](https://img.shields.io/nuget/v/futurum.test.svg?style=flat&label=nuget%3A%20futurum.test)](https://www.nuget.org/packages/futurum.test) | ||
|
||
Small dotnet testing library, allowing you to test code that uses Futurum.Core |
This file contains 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
This file contains 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
This file contains 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,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.3.0" /> | ||
<PackageReference Include="Futurum.Core" Version="1.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | ||
<PackageReference Include="coverlet.msbuild" Version="3.1.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Futurum.Test\Futurum.Test.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
244 changes: 244 additions & 0 deletions
244
test/Futurum.Test.Tests/Option/FluentAssertionOptionExtensionsTests.cs
This file contains 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,244 @@ | ||
using FluentAssertions; | ||
|
||
using Futurum.Test.Option; | ||
|
||
using Xunit; | ||
|
||
namespace Futurum.Test.Tests.Option; | ||
|
||
public class FluentAssertionOptionExtensionsTests | ||
{ | ||
public class ShouldBeHasValue | ||
{ | ||
[Fact] | ||
public void HasValue() | ||
{ | ||
var option = Core.Option.Option.From(10); | ||
|
||
option.ShouldBeHasValue(); | ||
} | ||
|
||
[Fact] | ||
public void HasNoValue() | ||
{ | ||
var option = Core.Option.Option.None<int>(); | ||
|
||
var action = () => option.ShouldBeHasValue(); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected option.HasValue to be true, but found False."); | ||
} | ||
} | ||
|
||
public class ShouldBeHasValueWithValue | ||
{ | ||
[Fact] | ||
public void HasValue_matches() | ||
{ | ||
var value = 10; | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
option.ShouldBeHasValueWithValue(value); | ||
} | ||
|
||
[Fact] | ||
public void HasValue_doesnt_match() | ||
{ | ||
var value = 10; | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
var action = () => option.ShouldBeHasValueWithValue(20); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected option.Value to be 20, but found 10."); | ||
} | ||
|
||
[Fact] | ||
public void HasNoValue() | ||
{ | ||
var option = Core.Option.Option.None<int>(); | ||
|
||
var action = () => option.ShouldBeHasValueWithValue(10); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected option.HasValue to be true, but found False."); | ||
} | ||
} | ||
|
||
public class ShouldBeHasValueWithValueWithSelector | ||
{ | ||
[Fact] | ||
public void HasValue_matches() | ||
{ | ||
var value = new TestClass(10); | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
option.ShouldBeHasValueWithValue(x => x.Number, value.Number); | ||
} | ||
|
||
[Fact] | ||
public void HasValue_doesnt_match() | ||
{ | ||
var value = new TestClass(10); | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
var action = () => option.ShouldBeHasValueWithValue(x => x.Number, 20); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected selectorFunc(option.Value) to be 20, but found 10."); | ||
} | ||
|
||
[Fact] | ||
public void HasNoValue() | ||
{ | ||
var option = Core.Option.Option.None<TestClass>(); | ||
|
||
var action = () => option.ShouldBeHasValueWithValue(x => x.Number, 10); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected option.HasValue to be true, but found False."); | ||
} | ||
} | ||
|
||
public class ShouldBeHasValueWithValueEquivalentTo | ||
{ | ||
[Fact] | ||
public void HasValue_matches() | ||
{ | ||
var value = new TestClass(10); | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
option.ShouldBeHasValueWithValueEquivalentTo(new TestClass(10)); | ||
} | ||
|
||
[Fact] | ||
public void HasValue_doesnt_match() | ||
{ | ||
var value = new TestClass(10); | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
var action = () => option.ShouldBeHasValueWithValueEquivalentTo(new TestClass(20)); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected property option.Value.Number to be 20, but found 10."); | ||
} | ||
|
||
[Fact] | ||
public void HasNoValue() | ||
{ | ||
var option = Core.Option.Option.None<TestClass>(); | ||
|
||
var action = () => option.ShouldBeHasValueWithValueEquivalentTo(new TestClass(20)); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected option.HasValue to be true, but found False."); | ||
} | ||
} | ||
|
||
public class ShouldBeHasValueWithValueEquivalentToWithSelector | ||
{ | ||
[Fact] | ||
public void HasValue_matches() | ||
{ | ||
var value = new TestChildClass(10); | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
option.ShouldBeHasValueWithValueEquivalentTo(x => x.Child, new TestChildClass.ChildClass(10)); | ||
} | ||
|
||
[Fact] | ||
public void HasValue_doesnt_match() | ||
{ | ||
var value = new TestChildClass(10); | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
var action = () => option.ShouldBeHasValueWithValueEquivalentTo(x => x.Child, new TestChildClass.ChildClass(20)); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected property selectorFunc(option.Value).Number to be 20, but found 10."); | ||
} | ||
|
||
[Fact] | ||
public void HasNoValue() | ||
{ | ||
var option = Core.Option.Option.None<TestChildClass>(); | ||
|
||
var action = () => option.ShouldBeHasValueWithValueEquivalentTo(x => x.Child, new TestChildClass.ChildClass(10)); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected option.HasValue to be true, but found False."); | ||
} | ||
} | ||
|
||
public class ShouldBeHasValueWithValueAssertion | ||
{ | ||
[Fact] | ||
public void HasValue_matches() | ||
{ | ||
var value = 10; | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
option.ShouldBeHasValueWithValueAssertion(x => x.Should().Be(value)); | ||
} | ||
|
||
[Fact] | ||
public void HasValue_doesnt_match() | ||
{ | ||
var value = 10; | ||
|
||
var option = Core.Option.Option.From(value); | ||
|
||
var action = () => option.ShouldBeHasValueWithValueAssertion(x => x.Should().NotBe(value)); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Did not expect x to be 10"); | ||
} | ||
|
||
[Fact] | ||
public void HasNoValue() | ||
{ | ||
var option = Core.Option.Option.None<int>(); | ||
|
||
var action = () => option.ShouldBeHasValueWithValueAssertion(x => x.Should().Be(10)); | ||
|
||
action.Should().Throw<Xunit.Sdk.XunitException>().Which.Message.Should().Contain("Expected option.HasValue to be true, but found False."); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void ShouldBeHasNoValue() | ||
{ | ||
var option = Core.Option.Option.None<int>(); | ||
|
||
option.ShouldBeHasNoValue(); | ||
} | ||
|
||
private class TestClass | ||
{ | ||
public int Number { get; } | ||
|
||
public TestClass(int number) | ||
{ | ||
Number = number; | ||
} | ||
} | ||
|
||
private class TestChildClass | ||
{ | ||
public ChildClass Child { get; } | ||
|
||
public TestChildClass(int number) | ||
{ | ||
Child = new ChildClass(number); | ||
} | ||
|
||
public class ChildClass | ||
{ | ||
public int Number { get; } | ||
|
||
public ChildClass(int number) | ||
{ | ||
Number = number; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.