public async Task ExtractClass_with_filename_set_copies_element_to_new_file_and_inserts_ux_class_attribute()
        {
            // Setup
            _root = CreateRootElement();
            var      projectClasses  = new BehaviorSubject <IEnumerable <IElement> >(new IElement[] {});
            var      project         = Substitute.For <IProject>();
            IElement createdFileRoot = null;

            project.Classes.ReturnsForAnyArgs(projectClasses);

            project
            .CreateDocument(default(RelativeFilePath))
            .ReturnsForAnyArgs(
                ci =>
            {
                var fragment           = ci.Arg <SourceFragment>();
                var nativeRelativePath = ci.Arg <RelativeFilePath>().NativeRelativePath;
                createdFileRoot        = CreateRootElement(fragment, nativeRelativePath);
                projectClasses.OnNext(new[] { createdFileRoot });
                return(Task.FromResult(false));                                // no idea what i'm doing
            });
            var classExtractor = new ClassExtractor(project);

            // Do
            await classExtractor.ExtractClass(await GetTreeChild("Panel"), "MyPanel", RelativeFilePath.Parse("CustomPanel.ux"));

            // Assert
            Assert.That(createdFileRoot, Is.Not.Null);
            Assert.That(await createdFileRoot.Name.FirstAsync(), Is.EqualTo("Panel"));
            Assert.That(await createdFileRoot.UxClass().FirstAsync(), Is.EqualTo(Optional.Some("MyPanel")));
            Assert.That(await GetTreeChild("MyPanel"), Is.Not.Null);
        }
        public async Task ExtractClass_turns_element_into_a_class_and_inserts_an_instance_of_that_class_beside_it()
        {
            _root = CreateRootElement();
            var classExtractor = new ClassExtractor(Substitute.For <IProject>());
            await classExtractor.ExtractClass(await GetTreeChild("Panel"), "CustomPanel", Optional.None());

            var uxClassAttribute = await(await GetTreeChild("Panel")).UxClass().FirstAsync();

            Assert.That(uxClassAttribute, Is.EqualTo(Optional.Some("CustomPanel")));
            Assert.That(await GetTreeChild("CustomPanel"), Is.Not.Null);
        }
        public async Task ExtractClass_prints_message_to_logview_when_exception_is_thrown()
        {
            _root = CreateRootElement();
            var projectClasses = new BehaviorSubject <IEnumerable <IElement> >(new IElement[] { });
            var project        = Substitute.For <IProject>();

            project.Classes.ReturnsForAnyArgs(projectClasses);

            project
            .CreateDocument(default(RelativeFilePath))
            .ReturnsForAnyArgs(_ =>
                               Task.Run(() => { throw new IOException("Couldn't write a file, as the disk just imploded"); }));

            var    classExtractor = new ClassExtractor(project);
            string logMessage     = null;

            using (classExtractor.LogMessages.Subscribe(message => logMessage = message))
            {
                await classExtractor.ExtractClass(await GetTreeChild("Panel"), "MyPanel", RelativeFilePath.Parse("CustomPanel.ux"));
            }

            Assert.That(logMessage, Is.EqualTo("Error: Unable to create class. Couldn't write a file, as the disk just imploded\r\n"));
        }