|
11 | 11 | using NUnit.Framework; |
12 | 12 | using System; |
13 | 13 | using System.Collections.Generic; |
14 | | -using System.Diagnostics; |
15 | 14 | using System.Linq; |
16 | 15 | using System.Threading; |
17 | 16 |
|
@@ -77,6 +76,27 @@ public void Should_Create_Tracked_Lines_From_Existing_Coverage() |
77 | 76 | autoMoqer.Verify<ITrackedLinesFactory>(trackedLinesFactory => trackedLinesFactory.Create(lines, textSnapshot, "filepath")); |
78 | 77 | } |
79 | 78 |
|
| 79 | + [Test] |
| 80 | + public void Should_Log_If_Exception_Creating_Tracked_Lines() |
| 81 | + { |
| 82 | + var exception = new Exception("exception"); |
| 83 | + |
| 84 | + SimpleTextInfoSetUp(false, "CSharp"); |
| 85 | + |
| 86 | + var mockTrackedLinesFactory = autoMoqer.GetMock<ITrackedLinesFactory>(); |
| 87 | + mockTrackedLinesFactory.Setup( |
| 88 | + trackedLinesFactory => trackedLinesFactory.Create( |
| 89 | + It.IsAny<List<ILine>>(), |
| 90 | + It.IsAny<ITextSnapshot>(), |
| 91 | + It.IsAny<string>()) |
| 92 | + ).Throws(exception); |
| 93 | + |
| 94 | + var bufferLineCoverage = autoMoqer.Create<BufferLineCoverage>(); |
| 95 | + |
| 96 | + autoMoqer.Verify<ILogger>(logger => logger.Log("Error creating tracked lines for filepath", exception)); |
| 97 | + |
| 98 | + } |
| 99 | + |
80 | 100 | [Test] |
81 | 101 | public void Should_Not_Create_TrackedLines_If_EditorCoverageColouringMode_Is_Off() |
82 | 102 | { |
@@ -167,12 +187,63 @@ void RaiseTestExecutionStartingMessage() |
167 | 187 | Times.Exactly(expectCoverageChangedMessage ? 1 : 0)); |
168 | 188 | } |
169 | 189 |
|
| 190 | + [Test] |
| 191 | + public void Should_Log_When_Text_Changed_Since_TestExecutionStartingMessage() |
| 192 | + { |
| 193 | + var autoMoqer = new AutoMoqer(); |
| 194 | + var mockTextView = new Mock<ITextView>(); |
| 195 | + var mockTextBuffer = new Mock<ITextBuffer2>(); |
| 196 | + var textSnapshot = new Mock<ITextSnapshot>().Object; |
| 197 | + mockTextBuffer.Setup(textBuffer => textBuffer.CurrentSnapshot).Returns(textSnapshot); |
| 198 | + var mockTextInfo = new Mock<ITextInfo>(); |
| 199 | + mockTextInfo.SetupGet(textInfo => textInfo.TextBuffer).Returns(mockTextBuffer.Object); |
| 200 | + mockTextInfo.SetupGet(textInfo => textInfo.TextView).Returns(mockTextView.Object); |
| 201 | + mockTextInfo.SetupGet(textInfo => textInfo.FilePath).Returns("filepath"); |
| 202 | + autoMoqer.SetInstance(mockTextInfo.Object); |
| 203 | + |
| 204 | + var mockAppOptionsProvider = autoMoqer.GetMock<IAppOptionsProvider>(); |
| 205 | + var firstMockAppOptions = new Mock<IAppOptions>(); |
| 206 | + firstMockAppOptions.SetupGet(appOptions => appOptions.EditorCoverageColouringMode).Returns(EditorCoverageColouringMode.Off); |
| 207 | + var secondAppOptions = new Mock<IAppOptions>(); |
| 208 | + secondAppOptions.SetupGet(appOptions => appOptions.EditorCoverageColouringMode).Returns(EditorCoverageColouringMode.UseRoslynWhenTextChanges); |
| 209 | + mockAppOptionsProvider.SetupSequence(appOptionsProvider => appOptionsProvider.Get()) |
| 210 | + .Returns(firstMockAppOptions.Object).Returns(secondAppOptions.Object); |
| 211 | + |
| 212 | + var mockTrackedLinesFactory = autoMoqer.GetMock<ITrackedLinesFactory>(); |
| 213 | + var mockTrackedLines = new Mock<ITrackedLines>(); |
| 214 | + mockTrackedLines.Setup(trackedLines => trackedLines.GetLines(0, 10)).Returns(new List<IDynamicLine> { new Mock<IDynamicLine>().Object }); |
| 215 | + mockTrackedLinesFactory.Setup(trackedLinesFactory => trackedLinesFactory.Create(It.IsAny<List<ILine>>(), textSnapshot, "filepath")) |
| 216 | + .Returns(mockTrackedLines.Object); |
| 217 | + |
| 218 | + |
| 219 | + var bufferLineCoverage = autoMoqer.Create<BufferLineCoverage>(); |
| 220 | + void RaiseChangedOnBackground() |
| 221 | + { |
| 222 | + mockTextBuffer.Raise(textBuffer => textBuffer.ChangedOnBackground += null, new TextContentChangedEventArgs(new Mock<ITextSnapshot>().Object, new Mock<ITextSnapshot>().Object, new EditOptions(), null)); |
| 223 | + } |
| 224 | + void RaiseTestExecutionStartingMessage() |
| 225 | + { |
| 226 | + (bufferLineCoverage as IListener<TestExecutionStartingMessage>).Handle(new TestExecutionStartingMessage()); |
| 227 | + } |
| 228 | + |
| 229 | + |
| 230 | + |
| 231 | + RaiseTestExecutionStartingMessage(); |
| 232 | + Thread.Sleep(1); |
| 233 | + RaiseChangedOnBackground(); |
| 234 | + |
| 235 | + bufferLineCoverage.Handle(new NewCoverageLinesMessage { CoverageLines = new Mock<IFileLineCoverage>().Object }); |
| 236 | + |
| 237 | + autoMoqer.Verify<ILogger>(ILogger => ILogger.Log("Not creating editor marks for filepath as it was changed after test execution started")); |
| 238 | + |
| 239 | + } |
| 240 | + |
170 | 241 | [Test] |
171 | 242 | public void Should_Not_Throw_If_No_Initial_Coverage() |
172 | 243 | { |
173 | 244 | SimpleTextInfoSetUp(); |
174 | 245 |
|
175 | | - new BufferLineCoverage(null, textInfo, new Mock<IEventAggregator>().Object, null, null,new Mock<IAppOptionsProvider>().Object); |
| 246 | + new BufferLineCoverage(null, textInfo, new Mock<IEventAggregator>().Object, null, null,new Mock<IAppOptionsProvider>().Object,null); |
176 | 247 | } |
177 | 248 |
|
178 | 249 | [Test] |
@@ -330,6 +401,31 @@ public void Should_Update_TrackedLines_When_Text_Buffer_ChangedOnBackground(bool |
330 | 401 |
|
331 | 402 | } |
332 | 403 |
|
| 404 | + [Test] |
| 405 | + public void Should_Log_When_Exception_Updating_TrackedLines_When_Text_Buffer_ChangedOnBackground() |
| 406 | + { |
| 407 | + SimpleTextInfoSetUp(); |
| 408 | + |
| 409 | + var mockAfterSnapshot = new Mock<ITextSnapshot>(); |
| 410 | + mockAfterSnapshot.SetupGet(textSnapshot => textSnapshot.LineCount).Returns(100); |
| 411 | + |
| 412 | + var newSpan = new Span(1, 2); |
| 413 | + var mockTrackedLines = new Mock<ITrackedLines>(); |
| 414 | + var changedLineNumbers = new List<int> { 11, 12 }; |
| 415 | + var exception = new Exception("message"); |
| 416 | + mockTrackedLines.Setup(trackedLines => trackedLines.GetChangedLineNumbers(mockAfterSnapshot.Object, new List<Span> { newSpan })) |
| 417 | + .Throws(exception); |
| 418 | + autoMoqer.Setup<ITrackedLinesFactory, ITrackedLines>(trackedLinesFactory => trackedLinesFactory.Create(It.IsAny<List<ILine>>(), It.IsAny<ITextSnapshot>(), It.IsAny<string>())) |
| 419 | + .Returns(mockTrackedLines.Object); |
| 420 | + |
| 421 | + |
| 422 | + var bufferLineCoverage = autoMoqer.Create<BufferLineCoverage>(); |
| 423 | + |
| 424 | + mockTextBuffer.Raise(textBuffer => textBuffer.ChangedOnBackground += null, CreateTextContentChangedEventArgs(mockAfterSnapshot.Object, newSpan)); |
| 425 | + |
| 426 | + autoMoqer.Verify<ILogger>(logger => logger.Log("Error updating tracked lines for filepath", exception)); |
| 427 | + } |
| 428 | + |
333 | 429 | [Test] |
334 | 430 | public void Should_Not_Throw_When_Text_Buffer_Changed_And_No_Coverage() |
335 | 431 | { |
|
0 commit comments