Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add toggle functionality #433

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMoq;
using FineCodeCoverage.Core.Utilities;
using FineCodeCoverage.Editor.IndicatorVisibility;
using FineCodeCoverage.Output;
using FineCodeCoverageTests.Test_helpers;
using Moq;
using NUnit.Framework;

namespace FineCodeCoverageTests.Editor.IndicatorVisibility
{
internal class FileIndicatorVisibility_Tests
{
[Test]
public void SHould_Export_As_Initializable()
{
ExportsInitializable.Should_Export_IInitializable(typeof(FileIndicatorVisibility));
}

[Test]
public void Should_Add_Itself_As_EventAggregator_Listener()
{
var mockEventAggregator = new Mock<IEventAggregator>();

var fileIndicatorVisibility = new FileIndicatorVisibility(mockEventAggregator.Object);

mockEventAggregator.Verify(eventAggregator => eventAggregator.AddListener(fileIndicatorVisibility,null), Times.Once());
}

[Test]
public void Should_Toggle_IsVisible_And_Raise_VisibilityChanged_When_Handle_ToggleCoverageIndicatorsMessage()
{
var fileIndicatorVisibility = new AutoMoqer().Create<FileIndicatorVisibility>();
var visibilityChangedCount = 0;
fileIndicatorVisibility.VisibilityChanged += (sender, args) => {
visibilityChangedCount++;
};
Assert.True(fileIndicatorVisibility.IsVisible(""));
fileIndicatorVisibility.Handle(new ToggleCoverageIndicatorsMessage());
Assert.False(fileIndicatorVisibility.IsVisible(""));
Assert.AreEqual(1, visibilityChangedCount);
fileIndicatorVisibility.Handle(new ToggleCoverageIndicatorsMessage());
Assert.True(fileIndicatorVisibility.IsVisible(""));
Assert.AreEqual(2, visibilityChangedCount);

}
}
}
75 changes: 71 additions & 4 deletions FineCodeCoverageTests/Editor/Tagging/Base/CoverageTagger_Tests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutoMoq;
using FineCodeCoverage.Core.Utilities;
using FineCodeCoverage.Editor.DynamicCoverage;
using FineCodeCoverage.Editor.IndicatorVisibility;
using FineCodeCoverage.Editor.Tagging.Base;
using FineCodeCoverage.Engine.Model;
using FineCodeCoverageTests.Editor.Tagging.Base.Types;
Expand All @@ -11,6 +12,7 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using LineSpan = FineCodeCoverageTests.Editor.Tagging.Types.LineSpan;

namespace FineCodeCoverageTests.Editor.Tagging.Base
Expand Down Expand Up @@ -122,7 +124,8 @@ public void Should_HasCoverage_When_Has(bool hasCoverage)
new Mock<ICoverageTypeFilter>().Object,
new Mock<IEventAggregator>().Object,
new Mock<ILineSpanLogic>(MockBehavior.Strict).Object,
new Mock<ILineSpanTagger<DummyTag>>().Object
new Mock<ILineSpanTagger<DummyTag>>().Object,
new Mock<IFileIndicatorVisibility>().Object
);

Assert.That(coverageTagger.HasCoverage, Is.EqualTo(hasCoverage));
Expand Down Expand Up @@ -161,7 +164,8 @@ public void Should_Not_Raise_TagsChanged_For_CoverageTypeFilterChangedMessage_If
new DummyCoverageTypeFilter(),
new Mock<IEventAggregator>().Object,
new Mock<ILineSpanLogic>(MockBehavior.Strict).Object,
new Mock<ILineSpanTagger<DummyTag>>().Object
new Mock<ILineSpanTagger<DummyTag>>().Object,
new Mock<IFileIndicatorVisibility>().Object
);

var tagsChanged = false;
Expand All @@ -185,7 +189,8 @@ public void Should_Return_No_Tags_If_No_Coverage_Lines()
new Mock<ICoverageTypeFilter>().Object,
new Mock<IEventAggregator>().Object,
new Mock<ILineSpanLogic>(MockBehavior.Strict).Object,
new Mock<ILineSpanTagger<DummyTag>>().Object
new Mock<ILineSpanTagger<DummyTag>>().Object,
new Mock<IFileIndicatorVisibility>().Object
);

var tags = coverageTagger.GetTags(new NormalizedSnapshotSpanCollection());
Expand Down Expand Up @@ -219,7 +224,7 @@ public void Should_GetLineSpans_From_LineSpanLogic_For_The_Spans_When_Coverage_A
mockTextSnapshot.SetupGet(currentSnapshot => currentSnapshot.Length).Returns(10);
mockTextInfo.SetupGet(textBufferAndFile => textBufferAndFile.TextBuffer.CurrentSnapshot).Returns(mockTextSnapshot.Object);
mockTextInfo.SetupGet(textBufferWithFilePath => textBufferWithFilePath.FilePath).Returns("filepath");

autoMoqer.Setup<IFileIndicatorVisibility,bool>(fileIndicatorVisibility => fileIndicatorVisibility.IsVisible(It.IsAny<string>())).Returns(true);
var coverageTagger = autoMoqer.Create<CoverageTagger<DummyTag>>();
var spans = new NormalizedSnapshotSpanCollection();

Expand Down Expand Up @@ -270,6 +275,8 @@ public void Should_GetTagsSpans_For_Filtered_LineSpans()
)
.Returns(lineSpans);

autoMoqer.Setup<ITextInfo,string>(textInfo => textInfo.FilePath).Returns("filepath");
autoMoqer.Setup<IFileIndicatorVisibility, bool>(fileIndicatorVisibility => fileIndicatorVisibility.IsVisible("filepath")).Returns(true);
var coverageTagger = autoMoqer.Create<CoverageTagger<DummyTag>>();

var tags = coverageTagger.GetTags(new NormalizedSnapshotSpanCollection());
Expand All @@ -285,5 +292,65 @@ IDynamicLine CreateLine(DynamicCoverageType coverageType)
}

}

[TestCase(true,false)]
[TestCase(false, true)]
public void Should_Raise_TagsChanged_When_FileIndicatorVisibility_Toggled(bool newVisibility,bool expectedTagsChanged)
{
var autoMoqer = new AutoMoqer();
var mockTextBuffer = new Mock<ITextBuffer2>();
var mockSnapshot = new Mock<ITextSnapshot>();
mockSnapshot.SetupGet(textSnapshot => textSnapshot.Length).Returns(10);
mockTextBuffer.SetupGet(textBuffer => textBuffer.CurrentSnapshot).Returns(mockSnapshot.Object);
autoMoqer.Setup<ITextInfo,string>(textInfo => textInfo.FilePath).Returns("filepath");
autoMoqer.Setup<ITextInfo,ITextBuffer>(textInfo => textInfo.TextBuffer).Returns(mockTextBuffer.Object);
var mockFileIndicatorVisibility = autoMoqer.GetMock<IFileIndicatorVisibility>();
mockFileIndicatorVisibility.SetupSequence(fileIndicatorVisibility => fileIndicatorVisibility.IsVisible("filepath"))
.Returns(true)
.Returns(newVisibility);
var coverageTagger = autoMoqer.Create<CoverageTagger<DummyTag>>();
var tagsChanged = false;
coverageTagger.TagsChanged += (sender, args) =>
{
tagsChanged = true;
};
mockFileIndicatorVisibility.Raise(fileIndicatorVisibility => fileIndicatorVisibility.VisibilityChanged += null, EventArgs.Empty);

Assert.That(tagsChanged, Is.EqualTo(expectedTagsChanged));
}

[TestCase(true)]
[TestCase(false)]
public void Should_Have_No_Tags_When_FileIndicatorVisibility_Is_Initially_False(bool initiallyVisible)
{
var autoMoqer = new AutoMoqer();
autoMoqer.Setup<ICoverageTypeFilter, bool>(coverageTypeFilter => coverageTypeFilter.Show(DynamicCoverageType.Covered)).Returns(true);
var mockLineSpan = new Mock<ILineSpan>();
mockLineSpan.SetupGet(lineSpan => lineSpan.Line.CoverageType).Returns(DynamicCoverageType.Covered);
autoMoqer.Setup<ILineSpanLogic, IEnumerable<ILineSpan>>(lineSpanLogic =>
lineSpanLogic.GetLineSpans(It.IsAny<IBufferLineCoverage>(), It.IsAny<NormalizedSnapshotSpanCollection>())
).Returns(new List<ILineSpan> { mockLineSpan.Object });

var mockFileIndicatorVisibility = autoMoqer.GetMock<IFileIndicatorVisibility>();
mockFileIndicatorVisibility.Setup(fileIndicatorVisibility => fileIndicatorVisibility.IsVisible(It.IsAny<string>()))
.Returns(initiallyVisible);
var coverageTagger = autoMoqer.Create<CoverageTagger<DummyTag>>();

var tags = coverageTagger.GetTags(new NormalizedSnapshotSpanCollection()).ToList();

Assert.That(tags.Count, Is.EqualTo(initiallyVisible ? 1 : 0));
}

[Test]
public void Should_Remove_FileIndicatorVisibility_VisibilityChange_Handler_When_Dispose()
{
var autoMoqer = new AutoMoqer();
var mockFileIndicatorVisibility = autoMoqer.GetMock<IFileIndicatorVisibility>();

var coverageTagger = autoMoqer.Create<CoverageTagger<DummyTag>>();
coverageTagger.Dispose();

mockFileIndicatorVisibility.VerifyRemove(fileIndicatorVisibility => fileIndicatorVisibility.VisibilityChanged -= It.IsAny<EventHandler>());
}
}
}
1 change: 1 addition & 0 deletions FineCodeCoverageTests/FineCodeCoverageTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Compile Include="Editor\DynamicCoverage\TrackedNewCodeLine_Tests.cs" />
<Compile Include="Editor\DynamicCoverage\LineTracker_Tests.cs" />
<Compile Include="Editor\DynamicCoverage\TrackingSpanRangeUpdatingTracker_Tests.cs" />
<Compile Include="Editor\IndicatorVisibility\FileIndicatorVisibility_Tests.cs" />
<Compile Include="Editor\Management\CoverageClassificationTypeService_Tests.cs" />
<Compile Include="Editor\Management\CoverageFontAndColorsCategoryItemNames_Tests.cs" />
<Compile Include="Editor\Management\FontsAndColorsHelper_Tests.cs" />
Expand Down
Loading
Loading