Exemplo n.º 1
0
        public void when_added_command_exists_then_throws()
        {
            var manager = new CommandManager(
                Mock.Of<IServiceProvider>(x =>
                    x.GetService(typeof(SVsShell)) == Mock.Of<IVsShell>() &&
                    x.GetService(typeof(DTE)) == Mock.Of<DTE>(dte =>
                        dte.Events.get_CommandEvents(It.IsAny<string>(), It.IsAny<int>()) == Mock.Of<CommandEvents>()) &&
                    x.GetService(typeof(IMenuCommandService)) == Mock.Of<IMenuCommandService>(mcs =>
                        mcs.FindCommand(It.IsAny<CommandID>()) == new MenuCommand(null, new CommandID(Guid.Empty, 0)))),
                Enumerable.Empty<Lazy<ICommandExtension, CommandAttribute>>(),
                Enumerable.Empty<Lazy<ICommandFilter, CommandFilterAttribute>>(),
                Enumerable.Empty<Lazy<ICommandInterceptor, CommandInterceptorAttribute>>());

            Assert.Throws<ArgumentException>(() =>
                manager.AddCommand(Mock.Of<ICommandExtension>(), new CommandAttribute(Guid.NewGuid().ToString(), 5)));
        }
Exemplo n.º 2
0
        public void when_adding_commands_then_skips_commands_for_other_packages()
        {
			var menusvc = new Mock<IMenuCommandService> ();

			var package = new Mock<MockPackage> ().As<IServiceProvider>();
			package.Setup(x => x.GetService(typeof(IMenuCommandService))).Returns(menusvc.Object);
			package.Setup(x => x.GetService(typeof(SVsShell))).Returns(Mock.Of<IVsShell>());
			package.Setup(x => x.GetService(typeof(DTE))).Returns(Mock.Of<DTE>(dte =>
                        dte.Events.get_CommandEvents(It.IsAny<string>(), It.IsAny<int>()) == Mock.Of<CommandEvents>()));

            var manager = new CommandManager(package.Object,
				new Lazy<ICommandExtension, CommandAttribute>[] {
					new Lazy<ICommandExtension, CommandAttribute>(() => Mock.Of<ICommandExtension>(), new CommandAttribute("CCB471F4-B764-4B1C-BEB7-26AFE5B9F48E", Guid.NewGuid().ToString(), 1)),
					new Lazy<ICommandExtension, CommandAttribute>(() => Mock.Of<ICommandExtension>(), new CommandAttribute("CD7DB44E-0472-49C8-92C5-046677F55E27", Guid.NewGuid().ToString(), 1)),
				},
                Enumerable.Empty<Lazy<ICommandFilter, CommandFilterAttribute>>(),
                Enumerable.Empty<Lazy<ICommandInterceptor, CommandInterceptorAttribute>>());

			manager.AddCommands ();

			menusvc.Verify (x => x.AddCommand (It.IsAny<MenuCommand> ()), Times.Once ());
        }