CollectionAssert.AreEquivalent with Custom IEqualityComparer

CollectionAssert.AreEquivalent is implemented as: Assert.That(actual, new CollectionEquivalentConstraint(expected), message, args); You can write out your assert that way and supply a custom IEqualityComparer with Using: Assert.That(actual, new CollectionEquivalentConstraint(expected).Using(customComparer)); You can also shorten new CollectionEquivalentConstraint to Is.EquivalentTo: Assert.That(actual, Is.EquivalentTo(expected).Using(customComparer));

Moq.Mock – how to set up a method that takes an expression

You can set it up like this: _mockRepos.Setup(x => x.Single<Page>(It.IsAny<Expression<Func<Page, bool>>>()))//.Returns etc…; However you are coming up against one of Moq’s shortcomings. You would want to put an actual expression there instead of using It.IsAny, but Moq doesn’t support setting up methods that take expressions with specific expressions (it’s a difficult feature to implement). The … Read more

Where can I find the meaning of NUnit console exit codes?

Error code -100 stands for UNEXPECTED_ERROR static ConsoleUi() { OK = 0; INVALID_ARG = -1; FILE_NOT_FOUND = -2; FIXTURE_NOT_FOUND = -3; TRANSFORM_ERROR = -4; UNEXPECTED_ERROR = -100; } EDIT: Additional information from a thread on the NUnit-Discuss google group: Additionally, positive values give a count of failed tests in the run. The -100 return code … Read more

How to avoid SerializationException: Type is not resolved for member XXX when testing a component that uses the LogicalCallContext

I think this is good explaination why you get this error. Is it possible to use the logical call context within a unit test in VS 2010? I searched what is good option this. I never find any answer except MarshalByRefObject. So why you should inherit your object with it . It is good explanation … Read more

NUnit – Is it possible to check in the TearDown whether the test succeeded?

This has been already solved in Ran’s answer to similar SO question. Quoting Ran: Since version 2.5.7, NUnit allows Teardown to detect if last test failed. A new TestContext class allows tests to access information about themselves including the TestStauts. For more details, please refer to http://nunit.org/?p=releaseNotes&r=2.5.7 [TearDown] public void TearDown() { if (TestContext.CurrentContext.Result.Status == … Read more

How to get Code Coverage from Unit Tests in Visual Studio 2022 Community Edition?

You have Fine Code Coverage working with VS 2022, you can access to it here https://github.com/FortuneN/FineCodeCoverage/releases and click on the 2022 file. After that, it´s just a plugin that you install on your computer and it´s available to every single project without the need to add it project by project. Update: Now it’s available directly … Read more

Unit test HttpContext.Current.Cache or other server-side methods in C#?

The way to do this is to avoid direct use of the HttpContext or other similar classes, and substitute them with mocks. After all, you’re not trying to test that the HttpContext functions properly (that’s microsoft’s job), you’re just trying to test that the methods got called when they should have. Steps (In case you … Read more

Run NUnit tests in .NET Core

Update 4: The NUnit3TestAdapter v3.8 has been released, so it is no longer alpha. Update 3: With NUnit3TestAdapter v3.8.0-alpha1 it is possible now to run the tests using dotnet test command. You just need to have these dependencies in your test project: <PackageReference Include=”nunit” Version=”3.7.0″ /> <PackageReference Include=”NUnit3TestAdapter” Version=”3.8.0-*” /> <PackageReference Include=”Microsoft.NET.Test.Sdk” Version=”15.*” /> You … Read more

Unit testing XML Generation [closed]

First, as pretty much everyone is saying, validate the XML if there’s a schema defined for it. (If there’s not, define one.) But you can build tests that are a lot more granular than that by executing XPath queries against the document, e.g.: string xml=”Your xml string here” ; XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)