コード例 #1
0
        public void CanReplaceDocumentObjectUsed()
        {
            MockDocument doc = new MockDocument();

            editor.SetDocument(doc);
            Assert.AreSame(doc, editor.Document);
        }
コード例 #2
0
        public ElasticRepositoryTests()
        {
            _mockDocumentWithoutId = new MockDocument {
                Name         = "mock #1",
                Value        = "mock #1's value",
                CreationDate = DateTime.UtcNow,
                IsActive     = true
            };

            _mockDocumentWithId = new MockDocument {
                Id           = "99",
                Name         = "mock #2",
                Value        = "mock #2's value",
                CreationDate = DateTime.UtcNow,
                IsActive     = false
            };

            ElasticClientManager.Initialize(new List <string> {
                string.Format(_testEndpoint, _testUsername, _testPassword)
            },
                                            _testIndex);

            var client = ElasticClientManager.GetInstance(_testIndex);

            _mockRepo = new ElasticRepository <MockDocument>(client);
        }
コード例 #3
0
        public void SetUp()
        {
            // Set up SearchOptions required by the BruteForceSearchStrategy.
            SearchOptions.CurrentFindPattern = "foo";
            SearchOptions.MatchCase          = false;
            SearchOptions.MatchWholeWord     = false;

            // Create search.
            search = new Search();
            search.TextIteratorBuilder = new ForwardTextIteratorBuilder();
            search.SearchStrategy      = new BruteForceSearchStrategy();
            MockCurrentDocumentIterator currentDocIterator = new MockCurrentDocumentIterator();

            search.DocumentIterator = currentDocIterator;

            // Create the document to be searched.
            MockDocument             doc = new MockDocument();
            StringTextBufferStrategy textBufferStrategy = new StringTextBufferStrategy();

            textBufferStrategy.SetContent("foo");
            doc.TextBufferStrategy = textBufferStrategy;

            // Create a doc info with an initial end offset right
            // at the end of the text.
            ProvidedDocumentInformation docInfo = new ProvidedDocumentInformation(doc, @"C:\Temp\test.txt", doc.TextLength);

            currentDocIterator.Current         = docInfo;
            currentDocIterator.CurrentFileName = docInfo.FileName;

            // Search the document.
            search.SearchStrategy.CompilePattern(null);
            result = search.FindNext(null);
        }
コード例 #4
0
        public MongoRepositoryTests()
        {
            _mockObject = new MockObject {
                Name = "mock #0"
            };

            _mockDocument99 = new MockDocument {
                Id           = "98",
                Name         = "mock #1",
                Value        = "mock #1's value",
                CreationDate = DateTime.UtcNow,
                IsActive     = true
            };

            _mockDocument98 = new MockDocument {
                Id           = "99",
                Name         = "mock #2",
                Value        = "mock #2's value",
                CreationDate = DateTime.UtcNow,
                IsActive     = false
            };

            MongoClientManager.Initialize(_testConnectionString, _testDatabase);

            var database = MongoClientManager.GetInstance(_testDatabase);

            _mockObjectRepo   = new MongoRepository <MockObject>(database);
            _mockDocumentRepo = new MongoRepository <MockDocument, string>(database);
        }
コード例 #5
0
        public async Task Simple_Request()
        {
            // arrange
            TestServer server = CreateStarWarsServer();
            HttpClient client = server.CreateClient();

            client.BaseAddress = new Uri("http://localhost:5000/graphql");

            var document = new MockDocument("query Test { __typename }");
            var request  = new OperationRequest("Test", document);

            // act
            var results    = new List <JsonDocument>();
            var connection = new HttpConnection(() => client);

            await foreach (var response in connection.ExecuteAsync(request))
            {
                if (response.Body is not null)
                {
                    results.Add(response.Body);
                }
            }

            // assert
            Assert.Collection(
                results,
                t => t.RootElement.ToString().MatchSnapshot());
        }
コード例 #6
0
        public void SetUp()
        {
            document  = new Document();
            validator = new DocumentValidator();
            results   = new ValidationResult();

            document = MockDocument.Get();
        }
コード例 #7
0
        public void TextEditorDocumentGetTextReturnsCorrectSectionOfText()
        {
            TextSection expectedSection = new TextSection(0, 5);

            MockDocument document = new MockDocument();

            document.Text = "abcdefghi";

            Assert.AreEqual("def", document.GetText(3, 3));
        }
        public void SetUp()
        {
            // Create the document to be iterated through.
            MockDocument doc = new MockDocument();
            ProvidedDocumentInformation docInfo = new ProvidedDocumentInformation(doc,
                                                                                  @"C:\Temp\test.txt",
                                                                                  0);

            // Create the forward iterator.
            forwardTextIterator = new ForwardTextIterator(docInfo);
        }
コード例 #9
0
        public void CreateTextEditorSnapshot_DocumentHasFakeSnapshot_ReturnsFakeSnapshot()
        {
            CreateXmlFoldingManager();

            MockDocument expectedSnapshot = new MockDocument();

            fakeTextEditor.MockDocument.SetSnapshot(expectedSnapshot);

            ITextBuffer snapshot = xmlFoldingManager.CreateTextEditorSnapshot();

            Assert.AreEqual(expectedSnapshot, snapshot);
        }
コード例 #10
0
        public void UpdateFolds_XmlFoldParserReturnsNullFromGetFolds_FoldingManagerFoldsAreNotUpdated()
        {
            CreateXmlFoldingManager();

            MockDocument expectedSnapshot = new MockDocument();

            fakeTextEditor.MockDocument.SetSnapshot(expectedSnapshot);
            fakeXmlFoldParser.Folds = null;

            xmlFoldingManager.UpdateFolds();

            bool result = fakeFoldingManager.IsUpdateFoldingsCalled;

            Assert.IsFalse(result);
        }
        public void SetUp()
        {
            // Create the document to be iterated through.
            MockDocument doc = new MockDocument();

            doc.Text = "bar";

            // Create a doc info with an initial end offset right
            // at the end of the text.
            ProvidedDocumentInformation docInfo = new ProvidedDocumentInformation(doc,
                                                                                  @"C:\Temp\test.txt",
                                                                                  doc.TextLength);

            // Create the forward iterator.
            forwardTextIterator = new ForwardTextIterator(docInfo);
        }
コード例 #12
0
        public void GetFolds_FakeXmlFoldParserUsed_ReturnsFoldsFromFakeXmlFoldParser()
        {
            CreateXmlFoldingManager();
            FoldingRegion fold = CreateFoldingRegion();

            fakeXmlFoldParser.Folds.Add(fold);

            MockDocument expectedSnapshot = new MockDocument();

            fakeTextEditor.MockDocument.SetSnapshot(expectedSnapshot);

            ITextBuffer snapshot = xmlFoldingManager.CreateTextEditorSnapshot();

            IList <FoldingRegion> folds = xmlFoldingManager.GetFolds(snapshot);

            Assert.AreEqual(fakeXmlFoldParser.Folds, folds);
        }
コード例 #13
0
        public void UpdateFolds_NoParameterPassedToMethod_SnapshotPassedToXmlFoldParser()
        {
            CreateXmlFoldingManager();
            AddDocumentPositionToOffsetReturnValue(5);
            AddDocumentPositionToOffsetReturnValue(10);

            MockDocument expectedSnapshot = new MockDocument();

            fakeTextEditor.MockDocument.SetSnapshot(expectedSnapshot);

            FoldingRegion fold = CreateTestFoldingRegion();

            fakeXmlFoldParser.Folds.Add(fold);

            xmlFoldingManager.UpdateFolds();

            Assert.AreEqual(expectedSnapshot, fakeXmlFoldParser.TextBufferPassedToGetFolds);
        }
コード例 #14
0
        public void SetUp()
        {
            // Set up SearchOptions required by the BruteForceSearchStrategy.
            SearchOptions.CurrentFindPattern = "foo";
            SearchOptions.MatchCase          = false;
            SearchOptions.MatchWholeWord     = false;

            // Create the document to be searched.
            MockDocument doc = new MockDocument();

            doc.Text = "foo";

            // Create a doc info with an initial end offset right
            // at the end of the text.
            ProvidedDocumentInformation docInfo = new ProvidedDocumentInformation(doc, @"C:\Temp\test.txt", doc.TextLength);

            // Search the document.
//			result = SearchManager.FindNext(SearchOptions.CurrentFindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchMode.Normal,
//			);
        }
コード例 #15
0
        public async Task Create_ShouldReturnOk_WhenAddedNewCustomer()
        {
            // Arrange
            var newCustomer = new MockDocument()
            {
                Address     = "Address",
                City        = "City",
                Phone       = "Phone",
                CompanyName = "CompanyName",
                ContactName = "ContactName",
                Country     = "Country",
                PostalCode  = "PostalCode",
                Region      = "Region"
            };

            //Act
            var savedCustomer = await controller.Post(newCustomer);

            //Assert
            Assert.NotNull(savedCustomer.Result);
        }
コード例 #16
0
        public void UpdateFolds_NoParameterPassedToMethod_FakeXmlFoldParserFoldsUsedToUpdateFakeFoldingManager()
        {
            CreateXmlFoldingManager();
            AddDocumentPositionToOffsetReturnValue(5);
            AddDocumentPositionToOffsetReturnValue(10);

            MockDocument expectedSnapshot = new MockDocument();

            fakeTextEditor.MockDocument.SetSnapshot(expectedSnapshot);

            FoldingRegion fold = CreateTestFoldingRegion();

            fakeXmlFoldParser.Folds.Add(fold);

            xmlFoldingManager.UpdateFolds();

            IList <NewFolding> newFolds = fakeFoldingManager.NewFoldsPassedToUpdateFoldings;

            List <NewFolding> expectedFolds = CreateTestNewFoldingList();

            NewFoldingHelper.AssertAreEqual(expectedFolds, newFolds);
        }
コード例 #17
0
        public void OneNodeMarked()
        {
            string xml = "<root><foo/></root>";

            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//root");

            IDocument doc = MockDocument.Create();

            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);

            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List <TextMarker> markers = new List <TextMarker>();

            foreach (TextMarker marker in markerStrategy.TextMarker)
            {
                markers.Add(marker);
            }

            // Remove markers.
            XPathNodeTextMarker.RemoveMarkers(markerStrategy);
            List <TextMarker> markersAfterRemove = new List <TextMarker>();

            foreach (TextMarker markerAfterRemove in markerStrategy.TextMarker)
            {
                markers.Add(markerAfterRemove);
            }

            XPathNodeTextMarker xpathNodeTextMarker = (XPathNodeTextMarker)markers[0];

            Assert.AreEqual(1, markers.Count);
            Assert.AreEqual(1, xpathNodeTextMarker.Offset);
            Assert.AreEqual(4, xpathNodeTextMarker.Length);
            Assert.AreEqual(TextMarkerType.SolidBlock, xpathNodeTextMarker.TextMarkerType);
            Assert.AreEqual(0, markersAfterRemove.Count);
            Assert.AreEqual(XPathNodeTextMarker.MarkerBackColor, xpathNodeTextMarker.Color);
        }
コード例 #18
0
        public void NamespaceQuery()
        {
            string xml = "<?xml version='1.0'?>\r\n" +
                         "<Xml1></Xml1>";

            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//namespace::*");

            IDocument doc = MockDocument.Create();

            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);

            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List <TextMarker> markers = new List <TextMarker>();

            foreach (TextMarker marker in markerStrategy.TextMarker)
            {
                markers.Add(marker);
            }
            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
コード例 #19
0
        public void EmptyCommentNode()
        {
            string xml = "<!----><root/>";

            XPathNodeMatch[] nodes = XmlView.SelectNodes(xml, "//comment()");

            IDocument doc = MockDocument.Create();

            doc.TextContent = xml;
            MarkerStrategy markerStrategy = new MarkerStrategy(doc);

            XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);

            List <TextMarker> markers = new List <TextMarker>();

            foreach (TextMarker marker in markerStrategy.TextMarker)
            {
                markers.Add(marker);
            }

            Assert.AreEqual(0, markers.Count);
            Assert.AreEqual(1, nodes.Length);
        }
コード例 #20
0
        public async Task LoadTest_MessagesReceivedInCorrectOrder()
        {
            // arrange
            CancellationToken ct = new CancellationTokenSource(20_000).Token;

            using IWebHost host = TestServerHelper
                                  .CreateServer(
                      x => x.AddTypeExtension <StringSubscriptionExtensions>(),
                      out var port);

            ServiceCollection serviceCollection = new();

            serviceCollection
            .AddProtocol <GraphQLWebSocketProtocolFactory>();


            for (var i = 0; i < 10; i++)
            {
                serviceCollection.AddWebSocketClient(
                    "Foo" + i,
                    c => c.Uri = new Uri("ws://localhost:" + port + "/graphql"));
            }

            IServiceProvider services = serviceCollection.BuildServiceProvider();

            ISessionPool sessionPool = services.GetRequiredService <ISessionPool>();

            var globalCounter = 0;

            async Task?CreateSubscription(int client, int id)
            {
                var connection =
                    new WebSocketConnection(async ct =>
                                            await sessionPool.CreateAsync("Foo" + client, ct));
                var document =
                    new MockDocument($"subscription Test {{ countUp }}");
                var request = new OperationRequest("Test", document);
                var counter = 0;

                await foreach (var response in connection.ExecuteAsync(request, ct))
                {
                    if (response.Body is not null)
                    {
                        Interlocked.Increment(ref globalCounter);
                        var received = response.Body.RootElement
                                       .GetProperty("data")
                                       .GetProperty("countUp")
                                       .GetInt32();

                        if (counter != received)
                        {
                            throw new InvalidOperationException();
                        }

                        counter++;
                    }
                }
            }

            // act
            var list = new List <Task>();

            for (var i = 0; i < 10; i++)
            {
                for (var j = 0; j < 10; j++)
                {
                    list.Add(CreateSubscription(i, j));
                }
            }

            await Task.WhenAll(list);

            // assert
            Assert.Equal(10000, globalCounter);
        }
コード例 #21
0
        public async Task Parallel_Request_SameSocket()
        {
            Snapshot.FullName();

            await TryTest(async ct =>
            {
                // arrange
                using IWebHost host = TestServerHelper
                                      .CreateServer(
                          x => x.AddTypeExtension <StringSubscriptionExtensions>(),
                          out var port);

                ServiceCollection serviceCollection = new();
                serviceCollection
                .AddProtocol <GraphQLWebSocketProtocolFactory>()
                .AddWebSocketClient(
                    "Foo",
                    c => c.Uri            = new Uri("ws://localhost:" + port + "/graphql"));
                IServiceProvider services = serviceCollection.BuildServiceProvider();

                ISessionPool sessionPool = services.GetRequiredService <ISessionPool>();
                ConcurrentDictionary <int, List <JsonDocument> > results = new();

                async Task CreateSubscription(int id)
                {
                    var connection = new WebSocketConnection(
                        async cancellationToken =>
                        await sessionPool.CreateAsync("Foo", cancellationToken));
                    var document = new MockDocument(
                        $"subscription Test {{ onTest(id:{id.ToString()}) }}");
                    var request = new OperationRequest("Test", document);
                    await foreach (var response in connection.ExecuteAsync(request, ct))
                    {
                        if (response.Body is not null)
                        {
                            results.AddOrUpdate(id,
                                                _ => new List <JsonDocument> {
                                response.Body
                            },
                                                (_, l) =>
                            {
                                l.Add(response.Body);
                                return(l);
                            });
                        }
                    }
                }

                // act
                var list = new List <Task>();
                for (var i = 0; i < 15; i++)
                {
                    list.Add(CreateSubscription(i));
                }

                await Task.WhenAll(list);

                // assert
                var str = "";
                foreach (KeyValuePair <int, List <JsonDocument> > sub in results.OrderBy(x => x.Key))
                {
                    JsonDocument[] jsonDocuments = sub.Value.ToArray();

                    str += "Operation " + sub.Key + "\n";
                    for (var index = 0; index < jsonDocuments.Length; index++)
                    {
                        str += "Operation " + jsonDocuments[index].RootElement + "\n";
                    }
                }

                str.MatchSnapshot();
            });
        }
コード例 #22
0
 public void Init()
 {
     document = new MockDocument();
 }