public void ShoudNotTrackRemovedItemAsModified() { var wordToAdd = new WordWrapper(new Word()); var collection = new ChangeTrackingCollection<WordWrapper>(words); Assert.AreEqual(2, collection.Count); Assert.IsFalse(collection.IsChanged); collection.Add(wordToAdd); Assert.AreEqual(3, collection.Count); Assert.AreEqual(1, collection.AddedItems.Count); Assert.AreEqual(0, collection.RemovedItems.Count); Assert.AreEqual(0, collection.ModifiedItems.Count); Assert.AreEqual(wordToAdd, collection.AddedItems.First()); Assert.IsTrue(collection.IsChanged); collection.Remove(wordToAdd); Assert.AreEqual(2, collection.Count); Assert.AreEqual(0, collection.AddedItems.Count); Assert.AreEqual(0, collection.RemovedItems.Count); Assert.AreEqual(0, collection.ModifiedItems.Count); Assert.IsFalse(collection.IsChanged); }
public void ShouldWrapUsingRowLength_AndTrimLeadingSpacesOnly() { var testInput = "ab def"; var result = new WordWrapper(3).Wrap(testInput).ToList(); Assert.IsTrue(result.Count == 2); Assert.AreEqual("ab ", result[0]); Assert.AreEqual("def", result[1]); }
public void ShouldWrapUsingRowLength() { var testInput = "abcdef"; var result = new WordWrapper(3).Wrap(testInput).ToList(); Assert.IsTrue(result.Count == 2); Assert.AreEqual("abc", result[0]); Assert.AreEqual("def", result[1]); }
public void ShouldWrapUsingRowLength_AndTrimLeadingSpaces_Complex() { var testInput = "abcdef ghi"; var result = new WordWrapper(3).Wrap(testInput).ToList(); Assert.IsTrue(result.Count == 3); Assert.AreEqual("abc", result[0]); Assert.AreEqual("def", result[1]); Assert.AreEqual("ghi", result[2]); }
public WordVertex(WordWrapper wordWrapper, string vertexValueAttribute) { if (wordWrapper == null) { throw new ArgumentNullException("wordWrapper", @"Must provide an instance of WordWrapper"); } this.wordWrapper = wordWrapper; this.vertexValueAttribute = string.IsNullOrEmpty(vertexValueAttribute) ? "form" : vertexValueAttribute; SetVertexId(); }
public WordEditorViewModel(WordWrapper wordWrapper, IEventAggregator eventAggregator, Guid viewId) { if (wordWrapper == null) { throw new ArgumentNullException("wordWrapper"); } if (eventAggregator == null) { throw new ArgumentNullException("eventAggregator"); } this.viewId = viewId; this.wordWrapper = wordWrapper; this.eventAggregator = eventAggregator; WordChangedCommand = new DelegateCommand(WordChangedCommandExecute, WordChangedCommandCanExecute); WordGotFocusCommand = new DelegateCommand(WordGotFocusCommandExecute, WordGotFocusCommandCanExecute); }
public AddWordViewModel(Word wordPrototype, List<Pair> words) { if (wordPrototype == null) { throw new ArgumentNullException("wordPrototype"); } if (words == null) { throw new ArgumentNullException("words"); } this.wordPrototype = wordPrototype; wordPrototypeOriginal = ObjectCopier.Clone(wordPrototype); this.words = words; SetAllWordAttributesAsEditable(this.wordPrototype); SetAllowedValuesSetForWordIdAttribute(this.wordPrototype, this.words); SetAllowedValuesSetForHeadWordAttribute(this.wordPrototype, this.words); Word = new WordWrapper(this.wordPrototype); OkButtonCommand = new DelegateCommand(OkButtonCommandExecute, OkButtonCommandCanExecute); }
private void AddSentenceCommandExecute(object obj) { if (SelectedDocument != null) { var appconfig = appConfigMapper.Map(SelectedDocument.Model.GetAttributeByName("configurationFilePath")) .GetAwaiter() .GetResult(); var sentencePrototype = DataStructure.Elements.OfType<Sentence>().FirstOrDefault(); var wordPrototype = DataStructure.Elements.OfType<Word>().FirstOrDefault(); var configuration = appconfig.Definitions.FirstOrDefault(); if (configuration == null) { eventAggregator.GetEvent<StatusNotificationEvent>() .Publish("Must define a configuration in the configuration file before adding a sentence"); return; } var inputDialog = new InputDialog("Enter sentence"); if (inputDialog.ShowDialog().GetValueOrDefault()) { var sentenceContent = inputDialog.Value; if (sentencePrototype != null) { var sentenceClone = ObjectCopier.Clone(sentencePrototype); sentenceClone.SetAttributeByName("date", DateTime.Now.ToString("dd-MM-yyyy")); sentenceClone.SetAttributeByName("id", (SelectedDocument.Sentences.Count + 1).ToString()); var newSentence = new SentenceWrapper(sentenceClone) { IsOptional = false, Content = new AttributeWrapper( new Attribute { Name = "content", DisplayName = "Content", Value = sentenceContent, IsOptional = true, IsEditable = false }) }; var words = sentenceContent.Split(' ').Where(s => !string.IsNullOrWhiteSpace(s)).ToArray(); for (var i = 0; i < words.Length; i++) { var wordContent = words[i]; var newWord = ObjectCopier.Clone(wordPrototype); newWord.Value = wordContent; newWord.SetAttributeByName(configuration.Edge.TargetVertexAttributeName, (i + 1).ToString()); newWord.SetAttributeByName(configuration.Edge.SourceVertexAttributeName, "0"); newWord.Attributes.Add( new Attribute { Name = "content", DisplayName = "Content", Value = wordContent, IsOptional = true, IsEditable = false }); if (wordPrototype != null) { var attribute = newWord.Attributes.FirstOrDefault( a => a.Name == configuration.Vertex.LabelAttributeName); if (attribute != null) { attribute.Value = wordContent; } } var newWordWrapper = new WordWrapper(newWord); newSentence.Words.Add(newWordWrapper); } newSentence.Attributes.ForEach( a => { a.IsOptional = false; a.IsEditable = true; }); SelectedDocument.Sentences.Add(newSentence); SelectedSentence = newSentence; } } } }
private void OkButtonCommandExecute(object obj) { var wordFormValue = Word.Model.Attributes.Single(a => a.Name.ToLowerInvariant().Equals("form")).Value; Word.Attributes.Add( new AttributeWrapper(new Attribute { Name = "content", DisplayName = "Content", Value = wordFormValue, IsEditable = false, IsOptional = false })); var originalWordWrapper = new WordWrapper(wordPrototypeOriginal); var originalHeadWordAttribute = originalWordWrapper.Attributes.Single(a => a.Name.ToLowerInvariant().Equals("head")); var headwordAttribute = Word.Attributes.Single(a => a.Name.ToLowerInvariant().Equals("head")); headwordAttribute.IsEditable = originalHeadWordAttribute.IsEditable; headwordAttribute.AllowedValuesSet = originalHeadWordAttribute.AllowedValuesSet; var headWordId = words.Where(p => p.Form == headwordAttribute.Value).Select(p => p.Id).FirstOrDefault(); headwordAttribute.Value = headWordId.ToString(); Word.AcceptChanges(); }
public OrderedWordVertex(WordWrapper wordWrapper, string vertexValueAttribute) : base(wordWrapper, vertexValueAttribute) { }
public void WrapWords_WhenPassedLongerStringWithNoSpacesGreaterThanRowLength_ShouldReturnStringSplitAtRowLength() { Assert.AreEqual("WordW\nordWo\nrd", WordWrapper.WrapWords("WordWordWord", 5)); }
public void WrapWords_WhenPassedStringEqualToRowLength_ShouldReturnInputString() { Assert.AreEqual("Word", WordWrapper.WrapWords("Word", 4)); }