I have a unit test where I have to mock a non-virtual method that returns a bool type public class XmlCupboardAccess { public bool IsDataEntityInXmlCupboard(string dataId, out string nameInCupboard,...
I have some issues trying to wrap my code to be used in unit tests. The issues is this. I have the interface IHttpHandler: public interface IHttpHandler { HttpClient...
This is my controller: public class BlogController : Controller { private IDAO<Blog> _blogDAO; private readonly ILogger<BlogController> _logger; public BlogController(ILogger<BlogController> logger, IDAO<Blog> blogDAO) { this._blogDAO = blogDAO; this._logger = logger;...
I am fairly new to unit testing in C# and learning to use Moq. Below is the class that I am trying to test. class MyClass { SomeClass someClass;...
Imagine this class public class Foo { private Handler _h; public Foo(Handler h) { _h = h; } public void Bar(int i) { _h.AsyncHandle(CalcOn(i)); } private SomeResponse CalcOn(int i)...
public void SubmitMessagesToQueue_OneMessage_SubmitSuccessfully() { var messageServiceClientMock = new Mock<IMessageServiceClient>(); var queueableMessage = CreateSingleQueueableMessage(); var message = queueableMessage[0]; var xml = QueueableMessageAsXml(queueableMessage); messageServiceClientMock.Setup(proxy => proxy.SubmitMessage(xml)).Verifiable(); //messageServiceClientMock.Setup(proxy => proxy.SubmitMessage(It.IsAny<XmlElement>())).Verifiable(); var serviceProxyFactoryStub...
I am testing a method for a service that makes a Web API call. Using a normal HttpClient works fine for unit tests if I also run the web...
I have a preexisting Interface… public interface ISomeInterface { void SomeMethod(); } and I’ve extended this intreface using a mixin… public static class SomeInterfaceExtensions { public static void AnotherMethod(this...
I have a test like this: [TestCase("~/page/myaction")] public void Page_With_Custom_Action(string path) { // Arrange var pathData = new Mock<IPathData>(); var pageModel = new Mock<IPageModel>(); var repository = new Mock<IPageRepository>();...
Is it possible to assign an out/ref parameter using Moq (3.0+)? I’ve looked at using Callback(), but Action<> does not support ref parameters because it’s based on generics. I’d...