Skip to content

Commit

Permalink
Beta expiration date bump. Modified File Browser to reset search when…
Browse files Browse the repository at this point in the history
… brought up against different solution. Modified Code Browser to reset search when brought up against different file.
  • Loading branch information
Sergey M committed Apr 1, 2020
1 parent 9e64c80 commit 1a72a8b
Show file tree
Hide file tree
Showing 21 changed files with 402 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
namespace DPackRx.Tests.CodeModel
{
/// <summary>
/// FileCodeModel tests.
/// <see cref="MemberCodeModel"/> tests.
/// </summary>
[TestFixture]
public class FileCodeModelTests
public class MemberCodeModelTests
{
#region Private Methods

/// <summary>
/// Returns test model instance.
/// </summary>
private FileCodeModel GetModel()
private MemberCodeModel GetModel()
{
return new FileCodeModel();
return new MemberCodeModel();
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion DPackRx.Tests/DPackRx.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CodeModel\FileModelTests.cs" />
<Compile Include="CodeModel\FileCodeModelTests.cs" />
<Compile Include="CodeModel\MemberCodeModelTests.cs" />
<Compile Include="Features\BookmarksFeatureTests.cs" />
<Compile Include="Features\BookmarksSimpleTaggerTests.cs" />
<Compile Include="Features\CodeBrowserFeatureTests.cs" />
Expand Down
34 changes: 26 additions & 8 deletions DPackRx.Tests/Features/CodeBrowserViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CodeBrowserViewModelTests
private Mock<ISearchMatchService> _searchMatchServiceMock;
private Mock<IShellSelectionService> _shellSelectionServiceMock;
private Mock<IShellImageService> _shellImageServiceMock;
private List<FileCodeModel> _members;
private List<MemberCodeModel> _members;

#endregion

Expand All @@ -49,17 +49,17 @@ public void Setup()

_optionsServiceMock = new Mock<IOptionsService>();

_members = new List<FileCodeModel>
_members = new List<MemberCodeModel>
{
new FileCodeModel { Name = "Test", FullName = "class1.Test", ElementKind = Kind.Method, Rank = 0, Matched = false },
new FileCodeModel { Name = "Hello", FullName = "class1.Hello", ElementKind = Kind.Method, Rank = 0, Matched = false },
new FileCodeModel { Name = "TestToo", FullName = "class1.TestToo", ElementKind = Kind.Property, Rank = 0, Matched = false },
new FileCodeModel { Name = "_somethingElse", FullName = "class1._somethingElse", ElementKind = Kind.Variable, Rank = 0, Matched = false },
new MemberCodeModel { Name = "Test", FullName = "class1.Test", ElementKind = Kind.Method, Rank = 0, Matched = false },
new MemberCodeModel { Name = "Hello", FullName = "class1.Hello", ElementKind = Kind.Method, Rank = 0, Matched = false },
new MemberCodeModel { Name = "TestToo", FullName = "class1.TestToo", ElementKind = Kind.Property, Rank = 0, Matched = false },
new MemberCodeModel { Name = "_somethingElse", FullName = "class1._somethingElse", ElementKind = Kind.Variable, Rank = 0, Matched = false },
};
_fileProcessorMock = new Mock<IFileProcessor>();
_fileProcessorMock
.Setup(p => p.GetMembers(ProcessorFlags.IncludeFileCodeModel, It.IsAny<CodeModelFilterFlags>()))
.Returns(_members)
.Returns(new FileCodeModel { FileName = "test", Members = _members })
.Verifiable();

_searchMatchServiceMock = new Mock<ISearchMatchService>();
Expand Down Expand Up @@ -125,6 +125,7 @@ public void OnInitialize(string search, CodeModelFilterFlags flags, int expected
else if (flags == CodeModelFilterFlags.ClassesInterfaces)
_members.Where(f => f.Matched && !((f.ElementKind == Kind.Class) || (f.ElementKind == Kind.Interface))).ForEach(f => f.Matched = false);

_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "File", string.Empty)).Returns("test").Verifiable();
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "Search", string.Empty)).Returns(search).Verifiable();
_optionsServiceMock.Setup(o => o.GetIntOption(viewModel.Feature, "Filter", (int)flags)).Returns((int)flags).Verifiable();
_optionsServiceMock.Setup(o => o.GetBoolOption(viewModel.Feature, "XmlDoc", false)).Returns(false).Verifiable();
Expand All @@ -137,12 +138,27 @@ public void OnInitialize(string search, CodeModelFilterFlags flags, int expected
Assert.That(viewModel.Search, Is.EqualTo(search));
Assert.That(viewModel.Filter, Is.EqualTo(flags));
_fileProcessorMock.Verify(p => p.GetMembers(ProcessorFlags.IncludeFileCodeModel, It.IsAny<CodeModelFilterFlags>()));
_optionsServiceMock.Verify(o => o.GetStringOption(viewModel.Feature, "File", string.Empty));
_optionsServiceMock.Verify(o => o.GetStringOption(viewModel.Feature, "Search", string.Empty));
_optionsServiceMock.Verify(o => o.GetIntOption(viewModel.Feature, "Filter", (int)flags));
_optionsServiceMock.Verify(o => o.GetBoolOption(viewModel.Feature, "XmlDoc", false));
_searchMatchServiceMock.Verify(s => s.MatchItems(search, It.IsAny<IEnumerable<IMatchItem>>()), Times.Once);
}

[Test]
public void OnInitialize_ResetSearch()
{
var viewModel = GetViewModel();

_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "File", string.Empty)).Returns("something else").Verifiable();
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "Search", string.Empty)).Returns("hello").Verifiable();

viewModel.OnInitialize(CodeModelFilterFlags.All);

Assert.That(viewModel.Search, Is.Null.Or.Empty, "Search should be reset on new file");
Assert.That(viewModel.FileName, Is.EqualTo("test"));
}

[Test]
public void OnInitialize_ErrorHandling()
{
Expand All @@ -157,6 +173,7 @@ public void OnClose(bool apply)
{
var viewModel = GetViewModel();

_optionsServiceMock.Setup(o => o.SetStringOption(viewModel.Feature, "File", string.Empty)).Verifiable();
_optionsServiceMock.Setup(o => o.SetStringOption(viewModel.Feature, "Search", string.Empty)).Verifiable();
_optionsServiceMock.Setup(o => o.SetIntOption(viewModel.Feature, "Filter", 0)).Verifiable();

Expand All @@ -166,6 +183,7 @@ public void OnClose(bool apply)

viewModel.OnClose(apply);

_optionsServiceMock.Verify(o => o.SetStringOption(viewModel.Feature, "File", string.Empty));
_optionsServiceMock.Verify(o => o.SetStringOption(viewModel.Feature, "Search", string.Empty));
_optionsServiceMock.Verify(o => o.SetIntOption(viewModel.Feature, "Filter", 0));
if (apply)
Expand Down Expand Up @@ -238,7 +256,7 @@ public void SelectMemberCommand_Execute()
{
var viewModel = GetViewModel();

var selection = new FileCodeModel();
var selection = new MemberCodeModel();
viewModel.SelectMemberCommand.Execute(selection);

Assert.That(viewModel.Selection, Is.EqualTo(selection));
Expand Down
21 changes: 20 additions & 1 deletion DPackRx.Tests/Features/FileBrowserViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Setup()
_solutionProcessorMock = new Mock<ISolutionProcessor>();
_solutionProcessorMock
.Setup(p => p.GetProjects(ProcessorFlags.IncludeFiles | ProcessorFlags.GroupLinkedFiles, CodeModelFilterFlags.All))
.Returns(new SolutionModel { Files = _files })
.Returns(new SolutionModel { SolutionName = "test", Files = _files })
.Verifiable();

_fileTypeResolverMock = new Mock<IFileTypeResolver>();
Expand Down Expand Up @@ -142,6 +142,7 @@ public void OnInitialize(string search, bool allFiles, string ignoreFiles, strin
else
_files.Where(f => f.FileName.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0).ForEach(f => f.Matched = true);

_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "Solution", string.Empty)).Returns("test").Verifiable();
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "Search", string.Empty)).Returns(search).Verifiable();
_optionsServiceMock.Setup(o => o.GetBoolOption(viewModel.Feature, "AllFiles", false)).Returns(allFiles).Verifiable();
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "IgnoreFiles", null)).Returns(ignoreFiles).Verifiable();
Expand All @@ -159,7 +160,9 @@ public void OnInitialize(string search, bool allFiles, string ignoreFiles, strin
Assert.That(viewModel.FilteredFiles.Count, Is.EqualTo(expectedCodeFileCount + expectedNoneCodeFileCount));
Assert.That(viewModel.Search, Is.EqualTo(search));
Assert.That(viewModel.AllFiles, Is.EqualTo(allFiles));
Assert.That(viewModel.SolutionName, Is.EqualTo("test"));
_solutionProcessorMock.Verify(p => p.GetProjects(ProcessorFlags.IncludeFiles | ProcessorFlags.GroupLinkedFiles, CodeModelFilterFlags.All));
_optionsServiceMock.Verify(o => o.GetStringOption(viewModel.Feature, "Solution", string.Empty), Times.Once);
_optionsServiceMock.Verify(o => o.GetStringOption(viewModel.Feature, "Search", string.Empty), Times.Once);
_optionsServiceMock.Verify(o => o.GetBoolOption(viewModel.Feature, "AllFiles", false), Times.Once);
_optionsServiceMock.Verify(o => o.GetStringOption(viewModel.Feature, "IgnoreFiles", null), Times.Once);
Expand All @@ -180,13 +183,28 @@ public void OnInitialize(string search, bool allFiles, string ignoreFiles, strin
_searchMatchServiceMock.Verify(s => s.MatchItems(search, It.IsAny<IEnumerable<IMatchItem>>()), Times.Once);
}

[Test]
public void OnInitialize_ResetSearch()
{
var viewModel = GetViewModel();

_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "Solution", string.Empty)).Returns("something else").Verifiable();
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "Search", string.Empty)).Returns("hello").Verifiable();

viewModel.OnInitialize(null);

Assert.That(viewModel.Search, Is.Null.Or.Empty, "Search should be reset on new solution");
Assert.That(viewModel.SolutionName, Is.EqualTo("test"));
}

[TestCase(true, true)]
[TestCase(true, false)]
[TestCase(false, true)]
public void OnClose(bool apply, bool selectCode)
{
var viewModel = GetViewModel();

_optionsServiceMock.Setup(o => o.SetStringOption(viewModel.Feature, "Solution", string.Empty)).Verifiable();
_optionsServiceMock.Setup(o => o.SetStringOption(viewModel.Feature, "Search", string.Empty)).Verifiable();
_optionsServiceMock.Setup(o => o.SetBoolOption(viewModel.Feature, "AllFiles", false)).Verifiable();

Expand All @@ -198,6 +216,7 @@ public void OnClose(bool apply, bool selectCode)

viewModel.OnClose(apply);

_optionsServiceMock.Verify(o => o.SetStringOption(viewModel.Feature, "Solution", string.Empty));
_optionsServiceMock.Verify(o => o.SetStringOption(viewModel.Feature, "Search", string.Empty));
_optionsServiceMock.Verify(o => o.SetBoolOption(viewModel.Feature, "AllFiles", false));
if (apply)
Expand Down
Loading

0 comments on commit 1a72a8b

Please sign in to comment.