Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8aeaca1

Browse files
committed
refactor: use shouldly library in tests
1 parent264b5d0 commit8aeaca1

14 files changed

+115
-101
lines changed

‎ReduxSimple.Tests/CreateReduxStoreTest.cs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
usingShouldly;
12
usingXunit;
23
usingstaticReduxSimple.Tests.Setup.TodoListStore.Functions;
34
usingEmptyStore=ReduxSimple.ReduxStore<ReduxSimple.Tests.Setup.EmptyStore.EmptyState>;
@@ -18,7 +19,7 @@ public void CanCreateAStoreWithEmptyState()
1819
// Act
1920

2021
// Assert
21-
Assert.NotNull(store.State);
22+
store.State.ShouldNotBeNull();
2223
}
2324

2425
[Fact]
@@ -34,7 +35,7 @@ public void CanCreateAStoreWithDefaultState()
3435
// Act
3536

3637
// Assert
37-
Assert.Empty(store.State.TodoList);
38+
store.State.TodoList.ShouldBeEmpty();
3839
}
3940

4041
[Fact]
@@ -52,9 +53,9 @@ public void CreatingAStoreShouldDispatchInitializeAction()
5253
varhistory=store.GetHistory();
5354

5455
// Assert
55-
Assert.Single(history.PreviousStates);
56-
Assert.IsType<InitializeStoreAction>(history.PreviousStates[0].Action);
57-
Assert.Empty(history.FutureActions);
56+
varpreviousState=history.PreviousStates.ShouldHaveSingleItem();
57+
previousState.Action.ShouldBeOfType<InitializeStoreAction>();
58+
history.FutureActions.ShouldBeEmpty();
5859
}
5960
}
6061
}

‎ReduxSimple.Tests/CreateSubReducersTest.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usingReduxSimple.Tests.Setup.NestedStore;
2+
usingShouldly;
23
usingSystem;
34
usingSystem.Linq;
45
usingXunit;
@@ -40,8 +41,8 @@ public void CanCreateAndUseSubReducers()
4041
store.Dispatch(newUpdateNumberAction{Number=10});
4142

4243
// Assert
43-
Assert.Equal(2,observeCount);
44-
Assert.Equal(10,lastResult);
44+
observeCount.ShouldBe(2);
45+
lastResult.ShouldBe(10);
4546
}
4647
}
4748
}

‎ReduxSimple.Tests/DispatchTest.cs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
usingXunit;
1+
usingShouldly;
2+
usingXunit;
23
usingstaticReduxSimple.Tests.Setup.TodoListStore.Functions;
34
usingTodoListStore=ReduxSimple.ReduxStore<ReduxSimple.Tests.Setup.TodoListStore.TodoListState>;
45

@@ -20,7 +21,7 @@ public void CanDispatchAction()
2021
DispatchAddTodoItemAction(store,1,"Create unit tests");
2122

2223
// Assert
23-
Assert.Single(store.State.TodoList);
24+
store.State.TodoList.ShouldHaveSingleItem();
2425
}
2526

2627
[Fact]
@@ -38,8 +39,8 @@ public void CanDispatchDifferentActions()
3839
DispatchSwitchUserAction(store,"Emily");
3940

4041
// Assert
41-
Assert.Single(store.State.TodoList);
42-
Assert.Equal("Emily",store.State.CurrentUser);
42+
store.State.TodoList.ShouldHaveSingleItem();
43+
store.State.CurrentUser.ShouldBe("Emily");
4344
}
4445
}
4546
}

‎ReduxSimple.Tests/EffectsTest.cs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
usingXunit;
1+
usingShouldly;
2+
usingXunit;
23
usingReduxSimple.Tests.Setup.TodoListStore;
34
usingSystem.Reactive.Linq;
45
usingstaticReduxSimple.Tests.Setup.TodoListStore.Functions;
@@ -46,8 +47,8 @@ public void CanUseEffectWithDispatch()
4647
DispatchAddTodoItemAction(store,1,"Create unit tests");
4748

4849
// Assert
49-
Assert.Equal(2,store.State.TodoList?.Count);
50-
Assert.Equal(1,calls);
50+
store.State.TodoList?.Count.ShouldBe(2);
51+
calls.ShouldBe(1);
5152
}
5253

5354
[Fact]
@@ -75,8 +76,8 @@ public void CanUseEffectWithoutDispatch()
7576
DispatchAddTodoItemAction(store,1,"Create unit tests");
7677

7778
// Assert
78-
Assert.Single(store.State.TodoList);
79-
Assert.Equal(1,calls);
79+
store.State.TodoList.ShouldHaveSingleItem();
80+
calls.ShouldBe(1);
8081
}
8182
}
8283
}

‎ReduxSimple.Tests/NestedArrayStoreTest.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usingReduxSimple.Tests.Setup.NestedArrayStore;
2+
usingShouldly;
23
usingSystem;
34
usingSystem.Linq;
45
usingXunit;
@@ -61,12 +62,12 @@ public void ThrowExceptionIfUsingIndexedArrayForNestedStates()
6162
lastResult4=number;
6263
});
6364

64-
varexception=Assert.Throws<NotSupportedException>(()=>
65+
varexception=Should.Throw<NotSupportedException>(()=>
6566
store.Dispatch(newUpdateNumberAction{Number=10})
6667
);
6768

6869
// Assert
69-
Assert.Equal("A sub-reducer cannot find the feature reducer of `NestedState` inside `RootState`.",exception.Message);
70+
exception.Message.ShouldBe("A sub-reducer cannot find the feature reducer of `NestedState` inside `RootState`.");
7071
}
7172
}
7273
}

‎ReduxSimple.Tests/ObserveActionTest.cs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usingReduxSimple.Tests.Setup.TodoListStore;
2+
usingShouldly;
23
usingSystem;
34
usingXunit;
45
usingstaticReduxSimple.Tests.Setup.TodoListStore.Functions;
@@ -32,8 +33,8 @@ public void CanObserveActions()
3233
DispatchAllActions(store);
3334

3435
// Assert
35-
Assert.Equal(4,observeCount);
36-
Assert.IsType<AddTodoItemAction>(lastAction);
36+
observeCount.ShouldBe(4);
37+
lastAction.ShouldBeOfType<AddTodoItemAction>();
3738
}
3839

3940
[Fact]
@@ -60,8 +61,8 @@ public void CanObserveSingleActionType()
6061
DispatchAllActions(store);
6162

6263
// Assert
63-
Assert.Equal(1,observeCount);
64-
Assert.IsType<SwitchUserAction>(lastAction);
64+
observeCount.ShouldBe(1);
65+
lastAction.ShouldBeOfType<SwitchUserAction>();
6566
}
6667
}
6768
}

‎ReduxSimple.Tests/RedoTest.cs‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
usingSystem;
1+
usingShouldly;
2+
usingSystem;
23
usingXunit;
34
usingstaticReduxSimple.Tests.Setup.TodoListStore.Functions;
45
usingTodoListStore=ReduxSimple.ReduxStore<ReduxSimple.Tests.Setup.TodoListStore.TodoListState>;
@@ -21,29 +22,29 @@ public void CanRedo()
2122
// Act
2223
DispatchAllActions(store);
2324

24-
Assert.True(store.CanUndo);
25+
store.CanUndo.ShouldBeTrue();
2526

2627
store.Undo();
2728

28-
Assert.True(store.CanUndo);
29+
store.CanUndo.ShouldBeTrue();
2930

3031
store.Undo();
3132

32-
Assert.True(store.CanUndo);
33+
store.CanUndo.ShouldBeTrue();
3334

3435
store.Undo();
3536

36-
Assert.True(store.CanRedo);
37+
store.CanRedo.ShouldBeTrue();
3738

3839
store.Redo();
3940

40-
Assert.True(store.CanRedo);
41+
store.CanRedo.ShouldBeTrue();
4142

4243
store.Redo();
4344

4445
// Assert
45-
Assert.Equal(2,store.State.TodoList?.Count);
46-
Assert.Equal("Emily",store.State.CurrentUser);
46+
store.State.TodoList?.Count.ShouldBe(2);
47+
store.State.CurrentUser.ShouldBe("Emily");
4748
}
4849

4950
[Fact]
@@ -61,7 +62,7 @@ public void CannotRedo()
6162
DispatchAllActions(store);
6263

6364
// Assert
64-
Assert.False(store.CanRedo);
65+
store.CanRedo.ShouldBeFalse();
6566
}
6667

6768
[Fact]
@@ -93,7 +94,7 @@ public void RedoAndObserveNormalTimelineActionsOnly()
9394
store.Redo();
9495

9596
// Assert
96-
Assert.Equal(4,observeCount);
97+
observeCount.ShouldBe(4);
9798
}
9899

99100
[Fact]
@@ -125,7 +126,7 @@ public void RedoAndObserveRedoneActionsOnly()
125126
store.Redo();
126127

127128
// Assert
128-
Assert.Equal(2,observeCount);
129+
observeCount.ShouldBe(2);
129130
}
130131
}
131132
}

‎ReduxSimple.Tests/ReduceTests.cs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usingReduxSimple.Tests.Setup.MultiReduceStore;
2+
usingShouldly;
23
usingXunit;
34
usingMultiReduceStore=ReduxSimple.ReduxStore<ReduxSimple.Tests.Setup.MultiReduceStore.MultiReduceState>;
45

@@ -18,9 +19,9 @@ public void CanExecuteMultipleReducers()
1819
store.Dispatch(newUpdateNumberAction{Number=12});
1920

2021
// Assert
21-
Assert.Equal(12,store.State.Number1);
22-
Assert.Equal(12,store.State.Number2);
23-
Assert.Equal(12,store.State.Number3);
22+
store.State.Number1.ShouldBe(12);
23+
store.State.Number2.ShouldBe(12);
24+
store.State.Number3.ShouldBe(12);
2425
}
2526
}
2627
}

‎ReduxSimple.Tests/ReduxSimple.Tests.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ItemGroup>
1313
<PackageReferenceInclude="Converto"Version="2.1.0" />
1414
<PackageReferenceInclude="Microsoft.NET.Test.Sdk"Version="15.5.0" />
15+
<PackageReferenceInclude="Shouldly"Version="3.0.2" />
1516
<PackageReferenceInclude="xunit"Version="2.4.1" />
1617
<PackageReferenceInclude="xunit.runner.visualstudio"Version="2.4.1" />
1718
<DotNetCliToolReferenceInclude="dotnet-xunit"Version="2.3.1" />

‎ReduxSimple.Tests/ResetTest.cs‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
usingReduxSimple.Tests.Setup.TodoListStore;
2+
usingShouldly;
23
usingSystem;
34
usingXunit;
45
usingstaticReduxSimple.Tests.Setup.TodoListStore.Functions;
@@ -32,18 +33,18 @@ public void CanResetStoreWithUndoneActions()
3233

3334
DispatchAllActions(store);
3435

35-
Assert.True(store.CanUndo);
36+
store.CanUndo.ShouldBeTrue();
3637

3738
store.Undo();
3839

3940
store.Reset();
4041

4142
// Assert
42-
Assert.Equal(1,observeCount);
43-
Assert.Empty(lastState?.TodoList);
44-
Assert.Equal("David",lastState?.CurrentUser);
45-
Assert.False(store.CanRedo);
46-
Assert.False(store.CanUndo);
43+
observeCount.ShouldBe(1);
44+
lastState?.TodoList.ShouldBeEmpty();
45+
lastState?.CurrentUser.ShouldBe("David");
46+
store.CanRedo.ShouldBeFalse();
47+
store.CanUndo.ShouldBeFalse();
4748
}
4849

4950
[Fact]
@@ -73,9 +74,9 @@ public void CanResetStore()
7374
store.Reset();
7475

7576
// Assert
76-
Assert.Equal(1,observeCount);
77-
Assert.Empty(lastState?.TodoList);
78-
Assert.Equal("David",lastState?.CurrentUser);
77+
observeCount.ShouldBe(1);
78+
lastState?.TodoList.ShouldBeEmpty();
79+
lastState?.CurrentUser.ShouldBe("David");
7980
}
8081

8182
[Fact]
@@ -105,10 +106,10 @@ public void ObserveHistoryOnReset()
105106
store.Reset();
106107

107108
// Assert
108-
Assert.Equal(5,observeCount);
109-
Assert.Single(lastHistory?.PreviousStates);
110-
Assert.IsType<InitializeStoreAction>(lastHistory?.PreviousStates[0].Action);
111-
Assert.Empty(lastHistory?.FutureActions);
109+
observeCount.ShouldBe(5);
110+
varpreviousState=lastHistory?.PreviousStates.ShouldHaveSingleItem();
111+
previousState?.Action.ShouldBeOfType<InitializeStoreAction>();
112+
lastHistory?.FutureActions.ShouldBeEmpty();
112113
}
113114
}
114115
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp