Skip to content

Commit

Permalink
Merge pull request #60 from sergey-visual-studio/FileBrowserDups
Browse files Browse the repository at this point in the history
File Browser fixed and improvements
  • Loading branch information
sergey-visual-studio authored Dec 3, 2023
2 parents 64a7f1b + d11f7dc commit 5797b51
Show file tree
Hide file tree
Showing 12 changed files with 476 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ dotnet_style_prefer_compound_assignment = false:none
# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = none

# VSSpell001: spelling
dotnet_diagnostic.VSSpell001.severity = none

# define "Constants" symbols specifications
dotnet_naming_symbols.constants.applicable_kinds = field
dotnet_naming_symbols.constants.applicable_accessibilities = public,private,protected,internal,protected_internal,local
Expand Down
218 changes: 211 additions & 7 deletions DPackRx.Tests/Features/FileBrowserFeatureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Moq;
using NUnit.Framework;

using DPackRx.Features;
using DPackRx.CodeModel;
using DPackRx.Features.FileBrowser;
using DPackRx.Options;
using DPackRx.Package;
Expand All @@ -24,6 +24,7 @@ public class FileBrowserFeatureTests
private Mock<IOptionsService> _optionsServiceMock;
private Mock<IShellSelectionService> _shellSelectionServiceMock;
private Mock<IModalDialogService> _modalDialogServiceMock;
private Mock<IShellEventsService> _shellEventsServiceMock;

#endregion

Expand All @@ -36,13 +37,18 @@ public void Setup()

_logMock = new Mock<ILog>();
_logMock.Setup(l => l.LogMessage(It.IsAny<string>(), It.IsAny<string>())).Verifiable();
_logMock.Setup(l => l.LogMessage(It.IsAny<string>(), It.IsAny<Exception>(), It.IsAny<string>())).Verifiable();

_optionsServiceMock = new Mock<IOptionsService>();

_shellSelectionServiceMock = new Mock<IShellSelectionService>();
_shellSelectionServiceMock.Setup(s => s.IsContextActive(It.IsAny<ContextType>())).Returns(true).Verifiable();

_modalDialogServiceMock = new Mock<IModalDialogService>();

_shellEventsServiceMock = new Mock<IShellEventsService>();
_shellEventsServiceMock.Setup(s => s.SubscribeSolutionEvents(It.IsAny<ISolutionEvents>())).Verifiable();
_shellEventsServiceMock.Setup(s => s.UnsubscribeSolutionEvents(It.IsAny<ISolutionEvents>())).Verifiable();
}

[TearDown]
Expand All @@ -53,6 +59,7 @@ public void TearDown()
_optionsServiceMock = null;
_shellSelectionServiceMock = null;
_modalDialogServiceMock = null;
_shellEventsServiceMock = null;
}

#endregion
Expand All @@ -62,10 +69,10 @@ public void TearDown()
/// <summary>
/// Returns test feature instance.
/// </summary>
private IFeature GetFeature()
private FileBrowserFeature GetFeature()
{
return new FileBrowserFeature(_serviceProviderMock.Object, _logMock.Object, _optionsServiceMock.Object,
_shellSelectionServiceMock.Object, _modalDialogServiceMock.Object);
_shellSelectionServiceMock.Object, _modalDialogServiceMock.Object, _shellEventsServiceMock.Object);
}

#endregion
Expand All @@ -80,6 +87,7 @@ public void Initialize()
feature.Initialize();

Assert.That(feature.Initialized, Is.True);
_shellEventsServiceMock.Verify(s => s.SubscribeSolutionEvents(It.IsNotNull<ISolutionEvents>()), Times.Once);
}

[Test]
Expand Down Expand Up @@ -123,19 +131,24 @@ public void IsValidContext_NoContext()
}

[Test]
public void Execute()
public void Execute([Values] bool isCashed)
{
var feature = GetFeature();
var cache = new SolutionModel();
if (isCashed)
feature.Cache = cache;

_modalDialogServiceMock
.Setup(d => d.ShowDialog<FileBrowserWindow, FileBrowserViewModel>(It.IsNotNull<string>()))
.Returns(true)
.Setup(d => d.ShowDialog<FileBrowserWindow, FileBrowserViewModel, SolutionModel>(It.IsNotNull<string>(), It.IsAny<object>()))
.Returns(cache)
.Verifiable();

var result = feature.Execute(CommandIDs.FILE_BROWSER);

Assert.That(result, Is.True);
_modalDialogServiceMock.Verify(d => d.ShowDialog<FileBrowserWindow, FileBrowserViewModel>(It.IsNotNull<string>()));
Assert.That(feature.Cache, Is.Not.Null);
_modalDialogServiceMock.Verify(d => d.ShowDialog<FileBrowserWindow, FileBrowserViewModel, SolutionModel>(It.IsNotNull<string>(), It.IsAny<object>()));
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), null, It.IsNotNull<string>()), Times.Once);
}

[Test]
Expand All @@ -148,6 +161,197 @@ public void Execute_InvalidCommand()
Assert.That(result, Is.False);
}

[Test]
public void SolutionOpened()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

feature.Execute(0);
featureEvents.SolutionOpened(false);

Assert.That(feature.Cache, Is.Null);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()), Times.Once);
}

[Test]
public void SolutionClosing()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

Assert.DoesNotThrow(() => featureEvents.SolutionClosing());
}

[Test]
public void SolutionClosed()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

feature.Execute(0);
featureEvents.SolutionClosed();

Assert.That(feature.Cache, Is.Null);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()), Times.Once);
}

[Test]
public void SolutionSaved()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

Assert.DoesNotThrow(() => featureEvents.SolutionSaved());
}

[Test]
public void SolutionRenamed()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

Assert.DoesNotThrow(() => featureEvents.SolutionRenamed(null, null));
}

[Test]
public void ProjectAdded()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

feature.Execute(0);
featureEvents.ProjectAdded(null);

Assert.That(feature.Cache, Is.Null);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()), Times.Once);
}

[Test]
public void ProjectDeleted()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

feature.Execute(0);
featureEvents.ProjectDeleted(null);

Assert.That(feature.Cache, Is.Null);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()), Times.Once);
}

[Test]
public void ProjectRenamed()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

feature.Execute(0);
featureEvents.ProjectRenamed(null);

Assert.That(feature.Cache, Is.Null);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()), Times.Once);
}

[Test]
public void ProjectUnloaded()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

feature.Execute(0);
featureEvents.ProjectUnloaded(null);

Assert.That(feature.Cache, Is.Null);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()), Times.Once);
}

[Test]
public void FileAdded()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

feature.Execute(0);
featureEvents.FileAdded(null, null);

Assert.That(feature.Cache, Is.Null);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()), Times.Once);
}

[Test]
public void FileDeleted()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

feature.Execute(0);
featureEvents.FileDeleted(null, null);

Assert.That(feature.Cache, Is.Null);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()), Times.Once);
}

[Test]
public void FileRenamed()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

feature.Execute(0);
featureEvents.FileRenamed(null, null, null);

Assert.That(feature.Cache, Is.Null);
_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), It.IsNotNull<string>()), Times.Once);
}

[Test]
public void FileChanged()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

Assert.DoesNotThrow(() => featureEvents.FileChanged(null, null));
}

[Test]
public void FileOpened()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

Assert.DoesNotThrow(() => featureEvents.FileOpened(null, null));
}

[Test]
public void FileClosed()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

Assert.DoesNotThrow(() => featureEvents.FileClosed(null, null));
}

[Test]
public void FileSaved()
{
var feature = GetFeature();
var featureEvents = (ISolutionEvents)feature;

Assert.DoesNotThrow(() => featureEvents.FileSaved(null, null));
}

[Test]
public void Dispose()
{
var feature = GetFeature();

((IDisposable)feature).Dispose();

Assert.That(feature.Initialized, Is.False);
_shellEventsServiceMock.Verify(s => s.UnsubscribeSolutionEvents(It.IsNotNull<ISolutionEvents>()), Times.Once);
}

#endregion
}
}
21 changes: 20 additions & 1 deletion DPackRx.Tests/Features/FileBrowserViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void Setup()

_logMock = new Mock<ILog>();
_logMock.Setup(l => l.LogMessage(It.IsAny<string>(), It.IsAny<string>())).Verifiable();
_logMock.Setup(l => l.LogMessage(It.IsAny<string>(), It.IsAny<Exception>(), It.IsAny<string>())).Verifiable();

_messageServiceMock = new Mock<IMessageService>();

Expand Down Expand Up @@ -197,6 +198,19 @@ public void OnInitialize_ResetSearch()
Assert.That(viewModel.SolutionName, Is.EqualTo("test"));
}

[Test]
public void OnInitialize_SolutionModelCache()
{
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(new SolutionModel());

_logMock.Verify(l => l.LogMessage(It.IsNotNull<string>(), null, It.IsNotNull<string>()), Times.Exactly(3));
}

[TestCase(true, true)]
[TestCase(true, false)]
[TestCase(false, true)]
Expand All @@ -207,20 +221,25 @@ public void OnClose(bool apply, bool selectCode)
_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();
_optionsServiceMock.Setup(o => o.GetStringOption(viewModel.Feature, "Search", string.Empty)).Verifiable();
_optionsServiceMock.Setup(o => o.GetBoolOption(viewModel.Feature, "AllFiles", false)).Verifiable();

_shellHelperServiceMock.Setup(s => s.OpenFiles(It.IsAny<IEnumerable<IExtensibilityItem>>())).Verifiable();
_shellHelperServiceMock.Setup(s => s.OpenDesignerFiles(It.IsAny<IEnumerable<IExtensibilityItem>>())).Verifiable();

viewModel.SelectionCode = selectCode;
viewModel.Selection = _files;

viewModel.OnInitialize(new SolutionModel { SolutionName = string.Empty });
viewModel.OnClose(apply);

Assert.That(viewModel.Cache, Is.Not.Null);
_optionsServiceMock.Verify(o => o.SetStringOption(viewModel.Feature, "Solution", string.Empty));
_optionsServiceMock.Verify(o => o.SetStringOption(viewModel.Feature, "Search", string.Empty));
_optionsServiceMock.Verify(o => o.SetStringOption(viewModel.Feature, "Search", null));
_optionsServiceMock.Verify(o => o.SetBoolOption(viewModel.Feature, "AllFiles", false));
if (apply)
{
Assert.That(viewModel.Result, Is.Not.Null);
if (selectCode)
{
_shellHelperServiceMock.Verify(s => s.OpenFiles(It.IsAny<IEnumerable<IExtensibilityItem>>()), Times.Once);
Expand Down
Loading

0 comments on commit 5797b51

Please sign in to comment.