Beispiel #1
0
        public void GetAllPeopleNames_GathererReturnsSome_ReturnsOnlySome()
        {
            var p1 = new Mock <Person>();

            p1.Setup(p => p.Id).Returns("Sadie");

            var p2 = new Mock <Person>();

            p2.Setup(p => p.Id).Returns("Jack");

            var repo = new Mock <ElementRepository <Person> >();

            repo.Setup(r => r.AllItems).Returns(new[] { p1.Object, p2.Object });

            var gatherer = new Mock <AutoCompleteValueGatherer>(null, null, null);
            var lists    = new Dictionary <string, IEnumerable <string> >();

            lists["person"] = new[] { "bear", "dawson" };

            gatherer.Setup(g => g.GetValueLists(false)).Returns(lists);
            var informant = new PersonInformant(repo.Object, gatherer.Object);

            var list = informant.GetAllPeopleNames();

            Assert.AreEqual(2, list.Count());
            Assert.IsTrue(list.Contains("bear"));
            Assert.IsTrue(list.Contains("dawson"));
        }
Beispiel #2
0
        /// ------------------------------------------------------------------------------------
        public ContributorsEditor(ComponentFile file, string imageKey,
                                  AutoCompleteValueGatherer autoCompleteProvider, PersonInformant personInformant) :
            base(file, null, imageKey)
        {
            InitializeComponent();
            Name = "Contributors";

            _model = new ContributorsListControlViewModel(autoCompleteProvider, SaveContributors);

            // ReSharper disable once UseObjectOrCollectionInitializer
            _contributorsControl      = new ContributorsListControl(_model);
            _contributorsControl.Dock = DockStyle.Fill;
            _contributorsControl.ValidatingContributor += HandleValidatingContributor;

            InitializeGrid();

            Controls.Add(_contributorsControl);

            file.AfterSave += file_AfterSave;

            SetComponentFile(file);

            if (personInformant != null)
            {
                personInformant.PersonUiIdChanged += HandlePersonsUiIdChanged;
            }
        }
Beispiel #3
0
        public void GetHasInformedConsent_PersonNotFound_ReturnsFalse()
        {
            var repo = new Mock <ElementRepository <Person> >();

            repo.Setup(x => x.GetById("Joe")).Returns((Person)null);
            var informant = new PersonInformant(repo.Object, null);

            Assert.IsFalse(informant.GetHasInformedConsent("Joe"));
        }
Beispiel #4
0
        public void GetPersonByName_PersonNotFound_ReturnsNull()
        {
            var repo = new Mock <ElementRepository <Person> >();

            repo.Setup(x => x.GetById("Joe")).Returns((Person)null);
            var informant = new PersonInformant(repo.Object, null);

            Assert.IsNull(informant.GetPersonByNameOrCode("Joe"));
        }
Beispiel #5
0
        public void GetHasInformedConsent_PersonDoesNotExist_ReturnsFalse()
        {
            var person = new Mock <Person>();

            person.Setup(p => p.GetInformedConsentComponentFile()).Returns((ComponentFile)null);
            var repo = new Mock <ElementRepository <Person> >();

            repo.Setup(x => x.GetById("Joe")).Returns(person.Object);
            var informant = new PersonInformant(repo.Object, null);

            Assert.IsFalse(informant.GetHasInformedConsent("Joe"));
        }
Beispiel #6
0
        public void GetPersonByName_PersonFound_ReturnsPerson()
        {
            var componentFile = new Mock <ProjectElementComponentFile>();
            var person        = new Mock <Person>();

            person.Setup(p => p.GetInformedConsentComponentFile()).Returns(componentFile.Object);
            var repo = new Mock <ElementRepository <Person> >();

            repo.Setup(x => x.GetById("Joe")).Returns(person.Object);
            var informant = new PersonInformant(repo.Object, null);

            Assert.AreEqual(person.Object, informant.GetPersonByNameOrCode("Joe"));
        }
Beispiel #7
0
        /// ------------------------------------------------------------------------------------
        public StatisticsViewModel(Project project, PersonInformant personInformant,
                                   SessionWorkflowInformant sessionInformant, IEnumerable <ComponentRole> componentRoles,
                                   AudioVideoDataGatherer backgroundStatisticsMananager)
        {
            ProjectName                 = (project == null ? string.Empty : project.Name);
            ProjectPath                 = (project == null ? string.Empty : project.FolderPath);
            PersonInformant             = personInformant;
            SessionInformant            = sessionInformant;
            _componentRoles             = componentRoles;
            _backgroundStatisticsGather = backgroundStatisticsMananager;
            _backgroundStatisticsGather.NewDataAvailable           += HandleNewStatistics;
            _backgroundStatisticsGather.FinishedProcessingAllFiles += HandleFinishedGatheringStatisticsForAllFiles;

            _chartBuilder = new HTMLChartBuilder(this);
        }
Beispiel #8
0
 public DummySession(string parentFolder, string name, PersonInformant personInformant, params string [] actors) : base(parentFolder, name + "-session", null, new SessionFileType(() => null, () => null),
                                                                                                                        MakeComponent, new XmlFileSerializer(null), (w, x, y, z) =>
                                                                                                                        new ProjectElementComponentFile(w, x, y, z, FieldUpdater.CreateMinimalFieldUpdaterForTests(null)),
                                                                                                                        ApplicationContainer.ComponentRoles, personInformant, null)
 {
     if (actors == null || actors.Length == 0)
     {
         _participants = new[] { "ddo-person" }
     }
     ;
     else
     {
         _participants = actors;
     }
     _metaFile.Setup(m => m.GetStringValue(SessionFileType.kTitleFieldName, null)).Returns(name);
 }
        private StatisticsViewModel CreateModel()
        {
            var nullRole = new ComponentRole(typeof(Session), "someRole", "someRole",
                                             ComponentRole.MeasurementTypes.None,
                                             p => p.EndsWith("txt"), "$ElementId$_someRole", Color.Magenta, Color.Black);

            var personInformer = new PersonInformant(
                new ElementRepository <Person>(_folder.Combine("people"), Person.kFolderName, null, null), null);

            var sessionInformer = new SessionWorkflowInformant(
                new ElementRepository <Session>(_folder.Combine("sessions"), Session.kFolderName, null, null),
                new[] { nullRole });

            return(new StatisticsViewModel(null, personInformer, sessionInformer, new[] { nullRole },
                                           new AudioVideoDataGatherer(_folder.Path, new[] { new AudioFileType(null, () => null, null) })));
        }
Beispiel #10
0
        public void GetAllPeopleNames_GathererContainsMoreThanPeopleNames_ReturnsOnlyPeopleNames()
        {
            var repo     = new Mock <ElementRepository <Person> >();
            var gatherer = new Mock <AutoCompleteValueGatherer>(null, null, null);
            var lists    = new Dictionary <string, IEnumerable <string> >();

            lists["decoy"]  = new[] { "shouldNotFind1", "shouldNotFind2" };
            lists["person"] = new[] { "bear", "dawson" };

            gatherer.Setup(g => g.GetValueLists(false)).Returns(lists);
            var informant = new PersonInformant(repo.Object, gatherer.Object);

            var list = informant.GetAllPeopleNames();

            Assert.AreEqual(2, list.Count());
            Assert.IsTrue(list.Contains("bear"));
            Assert.IsTrue(list.Contains("dawson"));
        }
Beispiel #11
0
        public void GetPeopleNamesFromRepository_ReturnsThem()
        {
            var p1 = new Mock <Person>();

            p1.Setup(p => p.Id).Returns("Sadie");

            var p2 = new Mock <Person>();

            p2.Setup(p => p.Id).Returns("Jack");

            var repo = new Mock <ElementRepository <Person> >();

            repo.Setup(r => r.AllItems).Returns(new[] { p1.Object, p2.Object });
            var informant = new PersonInformant(repo.Object, null);

            var list = informant.GetPeopleNamesFromRepository();

            Assert.AreEqual(2, list.Count());
            Assert.IsTrue(list.Contains("Sadie"));
            Assert.IsTrue(list.Contains("Jack"));
        }
Beispiel #12
0
        /// ------------------------------------------------------------------------------------
        public ContributorsEditor(ComponentFile file, string imageKey,
                                  AutoCompleteValueGatherer autoCompleteProvider, PersonInformant personInformant) :
            base(file, null, imageKey)
        {
            InitializeComponent();
            Name = "Contributors";

            _model = new ContributorsListControlViewModel(autoCompleteProvider, SaveContributors);
            var dataGridView = new DataGridView();

            dataGridView.Columns[dataGridView.Columns.Add("date", "date")].Visible = false;
            _model.ContributorsGridSettings = GridSettings.Create(dataGridView);

            // ReSharper disable once UseObjectOrCollectionInitializer
            _contributorsControl      = new ContributorsListControl(_model);
            _contributorsControl.Dock = DockStyle.Fill;
            _contributorsControl.ValidatingContributor += HandleValidatingContributor;

            InitializeGrid();

            // imageKey == "Contributor" when ContributorsEditor is lazy loaded for the session file type
            if (imageKey != null)
            {
                AddSessionControls();
            }
            else
            {
                Controls.Add(_contributorsControl);
            }

            file.AfterSave += file_AfterSave;

            SetComponentFile(file);

            if (personInformant != null)
            {
                personInformant.PersonUiIdChanged += HandlePersonsUiIdChanged;
            }
        }
Beispiel #13
0
        /// ------------------------------------------------------------------------------------
        public SessionBasicEditor(ComponentFile file, string imageKey,
                                  AutoCompleteValueGatherer autoCompleteProvider, FieldGatherer fieldGatherer,
                                  PersonInformant personInformant)
            : base(file, null, imageKey)
        {
            Logger.WriteEvent("PersonBasicEditor constructor. file = {0}", file);

            InitializeComponent();
            Name = "SessionEditor";

            _personInformant = personInformant;

            _autoCompleteProvider = autoCompleteProvider;
            _autoCompleteProvider.NewDataAvailable += LoadGenreList;

            _binder.TranslateBoundValueBeingRetrieved += HandleBinderTranslateBoundValueBeingRetrieved;
            _binder.TranslateBoundValueBeingSaved     += HandleBinderTranslateBoundValueBeingSaved;

            SetBindingHelper(_binder);
            _autoCompleteHelper.SetAutoCompleteProvider(autoCompleteProvider);

            _id.Enter   += delegate { EnsureFirstRowLabelIsVisible(_labelId); };
            _date.Enter += delegate { EnsureFirstRowLabelIsVisible(_labelDate); };

            _genre.Enter    += delegate { _genreFieldEntered = true; };
            _genre.Leave    += delegate { _genreFieldEntered = false; };
            _genre.KeyPress += HandleGenreKeyPress;

            InitializeGrid(autoCompleteProvider, fieldGatherer);

            file.AfterSave += file_AfterSave;


            if (_personInformant != null)
            {
                _personInformant.PersonUiIdChanged += HandlePersonsUiIdChanged;
            }
        }