public void GivenMessage_ReturnsMaintainVocabularyWordScreen() { var message = new ModifySpellingMessage("Bar"); var state = _reducer.Reduce(message, _initialState); state.CurrentScreen.Should().BeOfType <ModifyVocabularyWordScreen>(); }
public void GivenMessage_ModifiesExpectedProperty() { var message = new ModifySpellingMessage("Bar"); var state = _reducer.Reduce(message, _initialState); var screen = (ModifyVocabularyWordScreen)state.CurrentScreen; screen.Spelling.Should().Be(message.Spelling); }
public WordTutorApplication Reduce(IReduxMessage message, WordTutorApplication currentState) { if (currentState is null) { throw new ArgumentNullException(nameof(currentState)); } if (!(currentState.CurrentScreen is ModifyVocabularyWordScreen)) { return(currentState); } return((message ?? throw new ArgumentNullException(nameof(message))) switch { CloseScreenMessage m => currentState.CloseScreen(), ModifyPhraseMessage m => currentState.UpdateScreen( (ModifyVocabularyWordScreen s) => s.WithPhrase(m.Phrase)), ModifyPronunciationMessage m => currentState.UpdateScreen( (ModifyVocabularyWordScreen s) => s.WithPronunciation(m.Pronunciation)), ModifySpellingMessage m => currentState.UpdateScreen( (ModifyVocabularyWordScreen s) => s.WithSpelling(m.Spelling)), SaveNewVocabularyWordMessage m => currentState.UpdateVocabularySet( s => s.Add(m.Word)) .CloseScreen(), SaveModifiedVocabularyWordMessage m => currentState.UpdateVocabularySet( s => s.Replace(m.OriginalWord, m.ReplacementWord)) .CloseScreen(), _ => currentState, });