|
1 | 1 | using Fluxor.Blazor.Web.UnitTests.SupportFiles;
|
| 2 | +using System; |
2 | 3 | using Xunit;
|
3 | 4 |
|
4 | 5 | namespace Fluxor.Blazor.Web.UnitTests.Components.FluxorComponentTests
|
5 | 6 | {
|
6 | 7 | public class DisposeTests
|
7 | 8 | {
|
8 |
| - private readonly FluxorComponentWithStateProperties Subject; |
| 9 | + private readonly FluxorComponentWithStateProperties StateSubject; |
9 | 10 | private readonly MockState<int> MockState1;
|
10 | 11 | private readonly MockState<int> MockState2;
|
11 | 12 |
|
12 | 13 | [Fact]
|
13 | 14 | public void UnsubscribesFromStateProperties()
|
14 | 15 | {
|
15 |
| - Subject.ExecuteOnInitialized(); |
16 |
| - Subject.Dispose(); |
| 16 | + StateSubject.ExecuteOnInitialized(); |
| 17 | + StateSubject.Dispose(); |
17 | 18 |
|
18 | 19 | Assert.Equal(1, MockState1.UnsubscribeCount);
|
19 | 20 | Assert.Equal(1, MockState2.UnsubscribeCount);
|
20 | 21 | }
|
21 | 22 |
|
| 23 | + [Fact] |
| 24 | + public void WhenBaseOnInitializedWasNotCalled_ThenThrowsNullReferenceException() |
| 25 | + { |
| 26 | + string errorMessage = null; |
| 27 | + var component = new FluxorComponentThatOptionallyCallsBaseOnInitialized(); |
| 28 | + try |
| 29 | + { |
| 30 | + component.Test_OnInitialized(); |
| 31 | + component.Dispose(); |
| 32 | + } |
| 33 | + catch (NullReferenceException e) |
| 34 | + { |
| 35 | + errorMessage = e.Message; |
| 36 | + } |
| 37 | + Assert.Equal("Have you forgotten to call base.OnInitialized() in your component?", errorMessage); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public void WhenBaseOnInitializedWasCalled_ThenDoesNotThrowAnException() |
| 42 | + { |
| 43 | + var component = new FluxorComponentThatOptionallyCallsBaseOnInitialized |
| 44 | + { |
| 45 | + CallBaseOnInitialized = true |
| 46 | + }; |
| 47 | + component.Test_OnInitialized(); |
| 48 | + component.Dispose(); |
| 49 | + } |
| 50 | + |
22 | 51 | public DisposeTests()
|
23 | 52 | {
|
24 | 53 | MockState1 = new MockState<int>();
|
25 | 54 | MockState2 = new MockState<int>();
|
26 |
| - Subject = new FluxorComponentWithStateProperties |
| 55 | + StateSubject = new FluxorComponentWithStateProperties |
27 | 56 | {
|
28 | 57 | State1 = MockState1,
|
29 | 58 | State2 = MockState2
|
|
0 commit comments