예제 #1
0
        public void when_adding_commands_then_registers_commands_with_empty_package_guid()
        {
            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(Guid.Empty.ToString(), 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.Exactly(2));
        }