コード例 #1
0
        public void TaskAreas()
        {
            DispatcherHelper.Initialize();
            var projectService  = Substitute.For <IProjectService>();
            var dialogService   = Substitute.For <IDialogService>();
            var busyService     = Substitute.For <IBusyService>();
            var analysisService = Substitute.For <IAnalysisService>();
            var importService   = Substitute.For <IImportService>();
            var exportService   = Substitute.For <IExportService>();

            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);
            WordListsVarietyMeaningViewModel.Factory varietyglossFactory = (variety, meaning) => new WordListsVarietyMeaningViewModel(busyService, analysisService, wordFactory, variety, meaning);
            WordListsVarietyViewModel.Factory        varietyFactory      = variety => new WordListsVarietyViewModel(projectService, varietyglossFactory, variety);

            var wordLists = new WordListsViewModel(projectService, dialogService, importService, exportService, analysisService, varietyFactory);

            var project = new CogProject(_spanFactory)
            {
                Varieties = { new Variety("variety1"), new Variety("variety2"), new Variety("variety3") }
            };

            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            var commonTasks = (TaskAreaItemsViewModel)wordLists.TaskAreas[0];

            // add a new variety
            var addVariety = (TaskAreaCommandViewModel)commonTasks.Items[0];

            dialogService.ShowModalDialog(wordLists, Arg.Do <EditVarietyViewModel>(vm => vm.Name = "variety4")).Returns(true);
            addVariety.Command.Execute(null);

            Assert.That(project.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety1", "variety2", "variety3", "variety4" }));
        }
コード例 #2
0
        public void FindCommand()
        {
            DispatcherHelper.Initialize();
            var segmentPool     = new SegmentPool();
            var projectService  = Substitute.For <IProjectService>();
            var dialogService   = Substitute.For <IDialogService>();
            var busyService     = Substitute.For <IBusyService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);
            var exportService   = Substitute.For <IExportService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory  wordFactory  = word => new WordViewModel(busyService, analysisService, word);

            var segments = new SegmentsViewModel(projectService, dialogService, busyService, exportService, wordsFactory, wordFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);

            project.Meanings.AddRange(new[] { new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3") });
            project.Varieties.AddRange(new[] { new Variety("variety1"), new Variety("variety2") });
            project.Varieties[0].Words.AddRange(new[] { new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2]) });
            project.Varieties[1].Words.AddRange(new[] { new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2]) });
            projectService.Project.Returns(project);
            analysisService.SegmentAll();
            projectService.ProjectOpened += Raise.Event();

            WordsViewModel observedWords = segments.ObservedWords;

            observedWords.WordsView = new ListCollectionView(observedWords.Words);

            FindViewModel findViewModel = null;
            Action        closeCallback = null;

            dialogService.ShowModelessDialog(segments, Arg.Do <FindViewModel>(vm => findViewModel = vm), Arg.Do <Action>(callback => closeCallback = callback));
            segments.FindCommand.Execute(null);
            Assert.That(findViewModel, Is.Not.Null);
            Assert.That(closeCallback, Is.Not.Null);

            // already open, shouldn't get opened twice
            dialogService.ClearReceivedCalls();
            segments.FindCommand.Execute(null);
            dialogService.DidNotReceive().ShowModelessDialog(segments, Arg.Any <FindViewModel>(), Arg.Any <Action>());

            // nothing selected, no match
            findViewModel.Field  = FindField.Form;
            findViewModel.String = "nothing";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWords.SelectedWords, Is.Empty);

            // nothing selected, matches
            segments.SelectedSegment = segments.Varieties[1].Segments[3];
            WordViewModel[] wordsViewArray = observedWords.WordsView.Cast <WordViewModel>().ToArray();
            findViewModel.String = "fi";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWords.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(observedWords.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
        }
コード例 #3
0
        public void StrRep()
        {
            DispatcherHelper.Initialize();
            var busyService     = Substitute.For <IBusyService>();
            var projectService  = Substitute.For <IProjectService>();
            var analysisService = Substitute.For <IAnalysisService>();

            var project = new CogProject(_spanFactory);

            project.Meanings.Add(new Meaning("gloss1", "cat1"));
            project.Varieties.Add(new Variety("variety1"));

            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);
            WordListsVarietyMeaningViewModel.Factory varietyMeaningFactory = (v, meaning) => new WordListsVarietyMeaningViewModel(busyService, analysisService, wordFactory, v, meaning);

            projectService.Project.Returns(project);

            var variety = new WordListsVarietyViewModel(projectService, varietyMeaningFactory, project.Varieties[0]);
            WordListsVarietyMeaningViewModel varietyMeaning = variety.Meanings[0];

            Assert.That(varietyMeaning.Words, Is.Empty);
            Assert.That(varietyMeaning.StrRep, Is.Empty);

            project.Varieties[0].Words.Add(new Word("hɛ.loʊ", project.Meanings[0]));

            Assert.That(varietyMeaning.StrRep, Is.EqualTo("hɛ.loʊ"));
            Assert.That(varietyMeaning.Words.Select(w => w.StrRep), Is.EqualTo(new[] { "hɛ.loʊ" }));

            project.Varieties[0].Words.Add(new Word("gu.gəl", project.Meanings[0]));

            Assert.That(varietyMeaning.StrRep, Is.EqualTo("hɛ.loʊ,gu.gəl"));
            Assert.That(varietyMeaning.Words.Select(w => w.StrRep), Is.EqualTo(new[] { "hɛ.loʊ", "gu.gəl" }));

            varietyMeaning.StrRep = "hɛ.lp,gu.gəl";
            Assert.That(varietyMeaning.Words.Select(w => w.StrRep), Is.EqualTo(new[] { "hɛ.lp", "gu.gəl" }));

            varietyMeaning.StrRep = "hɛ.lp";
            Assert.That(varietyMeaning.Words.Select(w => w.StrRep), Is.EqualTo(new[] { "hɛ.lp" }));

            varietyMeaning.StrRep = "";
            Assert.That(varietyMeaning.Words, Is.Empty);

            varietyMeaning.StrRep = null;
            Assert.That(varietyMeaning.Words, Is.Empty);

            varietyMeaning.StrRep = " hɛ.lp,gu.gəl ,gu.fi ";
            Assert.That(varietyMeaning.Words.Select(w => w.StrRep), Is.EqualTo(new[] { "hɛ.lp", "gu.gəl", "gu.fi" }));
            Assert.That(varietyMeaning.StrRep, Is.EqualTo("hɛ.lp,gu.gəl,gu.fi"));

            varietyMeaning.StrRep = "hɛ.lp,gu.gəl,gu";
            Assert.That(varietyMeaning.Words.Select(w => w.StrRep), Is.EqualTo(new[] { "hɛ.lp", "gu.gəl", "gu" }));
        }
コード例 #4
0
        public void Varieties()
        {
            DispatcherHelper.Initialize();
            var projectService  = Substitute.For <IProjectService>();
            var dialogService   = Substitute.For <IDialogService>();
            var busyService     = Substitute.For <IBusyService>();
            var analysisService = Substitute.For <IAnalysisService>();

            WordsViewModel.Factory            wordsFactory   = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory             wordFactory    = word => new WordViewModel(busyService, analysisService, word);
            VarietiesVarietyViewModel.Factory varietyFactory = variety => new VarietiesVarietyViewModel(projectService, dialogService, wordsFactory, wordFactory, variety);

            var varieties = new VarietiesViewModel(projectService, dialogService, analysisService, varietyFactory);

            var project = new CogProject(_spanFactory);

            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            varieties.VarietiesView = new ListCollectionView(varieties.Varieties);

            Assert.That(varieties.Varieties, Is.Empty);
            Assert.That(varieties.IsVarietySelected, Is.False);
            Assert.That(varieties.SelectedVariety, Is.Null);

            project.Varieties.Add(new Variety("variety1"));

            Assert.That(varieties.Varieties.Count, Is.EqualTo(1));
            Assert.That(varieties.Varieties[0].Name, Is.EqualTo("variety1"));
            Assert.That(varieties.IsVarietySelected, Is.True);
            Assert.That(varieties.SelectedVariety, Is.EqualTo(varieties.VarietiesView.Cast <VarietiesVarietyViewModel>().First()));

            project = new CogProject(_spanFactory)
            {
                Varieties = { new Variety("French"), new Variety("English"), new Variety("Spanish") }
            };
            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "French", "English", "Spanish" }));
            Assert.That(varieties.IsVarietySelected, Is.False);
            Assert.That(varieties.SelectedVariety, Is.Null);

            varieties.VarietiesView = new ListCollectionView(varieties.Varieties);
            VarietiesVarietyViewModel[] varietiesViewArray = varieties.VarietiesView.Cast <VarietiesVarietyViewModel>().ToArray();
            Assert.That(varieties.IsVarietySelected, Is.True);
            Assert.That(varieties.SelectedVariety, Is.EqualTo(varietiesViewArray[0]));
            // should be sorted
            Assert.That(varietiesViewArray.Select(v => v.Name), Is.EqualTo(new[] { "English", "French", "Spanish" }));
        }
コード例 #5
0
            public TestEnvironment()
            {
                DispatcherHelper.Initialize();
                _projectService = Substitute.For <IProjectService>();
                DialogService   = Substitute.For <IDialogService>();
                var busyService     = Substitute.For <IBusyService>();
                var analysisService = Substitute.For <IAnalysisService>();

                WordsViewModel.Factory            wordsFactory   = words => new WordsViewModel(busyService, words);
                WordViewModel.Factory             wordFactory    = word => new WordViewModel(busyService, analysisService, word);
                VarietiesVarietyViewModel.Factory varietyFactory = variety => new VarietiesVarietyViewModel(_projectService, DialogService, wordsFactory, wordFactory, variety);

                VarietiesViewModel = new VarietiesViewModel(_projectService, DialogService, analysisService, varietyFactory);
            }
コード例 #6
0
        public void Varieties()
        {
            DispatcherHelper.Initialize();
            var projectService  = Substitute.For <IProjectService>();
            var dialogService   = Substitute.For <IDialogService>();
            var busyService     = Substitute.For <IBusyService>();
            var analysisService = Substitute.For <IAnalysisService>();
            var importService   = Substitute.For <IImportService>();
            var exportService   = Substitute.For <IExportService>();

            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, analysisService, word);
            WordListsVarietyMeaningViewModel.Factory varietyMeaningFactory = (variety, meaning) => new WordListsVarietyMeaningViewModel(busyService, analysisService, wordFactory, variety, meaning);
            WordListsVarietyViewModel.Factory        varietyFactory        = variety => new WordListsVarietyViewModel(projectService, varietyMeaningFactory, variety);

            var wordLists = new WordListsViewModel(projectService, dialogService, importService, exportService, analysisService, varietyFactory);

            var project = new CogProject(_spanFactory)
            {
                Varieties = { new Variety("variety1"), new Variety("variety2"), new Variety("variety3") }
            };

            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            Assert.That(wordLists.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety1", "variety2", "variety3" }));
            Assert.That(wordLists.IsEmpty, Is.False);

            project.Varieties.RemoveAt(0);
            Assert.That(wordLists.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety2", "variety3" }));
            Assert.That(wordLists.IsEmpty, Is.False);

            project.Varieties.Add(new Variety("variety1"));
            Assert.That(wordLists.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety2", "variety3", "variety1" }));
            Assert.That(wordLists.IsEmpty, Is.False);

            project.Varieties.Clear();
            Assert.That(wordLists.Varieties.Count, Is.EqualTo(0));
            Assert.That(wordLists.IsEmpty, Is.True);

            project = new CogProject(_spanFactory)
            {
                Varieties = { new Variety("variety1") }
            };
            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            Assert.That(wordLists.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety1" }));
            Assert.That(wordLists.IsEmpty, Is.False);
        }
コード例 #7
0
        public WordListsViewModelTestEnvironment()
        {
            DispatcherHelper.Initialize();
            _projectService = Substitute.For <IProjectService>();
            _dialogService  = Substitute.For <IDialogService>();
            var busyService = Substitute.For <IBusyService>();

            _analysisService = Substitute.For <IAnalysisService>();
            var importService = Substitute.For <IImportService>();
            var exportService = Substitute.For <IExportService>();

            WordViewModel.Factory wordFactory = word => new WordViewModel(busyService, _analysisService, word);
            WordListsVarietyMeaningViewModel.Factory varietyMeaningFactory = (variety, meaning) => new WordListsVarietyMeaningViewModel(busyService, _analysisService, wordFactory, variety, meaning);
            WordListsVarietyViewModel.Factory        varietyFactory        = (parent, variety) => new WordListsVarietyViewModel(_projectService, varietyMeaningFactory, parent, variety);

            _wordListsViewModel = new WordListsViewModel(_projectService, _dialogService, importService, exportService, _analysisService, varietyFactory);
        }
コード例 #8
0
        public void ObservedWords()
        {
            DispatcherHelper.Initialize();
            var segmentPool     = new SegmentPool();
            var projectService  = Substitute.For <IProjectService>();
            var dialogService   = Substitute.For <IDialogService>();
            var busyService     = Substitute.For <IBusyService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);
            var exportService   = Substitute.For <IExportService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory  wordFactory  = word => new WordViewModel(busyService, analysisService, word);

            var segments = new SegmentsViewModel(projectService, dialogService, busyService, exportService, wordsFactory, wordFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);

            project.Meanings.AddRange(new[] { new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3") });
            project.Varieties.AddRange(new[] { new Variety("variety1"), new Variety("variety2") });
            project.Varieties[0].Words.AddRange(new[] { new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2]) });
            project.Varieties[1].Words.AddRange(new[] { new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2]) });
            projectService.Project.Returns(project);
            analysisService.SegmentAll();
            projectService.ProjectOpened += Raise.Event();

            var observedWords = segments.ObservedWords;

            observedWords.WordsView = new ListCollectionView(segments.ObservedWords.Words);

            Assert.That(observedWords.WordsView, Is.Empty);

            segments.SelectedSegment = segments.Varieties[1].Segments[3];
            WordViewModel[] wordsViewArray = observedWords.WordsView.Cast <WordViewModel>().ToArray();
            Assert.That(wordsViewArray.Select(w => w.StrRep), Is.EqualTo(new[] { "gu.gəl", "gu.fi" }));
            Assert.That(wordsViewArray[0].Segments[1].IsSelected, Is.True);
            Assert.That(wordsViewArray[0].Segments[2].IsSelected, Is.False);
            Assert.That(wordsViewArray[0].Segments[4].IsSelected, Is.True);

            segments.SelectedSegment = segments.Varieties[0].Segments[1];
            Assert.That(observedWords.WordsView, Is.Empty);

            segments.SelectedSegment = null;
            Assert.That(observedWords.WordsView, Is.Empty);
        }
コード例 #9
0
ファイル: SegmentsViewModel.cs プロジェクト: FieldDB/cog
        public SegmentsViewModel(IProjectService projectService, IDialogService dialogService, IBusyService busyService, IExportService exportService, WordsViewModel.Factory wordsFactory,
                                 WordViewModel.Factory wordFactory)
            : base("Segments")
        {
            _projectService = projectService;
            _busyService    = busyService;
            _dialogService  = dialogService;
            _exportService  = exportService;
            _wordFactory    = wordFactory;

            _findCommand = new RelayCommand(Find);

            TaskAreas.Add(new TaskAreaCommandGroupViewModel("Syllable position",
                                                            new TaskAreaCommandViewModel("Onset", new RelayCommand(() => SyllablePosition   = SyllablePosition.Onset)),
                                                            new TaskAreaCommandViewModel("Nucleus", new RelayCommand(() => SyllablePosition = SyllablePosition.Nucleus)),
                                                            new TaskAreaCommandViewModel("Coda", new RelayCommand(() => SyllablePosition    = SyllablePosition.Coda))));

            TaskAreas.Add(new TaskAreaItemsViewModel("Common tasks",
                                                     new TaskAreaCommandViewModel("Find words", _findCommand),
                                                     new TaskAreaItemsViewModel("Sort words by", new TaskAreaCommandGroupViewModel(
                                                                                    new TaskAreaCommandViewModel("Meaning", new RelayCommand(() => SortWordsBy("Meaning.Gloss", ListSortDirection.Ascending))),
                                                                                    new TaskAreaCommandViewModel("Form", new RelayCommand(() => SortWordsBy("StrRep", ListSortDirection.Ascending)))))));

            TaskAreas.Add(new TaskAreaItemsViewModel("Other tasks",
                                                     new TaskAreaCommandViewModel("Export segment frequencies", new RelayCommand(() => _exportService.ExportSegmentFrequencies(this, _syllablePosition)))));

            _projectService.ProjectOpened += _projectService_ProjectOpened;

            Messenger.Default.Register <DomainModelChangedMessage>(this, msg =>
            {
                if (msg.AffectsComparison)
                {
                    PopulateSegments();
                }
            });

            _currentWords       = new BulkObservableList <WordViewModel>();
            _observedWords      = wordsFactory(new ReadOnlyBindableList <WordViewModel>(_currentWords));
            _domainSegments     = new BulkObservableList <Segment>();
            _segments           = new BulkObservableList <SegmentViewModel>();
            _readonlySegments   = new ReadOnlyBindableList <SegmentViewModel>(_segments);
            _categories         = new BulkObservableList <SegmentCategoryViewModel>();
            _readonlyCategories = new ReadOnlyBindableList <SegmentCategoryViewModel>(_categories);
        }
コード例 #10
0
ファイル: SegmentsViewModel.cs プロジェクト: sillsdev/cog
        public SegmentsViewModel(IProjectService projectService, IDialogService dialogService, IBusyService busyService, IExportService exportService, WordsViewModel.Factory wordsFactory,
			WordViewModel.Factory wordFactory)
            : base("Segments")
        {
            _projectService = projectService;
            _busyService = busyService;
            _dialogService = dialogService;
            _exportService = exportService;
            _wordFactory = wordFactory;

            _findCommand = new RelayCommand(Find);

            TaskAreas.Add(new TaskAreaCommandGroupViewModel("Syllable position",
                new TaskAreaCommandViewModel("Onset", new RelayCommand(() => SyllablePosition = SyllablePosition.Onset)),
                new TaskAreaCommandViewModel("Nucleus", new RelayCommand(() => SyllablePosition = SyllablePosition.Nucleus)),
                new TaskAreaCommandViewModel("Coda", new RelayCommand(() => SyllablePosition = SyllablePosition.Coda))));

            TaskAreas.Add(new TaskAreaItemsViewModel("Common tasks",
                new TaskAreaCommandViewModel("Find words", _findCommand),
                new TaskAreaItemsViewModel("Sort words by", new TaskAreaCommandGroupViewModel(
                    new TaskAreaCommandViewModel("Meaning", new RelayCommand(() => SortWordsBy("Meaning.Gloss", ListSortDirection.Ascending))),
                    new TaskAreaCommandViewModel("Form", new RelayCommand(() => SortWordsBy("StrRep", ListSortDirection.Ascending)))))));

            TaskAreas.Add(new TaskAreaItemsViewModel("Other tasks",
                new TaskAreaCommandViewModel("Export segment frequencies", new RelayCommand(ExportSegmentFrequencies, CanExportSegmentFrequencies))));

            _projectService.ProjectOpened += _projectService_ProjectOpened;

            Messenger.Default.Register<DomainModelChangedMessage>(this, msg =>
                {
                    if (msg.AffectsComparison)
                        PopulateSegments();
                });

            _currentWords = new BulkObservableList<WordViewModel>();
            _observedWords = wordsFactory(new ReadOnlyBindableList<WordViewModel>(_currentWords));
            _domainSegments = new BulkObservableList<Segment>();
            _segments = new BulkObservableList<SegmentViewModel>();
            _readonlySegments = new ReadOnlyBindableList<SegmentViewModel>(_segments);
            _categories = new BulkObservableList<SegmentCategoryViewModel>();
            _readonlyCategories = new ReadOnlyBindableList<SegmentCategoryViewModel>(_categories);
        }
コード例 #11
0
        public void Segments()
        {
            DispatcherHelper.Initialize();
            var segmentPool     = new SegmentPool();
            var projectService  = Substitute.For <IProjectService>();
            var dialogService   = Substitute.For <IDialogService>();
            var busyService     = Substitute.For <IBusyService>();
            var analysisService = new AnalysisService(_spanFactory, segmentPool, projectService, dialogService, busyService);
            var exportService   = Substitute.For <IExportService>();

            WordsViewModel.Factory wordsFactory = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory  wordFactory  = word => new WordViewModel(busyService, analysisService, word);

            var segments = new SegmentsViewModel(projectService, dialogService, busyService, exportService, wordsFactory, wordFactory);

            CogProject project = TestHelpers.GetTestProject(_spanFactory, segmentPool);

            project.Meanings.AddRange(new[] { new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3") });
            project.Varieties.AddRange(new[] { new Variety("variety1"), new Variety("variety2") });
            project.Varieties[0].Words.AddRange(new[] { new Word("hɛ.loʊ", project.Meanings[0]), new Word("gʊd", project.Meanings[1]), new Word("bæd", project.Meanings[2]) });
            project.Varieties[1].Words.AddRange(new[] { new Word("hɛlp", project.Meanings[0]), new Word("gu.gəl", project.Meanings[1]), new Word("gu.fi", project.Meanings[2]) });
            projectService.Project.Returns(project);
            analysisService.SegmentAll();
            projectService.ProjectOpened += Raise.Event();

            Assert.That(segments.HasSegments, Is.True);
            Assert.That(segments.Segments.Select(s => s.StrRep), Is.EqualTo(new[] { "b", "f", "l", "g", "h" }));
            Assert.That(segments.Categories.Select(c => c.Name), Is.EqualTo(new[] { "Labial", "Coronal", "Dorsal", "Guttural" }));
            Assert.That(segments.Categories[0].Segments, Is.EquivalentTo(new[] { segments.Segments[0], segments.Segments[1] }));
            Assert.That(segments.Categories[1].Segments, Is.EquivalentTo(new[] { segments.Segments[2] }));
            Assert.That(segments.Categories[2].Segments, Is.EquivalentTo(new[] { segments.Segments[3] }));
            Assert.That(segments.Categories[3].Segments, Is.EquivalentTo(new[] { segments.Segments[4] }));

            project.Varieties[0].Words.RemoveAll(project.Meanings[0]);
            analysisService.Segment(project.Varieties[0]);
            Messenger.Default.Send(new DomainModelChangedMessage(true));
            Assert.That(segments.HasSegments, Is.True);
            Assert.That(segments.Segments.Select(s => s.StrRep), Is.EqualTo(new[] { "b", "f", "g", "h" }));
            Assert.That(segments.Categories.Select(c => c.Name), Is.EqualTo(new[] { "Labial", "Dorsal", "Guttural" }));
            Assert.That(segments.Categories[0].Segments, Is.EquivalentTo(new[] { segments.Segments[0], segments.Segments[1] }));
            Assert.That(segments.Categories[1].Segments, Is.EquivalentTo(new[] { segments.Segments[2] }));
            Assert.That(segments.Categories[2].Segments, Is.EquivalentTo(new[] { segments.Segments[3] }));

            segments.SyllablePosition = SyllablePosition.Nucleus;
            Assert.That(segments.HasSegments, Is.True);
            Assert.That(segments.Segments.Select(s => s.StrRep), Is.EqualTo(new[] { "i", "u", "ʊ", "ɛ", "ə", "æ" }));
            Assert.That(segments.Categories.Select(c => c.Name), Is.EqualTo(new[] { "Close", "Mid", "Open" }));
            Assert.That(segments.Categories[0].Segments, Is.EquivalentTo(new[] { segments.Segments[0], segments.Segments[1], segments.Segments[2] }));
            Assert.That(segments.Categories[1].Segments, Is.EquivalentTo(new[] { segments.Segments[3], segments.Segments[4] }));
            Assert.That(segments.Categories[2].Segments, Is.EquivalentTo(new[] { segments.Segments[5] }));

            foreach (Variety variety in project.Varieties)
            {
                variety.Words.Clear();
            }
            analysisService.SegmentAll();
            Messenger.Default.Send(new DomainModelChangedMessage(true));
            Assert.That(segments.HasSegments, Is.False);
            Assert.That(segments.Segments, Is.Empty);
            Assert.That(segments.Categories, Is.Empty);
        }
コード例 #12
0
        public void FindCommand()
        {
            DispatcherHelper.Initialize();
            var projectService  = Substitute.For <IProjectService>();
            var dialogService   = Substitute.For <IDialogService>();
            var busyService     = Substitute.For <IBusyService>();
            var analysisService = Substitute.For <IAnalysisService>();

            WordsViewModel.Factory            wordsFactory   = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory             wordFactory    = word => new WordViewModel(busyService, analysisService, word);
            VarietiesVarietyViewModel.Factory varietyFactory = variety => new VarietiesVarietyViewModel(projectService, dialogService, wordsFactory, wordFactory, variety);

            var varieties = new VarietiesViewModel(projectService, dialogService, analysisService, varietyFactory);

            var project = new CogProject(_spanFactory)
            {
                Meanings  = { new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3") },
                Varieties = { new Variety("variety1"), new Variety("variety2") }
            };

            project.Varieties[0].Words.AddRange(new[] { new Word("hello", project.Meanings[0]), new Word("good", project.Meanings[1]), new Word("bad", project.Meanings[2]) });
            project.Varieties[1].Words.AddRange(new[] { new Word("help", project.Meanings[0]), new Word("google", project.Meanings[1]), new Word("goofy", project.Meanings[2]) });
            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            varieties.VarietiesView = new ListCollectionView(varieties.Varieties);
            WordsViewModel wordsViewModel = varieties.SelectedVariety.Words;

            wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words);
            WordViewModel[] wordsViewArray = wordsViewModel.WordsView.Cast <WordViewModel>().ToArray();

            FindViewModel findViewModel = null;
            Action        closeCallback = null;

            dialogService.ShowModelessDialog(varieties, Arg.Do <FindViewModel>(vm => findViewModel = vm), Arg.Do <Action>(callback => closeCallback = callback));
            varieties.FindCommand.Execute(null);
            Assert.That(findViewModel, Is.Not.Null);
            Assert.That(closeCallback, Is.Not.Null);

            // already open, shouldn't get opened twice
            dialogService.ClearReceivedCalls();
            varieties.FindCommand.Execute(null);
            dialogService.DidNotReceive().ShowModelessDialog(varieties, Arg.Any <FindViewModel>(), Arg.Any <Action>());

            // form searches
            findViewModel.Field = FindField.Form;

            // nothing selected, no match
            findViewModel.String = "fall";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.Empty);

            // nothing selected, matches
            findViewModel.String = "he";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable()));

            // first word selected, matches
            findViewModel.String = "o";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[0].ToEnumerable()));
            // start search over
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));

            // last word selected, matches
            wordsViewModel.SelectedWords.Clear();
            wordsViewModel.SelectedWords.Add(wordsViewArray[2]);
            findViewModel.String = "ba";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable()));

            // switch variety, nothing selected, matches, change selected word
            varieties.SelectedVariety = varieties.Varieties[1];
            wordsViewModel            = varieties.SelectedVariety.Words;
            wordsViewModel.WordsView  = new ListCollectionView(wordsViewModel.Words);
            wordsViewArray            = wordsViewModel.WordsView.Cast <WordViewModel>().ToArray();
            findViewModel.String      = "go";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            wordsViewModel.SelectedWords.Clear();
            wordsViewModel.SelectedWords.Add(wordsViewArray[0]);
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[2].ToEnumerable()));

            // gloss searches
            findViewModel.Field  = FindField.Gloss;
            findViewModel.String = "gloss2";
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
            findViewModel.FindNextCommand.Execute(null);
            Assert.That(wordsViewModel.SelectedWords, Is.EquivalentTo(wordsViewArray[1].ToEnumerable()));
        }
コード例 #13
0
        public void TaskAreas()
        {
            DispatcherHelper.Initialize();
            var projectService  = Substitute.For <IProjectService>();
            var dialogService   = Substitute.For <IDialogService>();
            var busyService     = Substitute.For <IBusyService>();
            var analysisService = Substitute.For <IAnalysisService>();

            WordsViewModel.Factory            wordsFactory   = words => new WordsViewModel(busyService, words);
            WordViewModel.Factory             wordFactory    = word => new WordViewModel(busyService, analysisService, word);
            VarietiesVarietyViewModel.Factory varietyFactory = variety => new VarietiesVarietyViewModel(projectService, dialogService, wordsFactory, wordFactory, variety);

            var varieties = new VarietiesViewModel(projectService, dialogService, analysisService, varietyFactory);

            var project = new CogProject(_spanFactory)
            {
                Meanings  = { new Meaning("gloss1", "cat1"), new Meaning("gloss2", "cat2"), new Meaning("gloss3", "cat3") },
                Varieties = { new Variety("variety1"), new Variety("variety2") }
            };

            project.Varieties[0].Words.AddRange(new[] { new Word("hello", project.Meanings[0]), new Word("good", project.Meanings[1]), new Word("bad", project.Meanings[2]) });
            project.Varieties[1].Words.AddRange(new[] { new Word("help", project.Meanings[0]), new Word("google", project.Meanings[1]), new Word("goofy", project.Meanings[2]) });
            projectService.Project.Returns(project);
            projectService.ProjectOpened += Raise.Event();

            varieties.VarietiesView = new ListCollectionView(varieties.Varieties);

            var commonTasks = (TaskAreaItemsViewModel)varieties.TaskAreas[0];

            var addVariety = (TaskAreaCommandViewModel)commonTasks.Items[0];

            dialogService.ShowModalDialog(varieties, Arg.Do <EditVarietyViewModel>(vm => vm.Name = "variety3")).Returns(true);
            addVariety.Command.Execute(null);
            Assert.That(varieties.SelectedVariety.Name, Is.EqualTo("variety3"));
            Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety1", "variety2", "variety3" }));

            var renameVariety = (TaskAreaCommandViewModel)commonTasks.Items[1];

            dialogService.ShowModalDialog(varieties, Arg.Do <EditVarietyViewModel>(vm => vm.Name = "variety4")).Returns(true);
            renameVariety.Command.Execute(null);
            Assert.That(varieties.SelectedVariety.Name, Is.EqualTo("variety4"));
            Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety1", "variety2", "variety4" }));

            var removeVariety = (TaskAreaCommandViewModel)commonTasks.Items[2];

            dialogService.ShowYesNoQuestion(varieties, Arg.Any <string>(), Arg.Any <string>()).Returns(true);
            removeVariety.Command.Execute(null);
            Assert.That(varieties.SelectedVariety.Name, Is.EqualTo("variety1"));
            Assert.That(varieties.Varieties.Select(v => v.Name), Is.EqualTo(new[] { "variety1", "variety2" }));

            varieties.SelectedVariety = varieties.Varieties.First(v => v.Name == "variety2");

            WordsViewModel wordsViewModel = varieties.SelectedVariety.Words;

            wordsViewModel.WordsView = new ListCollectionView(wordsViewModel.Words);
            var sortWordsByItems = (TaskAreaItemsViewModel)commonTasks.Items[4];
            var sortWordsByGroup = (TaskAreaCommandGroupViewModel)sortWordsByItems.Items[0];

            // default sorting is by gloss, change to form
            sortWordsByGroup.SelectedCommand = sortWordsByGroup.Commands[1];
            sortWordsByGroup.SelectedCommand.Command.Execute(null);
            Assert.That(wordsViewModel.WordsView.Cast <WordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] { "goofy", "google", "help" }));
            // change sorting back to gloss
            sortWordsByGroup.SelectedCommand = sortWordsByGroup.Commands[0];
            sortWordsByGroup.SelectedCommand.Command.Execute(null);
            Assert.That(wordsViewModel.WordsView.Cast <WordViewModel>().Select(w => w.StrRep), Is.EqualTo(new[] { "help", "google", "goofy" }));
        }
コード例 #14
0
        public VarietiesVarietyViewModel(IProjectService projectService, IDialogService dialogService, WordsViewModel.Factory wordsFactory, WordViewModel.Factory wordFactory, Variety variety)
            : base(variety)
        {
            _projectService = projectService;
            _dialogService  = dialogService;

            IEnumerable <Segment> segments = variety.SegmentFrequencyDistribution == null?Enumerable.Empty <Segment>() : variety.SegmentFrequencyDistribution.ObservedSamples;

            _segments                = new BulkObservableList <VarietySegmentViewModel>(segments.Select(seg => new VarietySegmentViewModel(this, seg)));
            _maxSegProb              = _segments.Select(seg => seg.Probability).Concat(0).Max();
            _readOnlySegments        = new ReadOnlyBindableList <VarietySegmentViewModel>(_segments);
            variety.PropertyChanged += variety_PropertyChanged;
            _affixes = new MirroredBindableList <Affix, AffixViewModel>(DomainVariety.Affixes, affix => new AffixViewModel(affix), vm => vm.DomainAffix);
            _words   = new MirroredBindableCollection <Word, WordViewModel>(variety.Words, word =>
            {
                WordViewModel vm = wordFactory(word);
                SelectWordSegments(vm);
                return(vm);
            }, vm => vm.DomainWord);
            _wordsViewModel     = wordsFactory(_words);
            _newAffixCommand    = new RelayCommand(NewAffix);
            _editAffixCommand   = new RelayCommand(EditAffix, CanEditAffix);
            _removeAffixCommand = new RelayCommand(RemoveAffix, CanRemoveAffix);
        }
コード例 #15
0
        public WordListsVarietyMeaningViewModel(IBusyService busyService, IAnalysisService analysisService, WordViewModel.Factory wordFactory, WordListsVarietyViewModel variety, Meaning meaning)
            : base(meaning)
        {
            _busyService     = busyService;
            _analysisService = analysisService;
            _variety         = variety;

            _domainWords = new ObservableList <Word>(variety.DomainVariety.Words[meaning]);
            _words       = new MirroredBindableList <Word, WordViewModel>(_domainWords, word => wordFactory(word), vm => vm.DomainWord);
            _domainWords.CollectionChanged += DomainWordsChanged;
            _strRep = string.Join(",", _domainWords.Select(word => word.StrRep));
            _showInVarietiesCommand = new RelayCommand(ShowInVarieties, () => _domainWords.Count > 0);
        }