Exemple #1
0
        public void GetLibraryInfoFromPath_HandlesProjects()
        {
            const string path = @"C:\Users\Rubberduck\Documents\Book1.xlsm";

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();
            var model      = reconciler.GetLibraryInfoFromPath(path);

            Assert.AreEqual(path, model.FullPath);
            Assert.IsFalse(model.IsBroken);
        }
Exemple #2
0
        public void GetLibraryInfoFromPath_ProjectsDoNotCallLoadLibrary()
        {
            const string path = @"C:\Users\Rubberduck\Documents\Book1.xlsm";

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler(null, out _, out var provider);

            reconciler.GetLibraryInfoFromPath(path);

            provider.Verify(m => m.LoadTypeLibrary(It.IsAny <string>()), Times.Never);
        }
Exemple #3
0
        public void GetLibraryInfoFromPath_LoadLibraryCalledOnTypeExtensions(string extension)
        {
            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler(null, out _, out var provider);
            var path       = $@"C:\Windows\System32\library{extension}";

            AddRemoveReferencesSetup.SetupIComLibraryProvider(provider, new ReferenceInfo(Guid.Empty, "Library", path, 1, 1), path, "Library 1.1");
            reconciler.GetLibraryInfoFromPath(path);

            provider.Verify(m => m.LoadTypeLibrary(It.IsAny <string>()), Times.Once);
        }
Exemple #4
0
        public void TryAddReferenceReferenceModel_ReturnedReferenceIsLastPriority()
        {
            var input      = new ReferenceModel(DummyReferenceInfo, 0);
            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();
            var references = AddRemoveReferencesSetup.GetReferencesMock(out var project, out _).Object;

            var priority = reconciler.TryAddReference(project.Object, input).Priority;

            Assert.IsTrue(priority > 0);
        }
Exemple #5
0
        public void TryAddReferenceReferenceModel_ReturnedReferenceIsRecent()
        {
            var input      = new ReferenceModel(DummyReferenceInfo, 0);
            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();

            AddRemoveReferencesSetup.GetReferencesMock(out var project, out _);

            var model = reconciler.TryAddReference(project.Object, input);

            Assert.IsTrue(model.IsRecent);
        }
Exemple #6
0
        public void TryAddReferenceString_CallsAddFromFile()
        {
            const string file = @"C:\Windows\System32\reference.dll";

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();
            var references = AddRemoveReferencesSetup.GetReferencesMock(out var project, out _);

            reconciler.TryAddReference(project.Object, file);

            references.Verify(m => m.AddFromFile(file), Times.Once);
        }
Exemple #7
0
        public void GetLibraryInfoFromPath_GivesBrokenReferenceOnThrow()
        {
            const string path = @"C:\Windows\System32\bad.dll";

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler(null, out _, out var provider);

            provider.Setup(m => m.LoadTypeLibrary(path)).Throws(new COMException());
            var model = reconciler.GetLibraryInfoFromPath(path);

            Assert.IsTrue(model.IsBroken);
        }
Exemple #8
0
        public void ReconcileReferences_RemoveNotCalledOnBuiltIn()
        {
            var registered = AddRemoveReferencesSetup.DummyReferencesList;
            var model      = AddRemoveReferencesSetup.ArrangeParsedAddRemoveReferencesModel(registered, registered, registered, out var references, out _);
            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();

            var vba   = references.Object.First(lib => lib.Name.Equals("VBA"));
            var excel = references.Object.First(lib => lib.Name.Equals("Excel"));

            reconciler.ReconcileReferences(model.Object, registered);
            references.Verify(m => m.Remove(vba), Times.Never);
            references.Verify(m => m.Remove(excel), Times.Never);
        }
Exemple #9
0
        public void TryAddReferenceString_ReturnsNullOnThrow()
        {
            const string file = @"C:\Windows\System32\reference.dll";

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();
            var references = AddRemoveReferencesSetup.GetReferencesMock(out var project, out _);

            references.Setup(m => m.AddFromFile(file)).Throws(new COMException());

            var model = reconciler.TryAddReference(project.Object, file);

            Assert.IsNull(model);
        }
Exemple #10
0
        public void TryAddReferenceReferenceModel_ReturnsNullOnThrow()
        {
            var input = new ReferenceModel(DummyReferenceInfo, 0);

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();
            var references = AddRemoveReferencesSetup.GetReferencesMock(out var project, out _);

            references.Setup(m => m.AddFromFile(input.FullPath)).Throws(new COMException());

            var model = reconciler.TryAddReference(project.Object, input);

            Assert.IsNull(model);
        }
Exemple #11
0
        public void TryAddReferenceString_DisplaysMessageOnThrow()
        {
            const string file      = @"C:\Windows\System32\reference.dll";
            const string exception = "Don't mock me.";

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler(null, out var messageBox, out _);
            var references = AddRemoveReferencesSetup.GetReferencesMock(out var project, out _);

            references.Setup(m => m.AddFromFile(file)).Throws(new COMException(exception));

            reconciler.TryAddReference(project.Object, file);

            messageBox.Verify(m => m.NotifyWarn(exception, RubberduckUI.References_AddFailedCaption));
        }
Exemple #12
0
        public void TryAddReferenceReferenceModel_DisplaysMessageOnThrow()
        {
            var          input     = new ReferenceModel(DummyReferenceInfo, 0);
            const string exception = "Don't mock me.";

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler(null, out var messageBox, out _);
            var references = AddRemoveReferencesSetup.GetReferencesMock(out var project, out _);

            references.Setup(m => m.AddFromFile(input.FullPath)).Throws(new COMException(exception));

            reconciler.TryAddReference(project.Object, input);

            messageBox.Verify(m => m.NotifyWarn(exception, RubberduckUI.References_AddFailedCaption));
        }
Exemple #13
0
        public void TryAddReferenceString_ReturnedReferenceIsRecent()
        {
            const string file = @"C:\Windows\System32\reference.dll";

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();
            var references = AddRemoveReferencesSetup.GetReferencesMock(out var project, out var builder);

            var returned = builder.CreateReferenceMock("Reference", file, 1, 1, false).Object;

            references.Setup(m => m.AddFromFile(file)).Returns(returned);

            var model = reconciler.TryAddReference(project.Object, file);

            Assert.IsTrue(model.IsRecent);
        }
Exemple #14
0
        public void ViewModelFilters_SearchInputFiltersList(string input, int expected)
        {
            var declaration = AddRemoveReferencesSetup.ArrangeMocksAndGetProject();
            var settings    = AddRemoveReferencesSetup.GetNonDefaultReferenceSettings();
            var model       = new AddRemoveReferencesModel(null, declaration, SearchReferencesList, settings);
            var reconciler  = AddRemoveReferencesSetup.ArrangeReferenceReconciler(settings);

            var viewModel = new AddRemoveReferencesViewModel(model, reconciler, new Mock <IFileSystemBrowserFactory>().Object, null);

            viewModel.SelectedFilter = ReferenceFilter.ComTypes.ToString();
            viewModel.Search         = input;

            var actual = viewModel.AvailableReferences.OfType <ReferenceModel>().Count();

            Assert.AreEqual(expected, actual);
        }
Exemple #15
0
        public void ReconcileReferences_UpdatesSettingsPinned()
        {
            var newReferences = AddRemoveReferencesSetup.LibraryReferenceInfoList
                                .Select(reference => new ReferenceModel(reference, ReferenceKind.TypeLibrary)).ToList();

            var model      = AddRemoveReferencesSetup.ArrangeParsedAddRemoveReferencesModel(null, newReferences, null, out _, out _);
            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();

            var pinned = newReferences.First();

            pinned.IsPinned = true;

            reconciler.ReconcileReferences(model.Object, newReferences);
            var result = model.Object.Settings.GetPinnedReferencesForHost(null).Exists(info => pinned.Matches(info));

            Assert.IsTrue(result);
        }
Exemple #16
0
        public void ReconcileReferences_AllReferencesAreAdded()
        {
            var newReferences = AddRemoveReferencesSetup.LibraryReferenceInfoList
                                .Select(reference => new ReferenceModel(reference, ReferenceKind.TypeLibrary)).ToList();

            var model      = AddRemoveReferencesSetup.ArrangeParsedAddRemoveReferencesModel(newReferences, newReferences, newReferences, out var references, out var builder);
            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler();

            var priority = references.Object.Count;

            foreach (var item in newReferences)
            {
                item.Priority = ++priority;
                var result = builder.CreateReferenceMock(item.Name, item.FullPath, item.Major, item.Minor);
                references.Setup(m => m.AddFromFile(item.FullPath)).Returns(result.Object);
            }

            var added = reconciler.ReconcileReferences(model.Object, newReferences);

            Assert.IsTrue(newReferences.All(reference => added.Contains(reference)));
        }
Exemple #17
0
        public void UpdateSettings_RemovesPinnedLibraries()
        {
            var settings   = AddRemoveReferencesSetup.GetDefaultReferenceSettings();
            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler(settings);

            var input = settings.GetPinnedReferencesForHost(null).Select(info =>
                                                                         new ReferenceModel(info, ReferenceKind.TypeLibrary)
            {
                IsPinned = true
            }).ToList();

            var output = input.Take(1).ToList();

            var model = AddRemoveReferencesSetup.ArrangeAddRemoveReferencesModel(output, null, settings);

            reconciler.UpdateSettings(model.Object);

            var actual   = settings.GetPinnedReferencesForHost(null);
            var expected = output.Select(reference => reference.ToReferenceInfo()).ToList();

            Assert.AreEqual(expected.Count, actual.Count);
            Assert.IsTrue(expected.All(info => actual.Contains(info)));
        }
Exemple #18
0
        public void GetLibraryInfoFromPath_LoadLibraryLoadsModel()
        {
            const string path        = @"C:\Windows\System32\library.dll";
            const string name        = "Library";
            const string description = "Library 1.1";

            var reconciler = AddRemoveReferencesSetup.ArrangeReferenceReconciler(null, out _, out var provider);
            var info       = new ReferenceInfo(AddRemoveReferencesSetup.DummyGuidOne, name, path, 1, 1);

            AddRemoveReferencesSetup.SetupIComLibraryProvider(provider, info, path, description);

            var model = reconciler.GetLibraryInfoFromPath(path);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(model.Guid, AddRemoveReferencesSetup.DummyGuidOne);
                Assert.AreEqual(model.Name, name);
                Assert.AreEqual(model.Description, description);
                Assert.AreEqual(model.FullPath, path);
                Assert.AreEqual(model.Major, 1);
                Assert.AreEqual(model.Minor, 1);
                Assert.IsFalse(model.IsBroken);
            });
        }