public void Select_DispatchOnOtherSlice_NoUpdate() { //Arrange var initialValue = new ComplexObjectReducer.ApplicationState( ui: new ComplexObjectReducer.UIState(isVisible: false), data: new ComplexObjectReducer.DataState( entities1: ImmutableSortedDictionary.Create <int, ComplexObjectReducer.Entitiy1>(), entities2: ImmutableSortedDictionary.Create <int, ComplexObjectReducer.Entitiy2>() ) ); var testId = 1; var testValue = "pinkey"; var results = new List <ImmutableSortedDictionary <int, ComplexObjectReducer.Entitiy1> >(); var store = new Store <ComplexObjectReducer.ApplicationState>(new ComplexObjectReducer(), initialValue); //Act var sub = store.Select(state => state.Data.Entities1).Subscribe(val => results.Add(val)); //make change in other slice store.Dispatch(new ComplexObjectReducer.AddEntity2Action(testId, testValue)); //Assert // receives inital state, but no new state Assert.IsTrue(results.Count == 1, $"results contains {results.Count} elements instead of 1"); sub.Dispose(); }
public void Select_DispatchOnCurrentSlice_ReceivesUpdate() { //Arrange var initialValue = new ComplexObjectReducer.ApplicationState( ui: new ComplexObjectReducer.UIState(isVisible: false), data: new ComplexObjectReducer.DataState( entities1: ImmutableSortedDictionary.Create <int, ComplexObjectReducer.Entitiy1>(), entities2: ImmutableSortedDictionary.Create <int, ComplexObjectReducer.Entitiy2>() ) ); var testId = 1; var testValue = "pinkey"; var results = new List <ImmutableSortedDictionary <int, ComplexObjectReducer.Entitiy1> >(); var store = new Store <ComplexObjectReducer.ApplicationState>(new ComplexObjectReducer(), initialValue); //Act var sub = store.Select(state => state.Data.Entities1).Subscribe(val => results.Add(val)); //make change in current slice store.Dispatch(new ComplexObjectReducer.AddEntity1Action(testId, testValue)); //Assert // receives inital state, and new state Assert.IsTrue(results.Count == 2, $"results contains {results.Count} elements instead of 2"); Assert.IsFalse(object.ReferenceEquals(results[0], results[1])); Assert.IsTrue(results[1].Count == 1, $"entities1 contains {results[1].Count} elements instead of 1"); var entity1 = results[1].First().Value; Assert.AreEqual(testId, entity1.Id); Assert.AreEqual(testValue, entity1.Value); sub.Dispose(); }