|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +namespace Microsoft.AspNetCore.Components; |
| 5 | + |
| 6 | +public class RestoreContextTest |
| 7 | +{ |
| 8 | + [Theory] |
| 9 | + [InlineData(RestoreBehavior.Default)] |
| 10 | + [InlineData(RestoreBehavior.SkipLastSnapshot)] |
| 11 | + public void ShouldRestore_InitialValueContext_WithDefaultOrSkipLastSnapshot(RestoreBehavior behavior) |
| 12 | + { |
| 13 | + var options = new RestoreOptions { RestoreBehavior = behavior }; |
| 14 | + |
| 15 | + var result = RestoreContext.InitialValue.ShouldRestore(options); |
| 16 | + |
| 17 | + Assert.True(result); |
| 18 | + } |
| 19 | + |
| 20 | + [Fact] |
| 21 | + public void ShouldRestore_InitialValueContext_WithSkipInitialValue() |
| 22 | + { |
| 23 | + var options = new RestoreOptions { RestoreBehavior = RestoreBehavior.SkipInitialValue }; |
| 24 | + |
| 25 | + var result = RestoreContext.InitialValue.ShouldRestore(options); |
| 26 | + |
| 27 | + Assert.False(result); |
| 28 | + } |
| 29 | + |
| 30 | + [Theory] |
| 31 | + [InlineData(RestoreBehavior.Default, true, true)] |
| 32 | + [InlineData(RestoreBehavior.Default, false, true)] |
| 33 | + [InlineData(RestoreBehavior.SkipInitialValue, true, false)] |
| 34 | + [InlineData(RestoreBehavior.SkipInitialValue, false, false)] |
| 35 | + public void ShouldRestore_InitialValueContext_ShouldRestore_IsIndependentOfAllowUpdates(RestoreBehavior behavior, bool allowUpdates, bool expectedResult) |
| 36 | + { |
| 37 | + var options = new RestoreOptions { RestoreBehavior = behavior, AllowUpdates = allowUpdates }; |
| 38 | + |
| 39 | + var result = RestoreContext.InitialValue.ShouldRestore(options); |
| 40 | + |
| 41 | + Assert.Equal(expectedResult, result); |
| 42 | + } |
| 43 | + |
| 44 | + [Theory] |
| 45 | + [InlineData(RestoreBehavior.Default)] |
| 46 | + [InlineData(RestoreBehavior.SkipInitialValue)] |
| 47 | + public void ShouldRestore_LastSnapshotContext_WithDefaultOrSkipInitialValue(RestoreBehavior behavior) |
| 48 | + { |
| 49 | + var options = new RestoreOptions { RestoreBehavior = behavior }; |
| 50 | + |
| 51 | + var result = RestoreContext.LastSnapshot.ShouldRestore(options); |
| 52 | + |
| 53 | + Assert.True(result); |
| 54 | + } |
| 55 | + |
| 56 | + [Fact] |
| 57 | + public void ShouldRestore_LastSnapshotContext_WithSkipLastSnapshot() |
| 58 | + { |
| 59 | + var options = new RestoreOptions { RestoreBehavior = RestoreBehavior.SkipLastSnapshot }; |
| 60 | + |
| 61 | + var result = RestoreContext.LastSnapshot.ShouldRestore(options); |
| 62 | + |
| 63 | + Assert.False(result); |
| 64 | + } |
| 65 | + |
| 66 | + [Theory] |
| 67 | + [InlineData(RestoreBehavior.Default, true, true)] |
| 68 | + [InlineData(RestoreBehavior.Default, false, true)] |
| 69 | + [InlineData(RestoreBehavior.SkipLastSnapshot, true, false)] |
| 70 | + [InlineData(RestoreBehavior.SkipLastSnapshot, false, false)] |
| 71 | + public void ShouldRestore_LastSnapshotContext_ShouldRestore_IsIndependentOfAllowUpdates(RestoreBehavior behavior, bool allowUpdates, bool expectedResult) |
| 72 | + { |
| 73 | + var options = new RestoreOptions { RestoreBehavior = behavior, AllowUpdates = allowUpdates }; |
| 74 | + |
| 75 | + var result = RestoreContext.LastSnapshot.ShouldRestore(options); |
| 76 | + |
| 77 | + Assert.Equal(expectedResult, result); |
| 78 | + } |
| 79 | + |
| 80 | + [Theory] |
| 81 | + [InlineData(RestoreBehavior.Default)] |
| 82 | + [InlineData(RestoreBehavior.SkipInitialValue)] |
| 83 | + [InlineData(RestoreBehavior.SkipLastSnapshot)] |
| 84 | + public void ShouldRestore_ValueUpdateContext_WithoutAllowUpdates(RestoreBehavior behavior) |
| 85 | + { |
| 86 | + var options = new RestoreOptions { RestoreBehavior = behavior }; |
| 87 | + |
| 88 | + var result = RestoreContext.ValueUpdate.ShouldRestore(options); |
| 89 | + |
| 90 | + Assert.False(result); |
| 91 | + } |
| 92 | + |
| 93 | + [Theory] |
| 94 | + [InlineData(RestoreBehavior.Default)] |
| 95 | + [InlineData(RestoreBehavior.SkipInitialValue)] |
| 96 | + [InlineData(RestoreBehavior.SkipLastSnapshot)] |
| 97 | + public void ShouldRestore_ValueUpdateContext_WithAllowUpdates(RestoreBehavior behavior) |
| 98 | + { |
| 99 | + var options = new RestoreOptions { AllowUpdates = true, RestoreBehavior = behavior }; |
| 100 | + |
| 101 | + var result = RestoreContext.ValueUpdate.ShouldRestore(options); |
| 102 | + |
| 103 | + Assert.True(result); |
| 104 | + } |
| 105 | +} |
0 commit comments