-
Notifications
You must be signed in to change notification settings - Fork 7
Added test project & github action to run tests #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/0.5.0
Are you sure you want to change the base?
Changes from 12 commits
c260fd8
2358c52
6f710d9
18ccf69
949290d
28ceca9
abae787
d61bd9a
ccb399b
d433837
554a389
ea92ba5
1ff0e54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # The name of the workflow. | ||
| # This is the name that's displayed for status | ||
| # badges (commonly embedded in README.md files). | ||
| name: tests | ||
|
|
||
| # Trigger this workflow on a push, or pull request to | ||
| # the production branch, when either C# or project files changed | ||
| on: | ||
| push: | ||
| pull_request: | ||
| branches: [ main ] | ||
| paths-ignore: | ||
| - 'README.md' | ||
|
|
||
| # Create an environment variable named DOTNET_VERSION | ||
| # and set it as "6.0.x" | ||
| env: | ||
| DOTNET_VERSION: '6.0.x' # The .NET SDK version to use | ||
|
|
||
| # Defines a single job named "build-and-test" | ||
| jobs: | ||
| build-and-test: | ||
|
|
||
| # When the workflow runs, this is the name that is logged | ||
| # This job will run three times, once for each "os" defined | ||
| name: build-and-test-${{matrix.os}} | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest] | ||
|
|
||
| # Each job run contains these five steps | ||
| steps: | ||
| # 1) Check out the source code so that the workflow can access it. | ||
| - uses: actions/checkout@v2 | ||
|
|
||
| # 2) Set up the .NET CLI environment for the workflow to use. | ||
| # The .NET version is specified by the environment variable. | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v1 | ||
| with: | ||
| dotnet-version: ${{ env.DOTNET_VERSION }} | ||
|
|
||
| # 3) Restore the dependencies and tools of a project or solution. | ||
| - name: Install dependencies | ||
| working-directory: ./Source | ||
| run: dotnet restore | ||
|
|
||
| # 4) Build a project or solution and all of its dependencies. | ||
| - name: Build | ||
| working-directory: ./Source | ||
| run: dotnet build --configuration Debug --no-restore | ||
|
|
||
| # 5) Test a project or solution. | ||
| - name: Test | ||
| working-directory: ./Source | ||
| run: dotnet test --no-restore --verbosity normal | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
| <PackageReference Include="xunit" Version="2.4.1" /> | ||
| <PackageReference Include="xunit.extensibility.core" 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.0"> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Morris.Reducible\Morris.Reducible.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| using Xunit; | ||
|
|
||
| namespace Morris.Reducible.Tests | ||
| { | ||
| public class ReducerTests | ||
| { | ||
| private record CounterState(int Counter); | ||
| private record IncrementCounter(int Amount); | ||
|
|
||
|
|
||
| [Fact] | ||
| public void WhenSimpleReducerInvoked_ThenStateIsUpdated() | ||
| { | ||
| //Given | ||
| var initialState = new CounterState(0); | ||
| var action = new IncrementCounter(1); | ||
| var counterIncrementCounterReducer = Reducer | ||
| .Given<CounterState, IncrementCounter>() | ||
| .Then((state, delta) => (true, state with { Counter = state.Counter + delta.Amount})); | ||
|
|
||
| //When | ||
| (bool changed, var counterState) = counterIncrementCounterReducer.Invoke(initialState, action); | ||
mrpmorris marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
mrpmorris marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| //Then | ||
| Assert.True(changed); | ||
| Assert.Equal(new CounterState(1), counterState); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WhenConditionalReducerInvokedWithPassingCondition_ThenStateIsUpdated() | ||
| { | ||
| //Given | ||
| var initialState = new CounterState(0); | ||
| var action = new IncrementCounter(1); | ||
| var counterIncrementCounterReducer = Reducer | ||
| .Given<CounterState, IncrementCounter>() | ||
| .When((state, delta) => state.Counter < 2) | ||
| .Then((state, delta) => state with { Counter = state.Counter + delta.Amount }); | ||
|
|
||
| //When | ||
| (bool changed, var counterState) = counterIncrementCounterReducer.Invoke(initialState, action); | ||
|
|
||
| //Then | ||
| Assert.True(changed); | ||
| Assert.Equal(new CounterState(1), counterState); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WhenConditionalReducerInvokedWithFailingCondition_ThenStateIsNotUpdated() | ||
| { | ||
| //Given | ||
| var initialState = new CounterState(0); | ||
| var action = new IncrementCounter(1); | ||
| var counterIncrementCounterReducer = Reducer | ||
| .Given<CounterState, IncrementCounter>() | ||
| .When((state, delta) => state.Counter > 2) | ||
| .Then((state, delta) => state with { Counter = state.Counter + delta.Amount }); | ||
|
|
||
| //When | ||
| (bool changed, var counterState) = counterIncrementCounterReducer.Invoke(initialState, action); | ||
|
|
||
| //Then | ||
| Assert.False(changed); | ||
| Assert.Equal(new CounterState(0), counterState); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WhenCombinedReducerInvoked_ThenStateIsUpdated() | ||
| { | ||
| //Given | ||
| var initialState = new CounterState(0); | ||
| var action = new IncrementCounter(1); | ||
| var counterIncrementCounterReducer1 = Reducer | ||
| .Given<CounterState, IncrementCounter>() | ||
| .Then((state, delta) => (true, state with { Counter = state.Counter + delta.Amount })); | ||
|
|
||
| var counterIncrementCounterReducer2 = Reducer | ||
| .Given<CounterState, IncrementCounter>() | ||
| .Then((state, delta) => (true, state with { Counter = state.Counter + delta.Amount })); | ||
| var combinedReducer = Reducer.Combine(counterIncrementCounterReducer1, counterIncrementCounterReducer2); | ||
|
|
||
| //When | ||
| (bool changed, var counterState) = combinedReducer.Invoke(initialState, action); | ||
|
|
||
| //Then | ||
| Assert.True(changed); | ||
| Assert.Equal(new CounterState(2), counterState); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,8 @@ public class ConditionBuilder<TState, TDelta> | |
| { | ||
| internal ConditionBuilder() { } | ||
|
|
||
| public ResultMapper<TState, TDelta> When(Func<TState, TDelta, bool> condition) => new ResultMapper<TState, TDelta>(condition); | ||
| public ResultMapper<TState, TDelta> When(Func<TState, TDelta, bool> condition) => | ||
| new ResultMapper<TState, TDelta>(condition); | ||
|
|
||
| public Func<TState, TDelta, Result<TState>> Then(Func<TState, TDelta, Result<TState>> reducer) | ||
| { | ||
|
|
@@ -20,15 +21,11 @@ public Func<TState, TDelta, Result<TState>> Then(Func<TState, TDelta, Result<TSt | |
| } | ||
|
|
||
| public ObjectResultMapper<TState, TSubState, TDelta> WhenReducedBy<TSubState>( | ||
| Func<TState, TSubState> subStateSelector, | ||
| Func<TSubState, TDelta, Result<TSubState>> reducer) | ||
| => | ||
| Func<TState, TSubState> subStateSelector, Func<TSubState, TDelta, Result<TSubState>> reducer) => | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer all of the original code in this case.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted |
||
| new ObjectResultMapper<TState, TSubState, TDelta>(subStateSelector, reducer); | ||
|
|
||
| public ImmutableArrayResultMapper<TState, TElement, TDelta> WhenReducedBy<TElement>( | ||
| Func<TState, ImmutableArray<TElement>> subStateSelector, | ||
| Func<TElement, TDelta, Result<TElement>> reducer) | ||
| => | ||
| new ImmutableArrayResultMapper<TState, TElement, TDelta>(subStateSelector, reducer); | ||
| Func<TState, ImmutableArray<TElement>> subStateSelector, Func<TElement, TDelta, Result<TElement>> reducer) => | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the original code here too.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted |
||
| new ImmutableArrayResultMapper<TState, TElement, TDelta>(subStateSelector, reducer); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.