Skip to content

Commit ba5b488

Browse files
authored
fix: RxRecord does not function like RxObject (#62)
added failing RxRecordTests changed RxRecord to function like RxObject change Notifications to internal move DistinctEvents internal
1 parent 315d317 commit ba5b488

File tree

9 files changed

+674
-108
lines changed

9 files changed

+674
-108
lines changed

src/ReactiveMarbles.Mvvm.Tests/TestFixture.cs renamed to src/ReactiveMarbles.Mvvm.Tests/RxObjectTestFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ReactiveMarbles.Mvvm.Tests;
1414
/// </summary>
1515
/// <seealso cref="RxObject" />
1616
[DataContract]
17-
public class TestFixture : RxObject
17+
public class RxObjectTestFixture : RxObject
1818
{
1919
[IgnoreDataMember]
2020
private string? _isNotNullString;
@@ -37,9 +37,9 @@ public class TestFixture : RxObject
3737
private string? _usesExprRaiseSet;
3838

3939
/// <summary>
40-
/// Initializes a new instance of the <see cref="TestFixture"/> class.
40+
/// Initializes a new instance of the <see cref="RxObjectTestFixture"/> class.
4141
/// </summary>
42-
public TestFixture() => TestCollection = new ObservableCollectionExtended<int>();
42+
public RxObjectTestFixture() => TestCollection = new ObservableCollectionExtended<int>();
4343

4444
/// <summary>
4545
/// Gets or sets the is not null string.
@@ -115,4 +115,4 @@ public string? UsesExprRaiseSet
115115
get => _usesExprRaiseSet;
116116
set => RaiseAndSetIfChanged(ref _usesExprRaiseSet, value);
117117
}
118-
}
118+
}

src/ReactiveMarbles.Mvvm.Tests/RxObjectTests.cs

Lines changed: 76 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace ReactiveMarbles.Mvvm.Tests;
2020

2121
/// <summary>
22-
/// Tests for the <see cref="ReactiveObject"/>.
22+
/// Tests for the <see cref="RxObject"/>.
2323
/// </summary>
2424
public class RxObjectTests
2525
{
@@ -43,7 +43,7 @@ public void ChangingShouldAlwaysArriveBeforeChanged()
4343
var beforeSet = "Foo";
4444
var afterSet = "Bar";
4545

46-
var fixture = new TestFixture { IsOnlyOneWord = beforeSet };
46+
var fixture = new RxObjectTestFixture { IsOnlyOneWord = beforeSet };
4747

4848
var beforeFired = false;
4949
fixture.Changing.Subscribe(
@@ -79,7 +79,7 @@ public void ChangingShouldAlwaysArriveBeforeChanged()
7979
[Fact]
8080
public void DeferredNotificationsDontShowUpUntilUndeferred()
8181
{
82-
var fixture = new TestFixture();
82+
var fixture = new RxObjectTestFixture();
8383
fixture.Changing.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var changing).Subscribe();
8484
fixture.Changed.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var changed).Subscribe();
8585
var propertyChangingEvents = new List<PropertyChangingEventArgs>();
@@ -135,7 +135,7 @@ public void DeferredNotificationsDontShowUpUntilUndeferred()
135135
[Fact]
136136
public void ExceptionsThrownInSubscribersShouldMarshalToThrownExceptions()
137137
{
138-
var fixture = new TestFixture { IsOnlyOneWord = "Foo" };
138+
var fixture = new RxObjectTestFixture { IsOnlyOneWord = "Foo" };
139139

140140
fixture.Changed.Subscribe(_ => throw new Exception("Terminate!"));
141141
fixture.ThrownExceptions.ToObservableChangeSet(ImmediateScheduler.Instance).Bind(out var exceptionList)
@@ -152,8 +152,8 @@ public void ExceptionsThrownInSubscribersShouldMarshalToThrownExceptions()
152152
[Fact]
153153
public void ObservableForPropertyUsingExpression()
154154
{
155-
var fixture = new TestFixture { IsNotNullString = "Foo", IsOnlyOneWord = "Baz" };
156-
var output = new List<IObservedChange<TestFixture, string?>>();
155+
var fixture = new RxObjectTestFixture { IsNotNullString = "Foo", IsOnlyOneWord = "Baz" };
156+
var output = new List<IObservedChange<RxObjectTestFixture, string?>>();
157157
fixture.ObservableForProperty(x => x.IsNotNullString)
158158
.Subscribe(x => output.Add(x));
159159

@@ -178,7 +178,7 @@ public void ObservableForPropertyUsingExpression()
178178
[Fact]
179179
public void RaiseAndSetUsingExpression()
180180
{
181-
var fixture = new TestFixture { IsNotNullString = "Foo", IsOnlyOneWord = "Baz" };
181+
var fixture = new RxObjectTestFixture { IsNotNullString = "Foo", IsOnlyOneWord = "Baz" };
182182
var output = new List<string>();
183183
fixture.Changed
184184
.Select(x => x.PropertyName)
@@ -193,10 +193,10 @@ public void RaiseAndSetUsingExpression()
193193
}
194194

195195
/// <summary>
196-
/// Test that ReactiveObject shouldn't serialize anything extra.
196+
/// Test that RxObject shouldn't serialize anything extra.
197197
/// </summary>
198198
[Fact(Skip = "JSONHelper")]
199-
public void ReactiveObjectShouldntSerializeAnythingExtra()
199+
public void RxObjectShouldntSerializeAnythingExtra()
200200
{
201201
// var fixture = new TestFixture
202202
// {
@@ -225,7 +225,7 @@ public void RxObjectSmokeTest()
225225
{
226226
var outputChanging = new List<string>();
227227
var output = new List<string>();
228-
var fixture = new TestFixture();
228+
var fixture = new RxObjectTestFixture();
229229

230230
fixture.Changing
231231
.Select(x => x.PropertyName)
@@ -249,12 +249,12 @@ public void RxObjectSmokeTest()
249249
}
250250

251251
/// <summary>
252-
/// Tests to make sure that ReactiveObject doesn't rethrow exceptions.
252+
/// Tests to make sure that RxObject doesn't rethrow exceptions.
253253
/// </summary>
254254
[Fact]
255-
public void ReactiveObjectShouldRethrowException()
255+
public void RxObjectShouldRethrowException()
256256
{
257-
var fixture = new TestFixture();
257+
var fixture = new RxObjectTestFixture();
258258
var observable = fixture.WhenAnyValue(x => x.IsOnlyOneWord).Skip(1);
259259
observable.Subscribe(_ => throw new Exception("This is a test."));
260260

@@ -268,11 +268,73 @@ public void ReactiveObjectShouldRethrowException()
268268
.Be("This is a test.");
269269
}
270270

271+
/// <summary>
272+
/// Tests that change notifications are not delayed.
273+
/// </summary>
274+
[Fact]
275+
public void ChangeNotificationsAreNotDelayed() =>
276+
277+
// Given, When, Then
278+
new RxObjectTestFixture()
279+
.AreChangeNotificationsDelayed()
280+
.Should()
281+
.BeFalse();
282+
283+
/// <summary>
284+
/// Tests that change notifications are delayed.
285+
/// </summary>
286+
[Fact]
287+
public void ChangeNotificationsAreDelayed()
288+
{
289+
// Given
290+
var fixture = new RxObjectTestFixture();
291+
292+
// When
293+
using var disposable = fixture.DelayChangeNotifications();
294+
295+
// Then
296+
fixture
297+
.AreChangeNotificationsDelayed()
298+
.Should()
299+
.BeTrue();
300+
}
301+
302+
/// <summary>
303+
/// Tests that change notifications are enabled.
304+
/// </summary>
305+
[Fact]
306+
public void ChangeNotificationsAreEnabled() =>
307+
308+
// Given, When, Then
309+
new RxObjectTestFixture()
310+
.AreChangeNotificationsEnabled()
311+
.Should()
312+
.BeTrue();
313+
314+
/// <summary>
315+
/// Tests that change notifications are suppressed.
316+
/// </summary>
317+
[Fact]
318+
public void ChangeNotificationsAreSuppressed()
319+
{
320+
// Given
321+
var fixture = new RxObjectTestFixture();
322+
323+
// When
324+
using var disposable = fixture.SuppressChangeNotifications();
325+
326+
// Then
327+
fixture
328+
.AreChangeNotificationsEnabled()
329+
.Should()
330+
.BeFalse();
331+
}
332+
271333
private static void AssertCount(int expected, params ICollection[] collections)
272334
{
273335
foreach (var collection in collections)
274336
{
275337
Assert.Equal(expected, collection.Count);
276338
}
277339
}
278-
}
340+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright (c) 2019-2021 ReactiveUI Association Incorporated. All rights reserved.
2+
// ReactiveUI Association Incorporated licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for full license information.
4+
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Runtime.Serialization;
8+
using DynamicData.Binding;
9+
10+
namespace ReactiveMarbles.Mvvm.Tests;
11+
12+
/// <summary>
13+
/// A test fixture.
14+
/// </summary>
15+
/// <seealso cref="RxRecord" />
16+
[DataContract]
17+
public record RxRecordTestFixture : RxRecord
18+
{
19+
[IgnoreDataMember]
20+
private string? _isNotNullString;
21+
22+
[IgnoreDataMember]
23+
private string? _isOnlyOneWord;
24+
25+
private string? _notSerialized;
26+
27+
[IgnoreDataMember]
28+
private int? _nullableInt;
29+
30+
[IgnoreDataMember]
31+
private string? _pocoProperty;
32+
33+
[IgnoreDataMember]
34+
private List<string>? _stackOverflowTrigger;
35+
36+
[IgnoreDataMember]
37+
private string? _usesExprRaiseSet;
38+
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="RxRecordTestFixture"/> class.
41+
/// </summary>
42+
public RxRecordTestFixture() => TestCollection = new ObservableCollectionExtended<int>();
43+
44+
/// <summary>
45+
/// Gets or sets the is not null string.
46+
/// </summary>
47+
[DataMember]
48+
public string? IsNotNullString
49+
{
50+
get => _isNotNullString;
51+
set => RaiseAndSetIfChanged(ref _isNotNullString, value);
52+
}
53+
54+
/// <summary>
55+
/// Gets or sets the is only one word.
56+
/// </summary>
57+
[DataMember]
58+
public string? IsOnlyOneWord
59+
{
60+
get => _isOnlyOneWord;
61+
set => RaiseAndSetIfChanged(ref _isOnlyOneWord, value);
62+
}
63+
64+
/// <summary>
65+
/// Gets or sets the not serialized.
66+
/// </summary>
67+
public string? NotSerialized
68+
{
69+
get => _notSerialized;
70+
set => RaiseAndSetIfChanged(ref _notSerialized, value);
71+
}
72+
73+
/// <summary>
74+
/// Gets or sets the nullable int.
75+
/// </summary>
76+
[DataMember]
77+
public int? NullableInt
78+
{
79+
get => _nullableInt;
80+
set => RaiseAndSetIfChanged(ref _nullableInt, value);
81+
}
82+
83+
/// <summary>
84+
/// Gets or sets the poco property.
85+
/// </summary>
86+
[DataMember]
87+
public string? PocoProperty
88+
{
89+
get => _pocoProperty;
90+
set => _pocoProperty = value;
91+
}
92+
93+
/// <summary>
94+
/// Gets or sets the stack overflow trigger.
95+
/// </summary>
96+
[DataMember]
97+
public List<string>? StackOverflowTrigger
98+
{
99+
get => _stackOverflowTrigger;
100+
set => RaiseAndSetIfChanged(ref _stackOverflowTrigger, value?.ToList());
101+
}
102+
103+
/// <summary>
104+
/// Gets or sets the test collection.
105+
/// </summary>
106+
[DataMember]
107+
public ObservableCollectionExtended<int> TestCollection { get; protected set; }
108+
109+
/// <summary>
110+
/// Gets or sets the uses expr raise set.
111+
/// </summary>
112+
[DataMember]
113+
public string? UsesExprRaiseSet
114+
{
115+
get => _usesExprRaiseSet;
116+
set => RaiseAndSetIfChanged(ref _usesExprRaiseSet, value);
117+
}
118+
}

0 commit comments

Comments
 (0)