コード例 #1
0
        public void FactoryMethodTest()
        {
            // Arrange
            var factory = new DocumentFactory();

            // Act
            var pdfDocument = factory.CreateDocument("Pdf");
            var xmlDocument = factory.CreateDocument("Xml");

            // Assert
            Assert.IsInstanceOfType(pdfDocument, typeof(PdfDocument));
            Assert.AreEqual("Pdf", pdfDocument.GetDocumentType());

            Assert.IsInstanceOfType(xmlDocument, typeof(XmlDocument));
            Assert.AreEqual("Xml", xmlDocument.GetDocumentType());
        }
コード例 #2
0
        public void SetUpFixture()
        {
            string python = "class Test:\r\n" +
                            "\tdef __init__(self):\r\n" +
                            "\t\tpass\r\n";

            DefaultProjectContent projectContent = new DefaultProjectContent();
            PythonParser          parser         = new PythonParser();

            compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);
            if (compilationUnit.Classes.Count > 0)
            {
                c = compilationUnit.Classes[0];
                if (c.Methods.Count > 0)
                {
                    method = c.Methods[0];
                }

                // Get folds.
                ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy();
                ParseInformation      parseInfo       = new ParseInformation();
                parseInfo.SetCompilationUnit(compilationUnit);

                DocumentFactory docFactory = new DocumentFactory();
                IDocument       doc        = docFactory.CreateDocument();
                doc.TextContent = python;
                List <FoldMarker> markers = foldingStrategy.GenerateFoldMarkers(doc, @"C:\Temp\test.py", parseInfo);

                if (markers.Count > 1)
                {
                    classMarker  = markers[0];
                    methodMarker = markers[1];
                }
            }
        }
コード例 #3
0
        internal Document CreateDocument(Guid mailboxGuid, bool initializeNestedDocuments)
        {
            Util.ThrowOnNullArgument(mailboxGuid, "mailboxGuid");
            DocumentFactory documentFactory = DocumentFactory.Current;

            return((Document)documentFactory.CreateDocument(new SimpleIdentity <Guid>(mailboxGuid), DocumentOperation.Insert, null, initializeNestedDocuments));
        }
コード例 #4
0
        /// <summary>
        /// Called to test a C# codefix when applied on the inputted string as a source
        /// </summary>
        /// <param name="oldSource">A class in the form of a string before the CodeFix was applied to it</param>
        /// <param name="newSource">A class in the form of a string after the CodeFix was applied to it</param>
        /// <param name="codeFixIndex">Index determining which codefix to apply if there are multiple</param>
        /// <param name="allowNewCompilerDiagnostics">A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied</param>
        protected void VerifyFix(string oldSource, string newSource, int?codeFixIndex = null, bool allowNewCompilerDiagnostics = false)
        {
            var analyzer        = this.GetDiagnosticAnalyzer();
            var codeFixProvider = this.GetCodeFixProvider();

            var document            = DocumentFactory.CreateDocument(oldSource);
            var analyzerDiagnostics = analyzer.GetSortedDiagnosticsFromDocuments(new[] { document });
            var compilerDiagnostics = document.GetCompilerDiagnostics();
            var attempts            = analyzerDiagnostics.Length;

            for (int i = 0; i < attempts; ++i)
            {
                var actions = new List <CodeAction>();
                var context = new CodeFixContext(document, analyzerDiagnostics[0], (a, d) => actions.Add(a), CancellationToken.None);
                codeFixProvider.RegisterCodeFixesAsync(context).Wait();

                if (!actions.Any())
                {
                    break;
                }

                if (codeFixIndex != null)
                {
                    document = ApplyFix(document, actions.ElementAt((int)codeFixIndex));
                    break;
                }

                document            = ApplyFix(document, actions.ElementAt(0));
                analyzerDiagnostics = analyzer.GetSortedDiagnosticsFromDocuments(new[] { document });

                var newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, document.GetCompilerDiagnostics());

                // check if applying the code fix introduced any new compiler diagnostics
                if (!allowNewCompilerDiagnostics && newCompilerDiagnostics.Any())
                {
                    // Format and get the compiler diagnostics again so that the locations make sense in the output
                    document = document.WithSyntaxRoot(Formatter.Format(document.GetSyntaxRootAsync().Result, Formatter.Annotation, document.Project.Solution.Workspace));
                    newCompilerDiagnostics = GetNewDiagnostics(compilerDiagnostics, document.GetCompilerDiagnostics());

                    Assert.IsTrue(
                        false,
                        string.Format(
                            "Fix introduced new compiler diagnostics:\r\n{0}\r\n\r\nNew document:\r\n{1}\r\n",
                            string.Join("\r\n", newCompilerDiagnostics.Select(d => d.ToString())),
                            document.GetSyntaxRootAsync().Result.ToFullString()));
                }

                // check if there are analyzer diagnostics left after the code fix
                if (!analyzerDiagnostics.Any())
                {
                    break;
                }
            }

            // after applying all of the code fixes, compare the resulting string to the inputted one
            var actual = document.GetStringFromDocument();

            Assert.AreEqual(newSource, actual);
        }
コード例 #5
0
ファイル: Db.cs プロジェクト: kjczarne/couchy
        public async Task <IDocument> Read <T>(string id) where T : IDocument
        {
            var response = await _getDocResponse(id);

            var jsonString = await response.Content.ReadAsStringAsync();

            return(DocumentFactory.CreateDocument <T>(jsonString));
        }
コード例 #6
0
        static void Main(string[] args)
        {
            IDocument document = DocumentFactory.CreateDocument();

            Console.WriteLine("Created Document Type : " + document.GetDocumentType());

            document = DocumentFactory.CreateDocument("WORD");
            Console.WriteLine("Created Document Type : " + document.GetDocumentType());

            Console.ReadLine();
        }
コード例 #7
0
        public async Task <IOTAwareContext> CreateDocumentAsync(string name)
        {
            if ((await Service.CreateDocumentAsync(new DocumentMetaData {
                Name = name, ClientId = this.Id
            })))
            {
                return(DocumentFactory.CreateDocument(name));
            }

            return(null);
        }
コード例 #8
0
        public void BeginLineOnSecondLine()
        {
            DomRegion       region   = new DomRegion(1, 0, 2, 0);
            DocumentFactory factory  = new DocumentFactory();
            IDocument       document = factory.CreateDocument();

            document.TextContent = "1234567890\r\n1234567890\r\n1234567890";
            ISegment segment = WixDocument.ConvertRegionToSegment(document, region);

            WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(12, 13);

            Assert.AreEqual(expectedSegment, segment);
        }
コード例 #9
0
        public void SingleLine()
        {
            DomRegion       region   = new DomRegion(0, 0, 0, 5);
            DocumentFactory factory  = new DocumentFactory();
            IDocument       document = factory.CreateDocument();

            document.TextContent = "1234567890";
            ISegment segment = WixDocument.ConvertRegionToSegment(document, region);

            WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(0, 6);

            Assert.AreEqual(expectedSegment, segment);
        }
コード例 #10
0
        public void ThreeLinesWithoutCarriageReturn()
        {
            DomRegion       region   = new DomRegion(0, 2, 2, 1);
            DocumentFactory factory  = new DocumentFactory();
            IDocument       document = factory.CreateDocument();

            document.TextContent = "1234567890\n1234567890\n1234567890";
            ISegment segment = WixDocument.ConvertRegionToSegment(document, region);

            WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(2, 22);

            Assert.AreEqual(expectedSegment, segment);
        }
コード例 #11
0
        public bool UploadDocument(DocumentMetaData meta, object content)
        {
            if (!Documents.ContainsKey(meta.Name))
            {
                var newDocument = DocumentFactory.CreateDocument(meta.Name);
                syncManager.SetContent(newDocument, content);
                Documents[meta.Name] = newDocument;

                return(true);
            }

            return(false);
        }
コード例 #12
0
        internal IDocument CreateTrainingSubDocument(IEnumerable <MdbCompositeItemIdentity> itemIterator, int maxDocumentCount, Guid mailboxGuid, Guid mdbGuid, IEnumerable <Tuple <PropertyDefinition, object> > propertiesForAllNestedDocuments)
        {
            DocumentFactory documentFactory = DocumentFactory.Current;
            IDocument       document        = (Document)documentFactory.CreateDocument(new SimpleIdentity <Guid>(mailboxGuid), DocumentOperation.Insert, null, true);

            foreach (MdbCompositeItemIdentity mdbCompositeItemIdentity in itemIterator)
            {
                Document document2 = (Document)documentFactory.CreateDocument(new MdbCompositeItemIdentity(mdbGuid, mailboxGuid, mdbCompositeItemIdentity.ItemId, 1), DocumentOperation.Insert);
                if (propertiesForAllNestedDocuments != null)
                {
                    foreach (Tuple <PropertyDefinition, object> tuple in propertiesForAllNestedDocuments)
                    {
                        document2.SetProperty(tuple.Item1, tuple.Item2);
                    }
                }
                document.AddDocument(document2);
                if (document.NestedDocuments.Count == maxDocumentCount)
                {
                    break;
                }
            }
            return(document);
        }
コード例 #13
0
        public async Task <IOTAwareContext> UploadDocumentAsync(string name, object content)
        {
            if (await Service.UploadDocumentAsync(new DocumentMetaData {
                Name = name, ClientId = this.Id
            }, content))
            {
                var newDocument = DocumentFactory.CreateDocument(name);
                syncManager.SetContent(newDocument, content);
                Documents[name] = newDocument;

                return(newDocument);
            }

            return(null);
        }
コード例 #14
0
        public async Task <IOTAwareContext> OpenDocumentAsync(string name)
        {
            var meta = new DocumentMetaData {
                Name = name, ClientId = this.Id
            };

            if ((await Service.OpenDocumentAsync(meta)))
            {
                var openedDocument = DocumentFactory.CreateDocument(name);
                Documents[name] = openedDocument;
                syncManager.SetContent(openedDocument, await Service.SynchronizeDocumentAsync(meta));

                return(openedDocument);
            }

            return(null);
        }
コード例 #15
0
        public bool CreateDocument(DocumentMetaData document)
        {
            if (!Documents.ContainsKey(document.Name))
            {
                var newInstance = DocumentFactory.CreateDocument(document.Name);
                Documents[document.Name] = newInstance;

                var to = Clients.Where(c => c.Key != document.ClientId);
                Parallel.ForEach(to, c => c.Value.Client.NotifyDocumentCreated(document.Name));

                return(true);
            }

            else
            {
                return(false);
            }
        }
コード例 #16
0
        public void SetUpFixture()
        {
            string python = "def foo():\r\n" +
                            "\tpass\r\n" +
                            "\r\n" +
                            "def bar(i):\r\n" +
                            "\tpass";

            DefaultProjectContent projectContent = new DefaultProjectContent();
            PythonParser          parser         = new PythonParser();

            compilationUnit = parser.Parse(projectContent, @"C:\test.py", python);

            if (compilationUnit.Classes.Count > 0)
            {
                globalClass = compilationUnit.Classes[0];
                if (globalClass.Methods.Count > 1)
                {
                    fooMethod = globalClass.Methods[0];
                    barMethod = globalClass.Methods[1];
                }
            }

            // Get folds.
            ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy();
            ParseInformation      parseInfo       = new ParseInformation();

            parseInfo.SetCompilationUnit(compilationUnit);

            DocumentFactory docFactory = new DocumentFactory();
            IDocument       doc        = docFactory.CreateDocument();

            doc.TextContent = python;
            List <FoldMarker> markers = foldingStrategy.GenerateFoldMarkers(doc, @"C:\Temp\test.py", parseInfo);

            if (markers.Count > 1)
            {
                fooMethodMarker = markers[0];
                barMethodMarker = markers[1];
            }
        }
コード例 #17
0
        public void SetUpFixture()
        {
            string Ruby = "class Test\r\n" +
                          "\r\n" +
                          "\tdef foo\r\n" +
                          "\tend\r\n" +
                          "end";

            DefaultProjectContent projectContent = new DefaultProjectContent();
            RubyParser            parser         = new RubyParser();

            compilationUnit = parser.Parse(projectContent, @"C:\test.rb", Ruby);
            if (compilationUnit.Classes.Count > 0)
            {
                c = compilationUnit.Classes[0];
                if (c.Methods.Count > 0)
                {
                    method = c.Methods[0];
                }

                // Get folds.
                ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy();
                ParseInformation      parseInfo       = new ParseInformation();
                parseInfo.SetCompilationUnit(compilationUnit);

                DocumentFactory docFactory = new DocumentFactory();
                IDocument       doc        = docFactory.CreateDocument();
                doc.TextContent = Ruby;
                List <FoldMarker> markers = foldingStrategy.GenerateFoldMarkers(doc, @"C:\Temp\test.rb", parseInfo);

                if (markers.Count > 0)
                {
                    classMarker = markers[0];
                }
                if (markers.Count > 1)
                {
                    methodMarker = markers[1];
                }
            }
        }
コード例 #18
0
 public FileContent(Encoding encoding)
     : this(documentFactory.CreateDocument(), encoding)
 {
 }
コード例 #19
0
 /// <inheritdoc />
 public IDocument CreateDocument(
     NormalizedPath source,
     NormalizedPath destination,
     IEnumerable <KeyValuePair <string, object> > items,
     IContentProvider contentProvider = null) =>
 _documentFactory.CreateDocument(source, destination, items, contentProvider);