/// <summary>
        /// Creates a project with a set number of lines and gives them a state that
        /// can easily be tested for.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="blocks">The block collection in the project.</param>
        /// <param name="blockTypes">The block types supervisor for the project.</param>
        /// <param name="commands">The commands supervisor for the project.</param>
        /// <param name="lineCount">The number of blocks to insert into the projects.</param>
        protected void SetupMultilineTest(
            out BlockCommandContext context,
            out ProjectBlockCollection blocks,
            out BlockTypeSupervisor blockTypes,
            out BlockCommandSupervisor commands,
            int lineCount = 4)
        {
            // Everything is based on the project.
            var project = new Project();

            context    = new BlockCommandContext(project);
            blocks     = project.Blocks;
            commands   = project.Commands;
            blockTypes = project.BlockTypes;

            // Insert the bulk of the lines.
            InsertLines(project, lineCount);

            // Go through and set up the block types for these elements.
            project.Blocks[0].SetBlockType(blockTypes.Chapter);

            for (int index = 1;
                 index < project.Blocks.Count;
                 index++)
            {
                project.Blocks[index].SetBlockType(blockTypes.Scene);
            }
        }
Exemple #2
0
        public void CreateEmptyBlockTypeManager()
        {
            // Arrange
            var project = new Project();

            // Act
            var manager = new BlockTypeSupervisor(project);

            // Assert
            Assert.AreEqual(project, manager.Project);
        }
        protected void SetupComplexMultilineTest(
            out ProjectBlockCollection blocks,
            out BlockTypeSupervisor blockTypes,
            out BlockCommandSupervisor commands,
            int lineCount = 10)
        {
            // Everything is based on the project.
            var project = new Project();

            blocks     = project.Blocks;
            commands   = project.Commands;
            blockTypes = project.BlockTypes;

            // Set up the structure and insert the lines.
            SetupComplexMultilineTest(project, lineCount);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        public Project(
            ProjectProcessingState initialProcessingState =
            ProjectProcessingState.Interactive)
        {
            // Set up the initial states.
            ProcessingState = initialProcessingState;

            // We need the settings set up first since it may contribute
            // to the loading of other components of the project.
            Settings   = new ProjectSettings();
            Properties = new PropertiesDictionary();
            BlockTypes = new BlockTypeSupervisor(this);
            Blocks     = new ProjectBlockCollection(this);
            Commands   = new BlockCommandSupervisor(this);
            Plugins    = new PluginSupervisor(this);
            Macros     = new ProjectMacros();
        }
        protected void SetupComplexMultilineTest(
            Project project,
            int lineCount)
        {
            // Insert the bulk of the lines.
            InsertLines(project, lineCount);

            // Change the block types for the project. This basically builds up a
            // structure of one chapter with any number of scenes that have one
            // epigraph, one epigraph attribution, and two paragraphs.
            BlockTypeSupervisor    blockTypes = project.BlockTypes;
            ProjectBlockCollection blocks     = project.Blocks;

            blocks[0].SetBlockType(blockTypes.Chapter);

            for (int blockIndex = 1;
                 blockIndex < blocks.Count;
                 blockIndex++)
            {
                Block block = blocks[blockIndex];

                if ((blockIndex - 1) % 5 == 0)
                {
                    block.SetBlockType(blockTypes.Scene);
                }
                else if ((blockIndex - 2) % 5 == 0)
                {
                    block.SetBlockType(blockTypes.Epigraph);
                }
                else if ((blockIndex - 3) % 5 == 0)
                {
                    block.SetBlockType(blockTypes.EpigraphAttribution);
                }
                else
                {
                    block.SetBlockType(blockTypes.Paragraph);
                }
            }

            // Let everything finish running.
            project.Plugins.WaitForBlockAnalzyers();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BlockType"/> class.
 /// </summary>
 /// <param name="supervisor">The Supervisor.</param>
 public BlockType(BlockTypeSupervisor supervisor)
 {
     Supervisor = supervisor;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BlockType"/> class.
 /// </summary>
 /// <param name="supervisor">The Supervisor.</param>
 public BlockType(BlockTypeSupervisor supervisor)
 {
     Supervisor = supervisor;
 }
        public void WriteRead()
        {
            // Arrange: Cleanup any existing output file.
            DirectoryInfo testDirectory = PrepareTestDirectory();

            // Arrange: Set up the plugin.
            ProjectBlockCollection             blocks;
            BlockCommandSupervisor             commands;
            PluginSupervisor                   plugins;
            FilesystemPersistenceProjectPlugin projectPlugin;

            SetupPlugin(out blocks, out commands, out plugins, out projectPlugin);

            PersistenceManager persistenceManager = PersistenceManager.Instance;

            // Arrange: Create a project with some interesting data and write it out.
            SetupComplexMultilineTest(blocks.Project, 10);
            blocks.Project.BlockTypes.Add("Custom Type", false);
            Block block = blocks[0];

            block.Properties[new HierarchicalPath("/Test")] = "Custom Property";
            block.TextSpans.Add(new TextSpan(1, 3, null, null));
            using (block.AcquireBlockLock(RequestLock.Write))
            {
                block.SetText("Incor Wurd Onz");
            }
            plugins.WaitForBlockAnalzyers();
            projectPlugin.Settings.SetIndividualDirectoryLayout();
            projectPlugin.Save(testDirectory);

            // Act
            var projectFile =
                new FileInfo(Path.Combine(testDirectory.FullName, "Project.aiproj"));
            Project project = persistenceManager.ReadProject(projectFile);

            // Assert: Block Types
            block = project.Blocks[0];

            BlockTypeSupervisor blockTypes = project.BlockTypes;

            blocks = project.Blocks;

            Assert.AreEqual(2, project.Plugins.Controllers.Count);
            Assert.NotNull(blockTypes["Custom Type"]);
            Assert.IsFalse(blockTypes["Custom Type"].IsStructural);

            // Assert: Blocks
            Assert.AreEqual(10, blocks.Count);

            Assert.AreEqual(blockTypes.Chapter, block.BlockType);
            Assert.AreEqual("Incor Wurd Onz", block.Text);

            Assert.AreEqual(blockTypes.Scene, blocks[1].BlockType);
            Assert.AreEqual("Line 2", blocks[1].Text);

            Assert.AreEqual(blockTypes.Epigraph, blocks[2].BlockType);
            Assert.AreEqual("Line 3", blocks[2].Text);

            Assert.AreEqual(blockTypes.EpigraphAttribution, blocks[3].BlockType);
            Assert.AreEqual("Line 4", blocks[3].Text);

            Assert.AreEqual(blockTypes.Paragraph, blocks[9].BlockType);
            Assert.AreEqual("Line 10", blocks[9].Text);

            // Assert: Verify content data.
            Assert.AreEqual(1, block.Properties.Count);
            Assert.AreEqual(
                "Custom Property", block.Properties[new HierarchicalPath("/Test")]);

            // Assert: Verify text spans.
            Assert.AreEqual(1, block.TextSpans.Count);

            Assert.AreEqual(1, block.TextSpans[0].StartTextIndex);
            Assert.AreEqual(3, block.TextSpans[0].StopTextIndex);
            Assert.IsNull(block.TextSpans[0].Controller);
            Assert.IsNull(block.TextSpans[0].Data);
        }
Exemple #9
0
        public void CountComplexSetup()
        {
            // Arrange
            ProjectBlockCollection   blocks;
            BlockCommandSupervisor   commands;
            WordCounterProjectPlugin projectPlugin;

            SetupPlugin(out blocks, out commands, out projectPlugin);
            SetupComplexMultilineTest(blocks.Project, 6);

            BlockTypeSupervisor blockTypes = blocks.Project.BlockTypes;

            // Act
            blocks.Project.Plugins.WaitForBlockAnalzyers();

            // Assert
            Project project = blocks.Project;

            Assert.AreEqual(1, project.Plugins.Controllers.Count);

            //int index = 0;
            //Assert.AreEqual(
            //	12, blocks[index].Properties.Get<int>(WordCounterPathUtility.WordCountPath));
            //Assert.AreEqual(
            //	36, blocks[index].Properties.Get<int>(WordCounterPathUtility.CharacterCountPath));
            //Assert.AreEqual(
            //	30, blocks[index].Properties.Get<int>(WordCounterPathUtility.NonWhitespaceCountPath));
            //Assert.AreEqual(
            //	1,
            //	blocks[index].Properties.Get<int>(WordCounterPathUtility.GetPath(blockTypes.Chapter)));
            //Assert.AreEqual(
            //	1, blocks[index].Properties.Get<int>(WordCounterPathUtility.GetPath(blockTypes.Scene)));
            //Assert.AreEqual(
            //	1,
            //	blocks[index].Properties.Get<int>(WordCounterPathUtility.GetPath(blockTypes.Epigraph)));
            //Assert.AreEqual(
            //	1,
            //	blocks[index].Properties.Get<int>(
            //		WordCounterPathUtility.GetPath(blockTypes.EpigraphAttribution)));
            //Assert.AreEqual(
            //	2,
            //	blocks[index].Properties.Get<int>(
            //		WordCounterPathUtility.GetPath(blockTypes.Paragraph)));

            //index++;
            //Assert.AreEqual(
            //	10, blocks[index].Properties.Get<int>(WordCounterPathUtility.WordCountPath));
            //Assert.AreEqual(
            //	30, blocks[index].Properties.Get<int>(WordCounterPathUtility.CharacterCountPath));
            //Assert.AreEqual(
            //	25, blocks[index].Properties.Get<int>(WordCounterPathUtility.NonWhitespaceCountPath));
            //Assert.AreEqual(
            //	1, blocks[index].Properties.Get<int>(WordCounterPathUtility.GetPath(blockTypes.Scene)));
            //Assert.AreEqual(
            //	1,
            //	blocks[index].Properties.Get<int>(WordCounterPathUtility.GetPath(blockTypes.Epigraph)));
            //Assert.AreEqual(
            //	1,
            //	blocks[index].Properties.Get<int>(
            //		WordCounterPathUtility.GetPath(blockTypes.EpigraphAttribution)));
            //Assert.AreEqual(
            //	2,
            //	blocks[index].Properties.Get<int>(
            //		WordCounterPathUtility.GetPath(blockTypes.Paragraph)));
        }