public SomeModel() { Count = NotifyChange.Of(() => _count, x => _count = x); Message = NotifyChange.Of <string>(); DetailedMessage = NotifyChange.Select(() => Message + "-" + Count, Message, Count); }
public void Given_I_have_selected_from_two_sources_When_selected_result_not_in_use_anymore_and_GC_Then_selected_result_should_be_collected() { // Arrange var model = new SomeModel(); var doubleCount = NotifyChange.Select(() => model.Count.Value * 2, model.Count); var doubleCountWeakRef = new WeakReference(doubleCount); // Act // ReSharper disable RedundantAssignment doubleCount = null; // ReSharper restore RedundantAssignment GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); // Assert doubleCountWeakRef.IsAlive.Should().BeFalse(); model.Count.Value.Should().Be(0); }
public void Given_I_have_selected_from_two_sources_When_selected_result_not_in_use_And_sources_are_changed_Then_no_exception_should_be_raised() { // Arrange var model = new SomeModel(); var detailedMessage = NotifyChange.Select(() => model.Message.Value + model.Count.Value, model.Count, model.Message); var detailedMessageWeakRef = new WeakReference(detailedMessage); // Act // ReSharper disable RedundantAssignment detailedMessage = null; // ReSharper restore RedundantAssignment GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); // Assert Assert.DoesNotThrow(() => { model.Count.Value += 1; model.Message.Value = "hey"; }); detailedMessageWeakRef.IsAlive.Should().BeFalse(); }