public void TestCodeCompletionMidStatement()
        {
            // Test inserting "FILTER(" between F and VALUES(
            var testLine = "CALCULATE( FVALUES([MyColumn])";
            var mockIp   = new Mock <IInsightProvider> ();

            mockIp.Setup(ip => ip.ShowInsight("FILTER"));
            var compData = new DaxCompletionData(mockIp.Object, "FILTER(«Table", 1.0);

            var mockDocLine      = new Mock <IDocumentLine>();
            var mockTextLocation = new TextLocation(0, 12);

            mockDocLine.SetupGet(dl => dl.Length).Returns(testLine.Length);

            var mockDoc = new Mock <IDocument>();

            mockDoc.SetupProperty(d => d.Text, testLine);
            mockDoc.Setup(d => d.GetLineByOffset(12)).Returns(mockDocLine.Object);
            mockDoc.Setup(d => d.GetLocation(12)).Returns(mockTextLocation);
            mockDoc.Setup(d => d.GetText(0, testLine.Length)).Returns(testLine);
            mockDoc.Setup(d => d.TextLength).Returns(testLine.Length);

            mockDoc.Setup(d => d.Replace(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
            .Callback((int offset, int length, string src) => {
                var start           = mockDoc.Object.Text.Substring(0, offset);
                var end             = mockDoc.Object.Text.Substring(offset + length);
                mockDoc.Object.Text = start + src + end;
            })
            .Verifiable();
            var mockSegment = new Mock <ISegment>();

            mockSegment.SetupGet(s => s.EndOffset).Returns(13);
            mockSegment.SetupGet(s => s.Length).Returns(0);

            IDocument doc = mockDoc.Object;
            ISegment  seg = mockSegment.Object;
            var       e   = new TextCompositionEventArgs(Keyboard.PrimaryDevice, new TextComposition(null, null, "I"));

            compData.CompleteInternal(doc, seg, e);

            Assert.AreEqual("CALCULATE( FILTER(VALUES([MyColumn])", doc.Text);
        }
        public void TestCodeCompletionWithUnderscoresInName()
        {
            var testLine = "EVALUATE DIM_D";
            var mockIp   = new Mock <IInsightProvider>();

            mockIp.Setup(ip => ip.ShowInsight("FILTER"));
            var compData = new DaxCompletionData(mockIp.Object, "Dim_Date", 1.0);

            var mockDocLine      = new Mock <IDocumentLine>();
            var mockTextLocation = new TextLocation(0, testLine.Length);

            mockDocLine.SetupGet(dl => dl.Length).Returns(testLine.Length);

            var mockDoc = new Mock <IDocument>();

            mockDoc.SetupProperty(d => d.Text, testLine);
            //mockDoc.Object.Text = testLine;
            mockDoc.Setup(d => d.GetLineByOffset(testLine.Length - 1)).Returns(mockDocLine.Object);
            mockDoc.Setup(d => d.GetLocation(testLine.Length - 1)).Returns(mockTextLocation);
            mockDoc.Setup(d => d.GetText(0, testLine.Length)).Returns(testLine);
            mockDoc.Setup(d => d.TextLength).Returns(testLine.Length);

            mockDoc.Setup(d => d.Replace(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
            .Callback((int offset, int length, string src) => {
                var start           = mockDoc.Object.Text.Substring(0, offset);
                var end             = mockDoc.Object.Text.Substring(offset + length);
                mockDoc.Object.Text = start + src + end;
            })
            .Verifiable();
            var mockSegment = new Mock <ISegment>();

            mockSegment.SetupGet(s => s.EndOffset).Returns(testLine.Length);

            var       e   = new TextCompositionEventArgs(Keyboard.PrimaryDevice, new TextComposition(null, null, "a"));
            IDocument doc = mockDoc.Object;
            ISegment  seg = mockSegment.Object;

            compData.CompleteInternal(doc, seg, e);

            Assert.AreEqual("EVALUATE Dim_Date", doc.Text);
        }
Beispiel #3
0
        public void TestCodeCompletion()
        {
            var testLine = "CALCULATE VALUES([MyColumn])";
            var mockIp   = new Mock <IInsightProvider> ();

            mockIp.Setup(ip => ip.ShowInsight("FILTER"));
            var compData = new DaxCompletionData(mockIp.Object, "FILTER", 1.0);

            var mockDocLine = new Mock <IDocumentLine>();

            mockDocLine.SetupGet(dl => dl.Offset).Returns(0);
            mockDocLine.SetupGet(dl => dl.Length).Returns(testLine.Length);

            var mockDoc = new Mock <IDocument>();

            mockDoc.SetupProperty(d => d.Text, testLine);
            mockDoc.Setup(d => d.GetLineByOffset(10)).Returns(mockDocLine.Object);
            mockDoc.Setup(d => d.GetText(0, testLine.Length));
            mockDoc.Setup(d => d.GetText(0, 28)).Returns(testLine.Substring(10));
            mockDoc.Setup(d => d.Replace(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <ITextSource>()))
            .Callback((int offset, int length, ITextSource src) => {
                var start           = src.Text.Substring(0, offset);
                var end             = src.Text.Substring(offset + length);
                mockDoc.Object.Text = start + src.Text + end;
            })
            .Verifiable();
            var mockSegment = new Mock <ISegment>();

            mockSegment.SetupGet(s => s.EndOffset).Returns(11);

            var e = new TextCompositionEventArgs(Keyboard.PrimaryDevice, new TextComposition(null, null, "F"));

            compData.CompleteInternal(mockDoc.Object, mockSegment.Object, e);
            IDocument doc = mockDoc.Object;

            Assert.AreEqual("CALCULATE FILTER(VALUES([MyColumn])", doc.Text);
        }