A composite command that includes a mixin to a child class by generating the mixin from an interface of the child class. A reference field to the mixin instance will also be created in the child class.
Inheritance: CompositeCommand
        public void CreateMixinFromInterfaceCommand_NoMixin()
            var command = new CreateMixinFromInterfaceCommand(null);
            var childClass = NSubstitute.Substitute.For<ClassWithSourceCode>();

        public void CreateMixinFromBaseClass()
            WithSourceFiles(Files.NotCompilable, Files.Mixin);
            var childClass = CreateClass("SimpleChildClassWithInterface");
            var baseInterface = childClass.SourceCode.BaseList.Types[0];

            var command = new CreateMixinFromInterfaceCommand((SimpleBaseTypeSyntax)baseInterface, Semantic);

            var result = command.Execute(childClass.SourceCode, Semantic);

            Assert.IsTrue(result.Members.Count == 2);
            Assert.IsTrue(result.Members.Any(x => x is FieldDeclarationSyntax));
            Assert.IsTrue(result.Members.Any(x => x is MemberDeclarationSyntax));
        public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
            var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
            // Find the node at the selection.
            var node = root.FindNode(context.Span);

            var model = await context.Document.GetSemanticModelAsync(context.CancellationToken).ConfigureAwait(false);

            CompositeCommand command = null;
            // create mixin from base type
            var baseTypeSyntax = node as SimpleBaseTypeSyntax;
            // create command depending on the selected node
            if (baseTypeSyntax != null)
                command = new CreateMixinFromInterfaceCommand(baseTypeSyntax, model);
                var fieldDeclarationNode = GetContainingFieldDeclaration(node);
                if (fieldDeclarationNode != null)
                    command = new CreateMixinFromFieldDeclarationCommand(fieldDeclarationNode, model);

            if (command == null)

            // get service provider and read settings from storage
            var serviceProvider = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider;
            var settings = new Settings(serviceProvider);

            var childClassDeclaration = node.FindContainingClass();
            var childClass = new ClassFactory(model).Create(childClassDeclaration);
            if (!command.CanExecute(childClass, settings))
            var action = CodeAction.Create(
                c => CreateMixin(command, context.Document, childClass, c));
            // Register this code action.