public ComparisonViewModelTestConductor(GenomeModel a = null, GenomeModel b = null)
 {
     View = new ComparisonViewModel(
         Favourites.Object,
         a ?? TestGenomeModel.Create(),
         b);
 }
        public void Ctor_ThrowsIfAIsNull_Test()
        {
            var favourites = new MockFavouritesManager().Object;
            var b          = TestGenomeModel.Create();

            Assert.Throws <ArgumentNullException>(() => new ComparisonViewModel(favourites, null, b));
        }
        public void Open_WhenUserCancelsSecondDialog_LoadsFirstDataset_Test()
        {
            var conductor = new ShellViewModelTestConductor();

            conductor.DialogManager.SetupOpenFileToReturn(x => x.Title == "Open Genome A", "a.txt");
            conductor.DialogManager.SetupOpenFileToReturn(x => x.Title == "Open Genome B", null);
            conductor.Loader.SetupLoadAsyncToReturn(x => x == "a.txt", TestGenomeModel.Create());

            conductor.Shell.Open();

            conductor.Loader.AssertLoadAsyncInvoked(Times.Once());
            conductor.Loader.AssertLoadAsyncInvoked(x => x == "a.txt", Times.Once());
        }
        public void Ctor_WhenBIsNotNull_CorrectlyInitializesMembers_Test()
        {
            var a = TestGenomeModel.Create();
            var b = TestGenomeModel.Create();

            var actual = new ComparisonViewModelTestConductor(a, b).View;

            foreach (var snp in actual.Snp)
            {
                Assert.NotNull(snp.GenotypeA);
                Assert.NotNull(snp.GenotypeB);
            }
        }
        public void Open_WhenUserCancelsSecondDialog_ActivatesComparison_Test()
        {
            var conductor = new ShellViewModelTestConductor();

            conductor.DialogManager.SetupOpenFileToReturn(x => x.Title == "Open Genome A", "a.txt");
            conductor.DialogManager.SetupOpenFileToReturn(x => x.Title == "Open Genome B", null);
            conductor.Loader.SetupLoadAsyncToReturn(x => x == "a.txt", TestGenomeModel.Create());

            conductor.Shell.Open();

            var comparison = Assert.IsType <ComparisonViewModel>(conductor.Shell.ActiveItem);

            Assert.True(comparison.Snp.All(x => x.GenotypeB == null));
        }
        public void Ctor_CorrectlyMarksSnpAsFavourites_Test()
        {
            var favouriteManager = new MockFavouritesManager();

            favouriteManager.SetupGetToReturn("rs001", true);
            favouriteManager.SetupGetToReturn("rs002", true);
            favouriteManager.SetupGetToReturn("rs003", false);

            var actual = new ComparisonViewModel(favouriteManager.Object, TestGenomeModel.Create());

            Assert.True(actual.Snp[0].IsFavourite);
            Assert.True(actual.Snp[1].IsFavourite);
            Assert.False(actual.Snp[2].IsFavourite);
        }
        public void Ctor_WhenBIsNotNull_AddsSnpExclusiveToB_Test()
        {
            var a = TestGenomeModel.Create(new string[0]);
            var b = TestGenomeModel.Create("rs001", "rs002", "rs003");

            var actual = new ComparisonViewModelTestConductor(a, b).View;

            Assert.Equal(b.Snp.Count, actual.Snp.Count);
            foreach (var snp in actual.Snp)
            {
                Assert.Null(snp.GenotypeA);
                Assert.NotNull(snp.GenotypeB);
            }
        }
        public void Open_WhenUserSelectsFirstDataset_InvokesOpenFileForSecondDataset_Test()
        {
            var conductor = new ShellViewModelTestConductor();

            conductor.DialogManager.SetupOpenFileToReturn(x => x.Title == "Open Genome A", "a.txt");
            conductor.Loader.SetupLoadAsyncToReturn(x => x == "a.txt", TestGenomeModel.Create());
            conductor.Loader.SetupLoadAsyncToReturn(x => x == "b.txt", TestGenomeModel.Create());

            conductor.Shell.Open();

            conductor.DialogManager.AssertOpenFileInvoked(x =>
                                                          x.Title == "Open Genome B" &&
                                                          x.DefaultExt == ".txt" &&
                                                          x.Filter == "Text documents (.txt)|*.txt");
        }
        public void Open_WhenUserSelectsBothDatasets_LoadsFirstAndSecondDatasets_Test()
        {
            var conductor = new ShellViewModelTestConductor();

            conductor.DialogManager.SetupOpenFileToReturn(x => x.Title == "Open Genome A", "a.txt");
            conductor.DialogManager.SetupOpenFileToReturn(x => x.Title == "Open Genome B", "b.txt");
            conductor.Loader.SetupLoadAsyncToReturn(x => x == "a.txt", TestGenomeModel.Create());
            conductor.Loader.SetupLoadAsyncToReturn(x => x == "b.txt", TestGenomeModel.Create());

            conductor.Shell.Open();

            conductor.Loader.AssertLoadAsyncInvoked(Times.Exactly(2));
            conductor.Loader.AssertLoadAsyncInvoked(x => x == "a.txt", Times.Once());
            conductor.Loader.AssertLoadAsyncInvoked(x => x == "b.txt", Times.Once());
        }
        public void Open_WhenLoadingDatasets_NotifiesOfPropertyChanged_Test()
        {
            var conductor = new ShellViewModelTestConductor();

            conductor.DialogManager.SetupOpenFileToReturn(x => x.Title == "Open Genome A", "a.txt");
            conductor.Loader.SetupLoadAsyncToReturn(x => x == "a.txt", TestGenomeModel.Create());

            conductor.Shell.CreatePropertyChangedObserver()
            .ExpectPropertyChanged(x => x.IsBusy)
            .ExpectPropertyChanged(x => x.ActiveItem)                // null.
            .ExpectPropertyChanged(x => x.ActiveItem)
            .ExpectPropertyChanged(x => x.IsBusy)
            .Verify(x => x.Open());

            Assert.False(conductor.Shell.IsBusy);
        }
        public void Ctor_ThrowsIfFavouritesManagerIsNull_Test()
        {
            var a = TestGenomeModel.Create();

            Assert.Throws <ArgumentNullException>(() => new ComparisonViewModel(null, a));
        }