public async Task InvalidateEverythingTest() { var users = Services.GetRequiredService <IUserService>(); // We need at least 1 user to see count invalidation messages await users.CreateAsync(new User() { Id = int.MaxValue, Name = "Chuck Norris", }, true); var u1 = await users.TryGetAsync(int.MaxValue); var c1 = await Computed.CaptureAsync(_ => users.CountAsync()); users.Invalidate(); var u2 = await users.TryGetAsync(int.MaxValue); u2 !.IsFrozen.Should().BeTrue(); var c2 = await Computed.CaptureAsync(_ => users.CountAsync()); u2.Should().NotBeSameAs(u1); u2 !.Id.Should().Be(u1 !.Id); u2.Name.Should().Be(u1.Name); c2.Should().NotBeSameAs(c1); c2 !.Value.Should().Be(c1 !.Value); }
private void CoreFirePropertyChanging(PropertyChangeEventArgs args) { OnPropertyChanging(args); if (PropertyChanging != null) { PropertyChanging(this, args); } IsFrozen.AssertFalse(); }
public async Task InvalidationTest() { var users = Services.GetRequiredService <IUserService>(); // We need at least 1 user to see count invalidation messages await users.CreateAsync(new User() { Id = int.MaxValue, Name = "Chuck Norris", }, true); var userCount = await users.CountAsync(); var u = new User() { Id = 1000, Name = "Bruce Lee" }; // This delete won't do anything, since the user doesn't exist (await users.DeleteAsync(u)).Should().BeFalse(); // Thus count shouldn't change (await users.CountAsync()).Should().Be(userCount); // But after this line the could should change await users.CreateAsync(u); var u1 = await users.TryGetAsync(u.Id); u1.Should().NotBeNull(); u1.Should().NotBeSameAs(u); // Because it's fetched u1 !.IsFrozen.Should().BeTrue(); u1.Id.Should().Be(u.Id); u1.Name.Should().Be(u.Name); (await users.CountAsync()).Should().Be(++userCount); var u2 = await users.TryGetAsync(u.Id); u2.Should().BeSameAs(u1); u.Name = "Jackie Chan"; await users.UpdateAsync(u); // u.Name change var u3 = await users.TryGetAsync(u.Id); u3.Should().NotBeNull(); u3.Should().NotBeSameAs(u2); u3 !.Id.Should().Be(u.Id); u3.Name.Should().Be(u.Name); (await users.CountAsync()).Should().Be(userCount); }
private void OnListChanging(Object o, ListChangeEventArgs e) { foreach (T c in e.NewItems) { OnChildAdding(c); if (ChildAdding != null) { ChildAdding(c); } } foreach (T c in e.OldItems) { OnChildRemoving(c); if (ChildRemoving != null) { ChildRemoving(c); } } IsFrozen.AssertFalse(); }