Esempio n. 1
0
        public void Presenter_Reject_ReturnsNull()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 15, 1, 15);

            IVBComponent component;
            var          vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);

            using (var state = MockParser.CreateAndParse(vbe.Object))
            {
                var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

                var model = new ExtractInterfaceModel(state, qualifiedSelection);
                model.Members.ElementAt(0).IsSelected = true;

                var view = new Mock <IRefactoringDialog <ExtractInterfaceViewModel> >();
                view.Setup(v => v.ViewModel).Returns(new ExtractInterfaceViewModel());
                view.Setup(v => v.DialogResult).Returns(DialogResult.Cancel);

                var factory = new ExtractInterfacePresenterFactory(vbe.Object, state, view.Object);

                var presenter = factory.Create();

                Assert.AreEqual(null, presenter.Show());
            }
        }
        public void Factory_NullSelectionNullReturnsNullPresenter()
        {
            //Input
            const string inputCode =
                @"Private Sub Foo()
End Sub";

            //Arrange
            var builder        = new MockVbeBuilder();
            var projectBuilder = builder.ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none);

            projectBuilder.AddComponent("Module1", vbext_ComponentType.vbext_ct_ClassModule, inputCode);
            var project = projectBuilder.Build();

            builder.AddProject(project);
            var vbe = builder.Build();

            vbe.Setup(v => v.ActiveCodePane).Returns((CodePane)null);

            var mockHost = new Mock <IHostApplication>();

            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var factory = new ExtractInterfacePresenterFactory(vbe.Object, parser.State, null);

            Assert.AreEqual(null, factory.Create());
        }
        public void Factory_NoMembersInTarget_ReturnsNull()
        {
            //Input
            const string inputCode =
                @"Private Sub Foo()
End Sub";
            var selection = new Selection(1, 15, 1, 15);

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component, selection);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var factory = new ExtractInterfacePresenterFactory(vbe.Object, state, null);

            Assert.AreEqual(null, factory.Create());
        }
        public void Factory_NullSelectionNullReturnsNullPresenter()
        {
            //Input
            const string inputCode =
                @"Private Sub Foo()
End Sub";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleModule(inputCode, ComponentType.ClassModule, out component);
            var          state = MockParser.CreateAndParse(vbe.Object);

            vbe.Setup(v => v.ActiveCodePane).Returns((ICodePane)null);

            var factory = new ExtractInterfacePresenterFactory(vbe.Object, state, null);

            Assert.AreEqual(null, factory.Create());
        }
        public void Presenter_Accept_ReturnsUpdatedModel()
        {
            //Input
            const string inputCode =
                @"Public Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub";
            var selection = new Selection(1, 15, 1, 15);

            //Arrange
            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe      = builder.BuildFromSingleModule(inputCode, vbext_ComponentType.vbext_ct_ClassModule, out component, selection);
            var         mockHost = new Mock <IHostApplication>();

            mockHost.SetupAllProperties();
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState(new Mock <ISinks>().Object));

            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

            var model = new ExtractInterfaceModel(parser.State, qualifiedSelection);

            model.Members.ElementAt(0).IsSelected = true;

            var view = new Mock <IExtractInterfaceDialog>();

            view.Setup(v => v.ShowDialog()).Returns(DialogResult.OK);
            view.Setup(v => v.InterfaceName).Returns("Class1");

            var factory   = new ExtractInterfacePresenterFactory(vbe.Object, parser.State, view.Object);
            var presenter = factory.Create();

            Assert.AreEqual("Class1", presenter.Show().InterfaceName);
        }