You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my VS2022 test project, I have Moq V4.16.1 installed.
I do not have NSubstitude installed.
I discovered that my test project does reference a package Teststack.Dossier V4.0.0, and that has a dependency on NSubstitute
That is where things got interesting :)
In the MoqIsAnyCompletion.cs
...
var hasMoqReferenced = context.Document.Project.MetadataReferences.Any(r => r.Display.Contains(this._provider.AssemblyName));
...
and in NSubstituteArgAnyCompletion.cs
...
var hasNSubstituteReferenced = context.Document.Project.MetadataReferences.Any(r => r.Display.Contains(this._provider.AssemblyName));
...
both those flags returned true, and then my suggestions somehow default to Args.Any instead of It.Any.
Seems like whoever is last, wins...not too sure.
Anyway, I found a way to make it work, but of course, I only looked at it from my point of view and my project. I want your input too, please 😊.
Suggestion
Read the project .csproj file to determine the packages installed by the developer, and ignore the sub-dependencies.
public static class PackagesHelper
{
// btw, feel free to refactor, just a quick test
public static IEnumerable<string> GetProjectNugetPackages(Project project)
{
var nugetPackages = new List<string>();
var csproj = new XmlDocument();
csproj.Load(project.FilePath);
var nodes = csproj.SelectNodes("//PackageReference[@Include and @Version]");
foreach (XmlNode packageReference in nodes)
{
var packageName = packageReference.Attributes["Include"].Value;
nugetPackages.Add(packageName);
}
return nugetPackages;
}
}
In the MoqIsAnyCompletion.cs
...
var hasMoqReferenced = PackagesHelper.GetProjectNugetPackages(context.Document.Project).Any(x => x.Equals(this._provider.AssemblyName, StringComparison.InvariantCultureIgnoreCase));
...
and in NSubstituteArgAnyCompletion.cs
...
var hasNSubstituteReferenced = PackagesHelper.GetProjectNugetPackages(context.Document.Project).Any(x => x.Equals(this._provider.AssemblyName, StringComparison.InvariantCultureIgnoreCase));
...
Let me know your thoughts.
PS: Like the project, THAXN! 😊
The text was updated successfully, but these errors were encountered:
rpbeukes
added a commit
to rpbeukes/Mocking.Helpers
that referenced
this issue
Jun 16, 2022
Scenario
In my VS2022 test project, I have
Moq V4.16.1
installed.I do not have NSubstitude installed.
I discovered that my test project does reference a package Teststack.Dossier V4.0.0, and that has a dependency on
NSubstitute
That is where things got interesting :)
In the
MoqIsAnyCompletion.cs
and in
NSubstituteArgAnyCompletion.cs
both those flags returned true, and then my suggestions somehow default to
Args.Any
instead ofIt.Any
.Seems like whoever is last, wins...not too sure.
Anyway, I found a way to make it work, but of course, I only looked at it from my point of view and my project. I want your input too, please 😊.
Suggestion
Read the project
.csproj
file to determine the packages installed by the developer, and ignore the sub-dependencies.In the
MoqIsAnyCompletion.cs
and in
NSubstituteArgAnyCompletion.cs
Let me know your thoughts.
PS: Like the project, THAXN! 😊
The text was updated successfully, but these errors were encountered: