Questions tagged [automoq]

Auto mocking provider for Moq

AutoMoq is an "auto-mocking" container that automatically creates any fake objects that are necessary to instantiate the class under test.

Developer can access those fakes through the mocker, or developer can just ignore them if they're not important.

80 questions
1
vote
0 answers

How to mock a methods in the same class under test?

I am using Moq v4.13 and C#. I am trying to test method MethodA on the interface of MyClass : IMyInterface. MethodA has invocations on methods of another interface (IAnother) and I have set up those. These seem to be setup fine. MethodA also …
Anand
  • 1,387
  • 2
  • 26
  • 48
1
vote
1 answer

AutoFixture AutoMoq - SetReturnsDefault() does not work with fixture created mocks

I have a mock. This mock has two methods, MethodA() and MethodB(). I want to setup both methods to return false. I created various versions of the code, all of them should work, but some don't: These work: 1. var mock =…
Andrej Lucansky
  • 725
  • 10
  • 17
1
vote
1 answer

How to mock property injection dependency using AutoMock

How to mock a property injection. using (var mock = AutoMock.GetLoose()) { // mock.Mock creates the mock for constructor injected property // but not property injection (propertywiredup). } I could not find similar here to mock property…
dsi
  • 3,199
  • 12
  • 59
  • 102
1
vote
1 answer

AutoFixture deep freeze of object

I have a class public class GetDashboardStatisticsResult { public GetPublicationStatisticsResult Publications { get; set; } public GetSwitchboardStatisticsResult Switchboard { get; set; } } Which I use in my test like this public async Task…
Veikedo
  • 1,453
  • 1
  • 18
  • 25
1
vote
2 answers

How to induce an exception thrown when unit testing a simple method

I have a service call wrapper that does nothing but forwards the parameter to a service in a call. The reason for the wrapper is so we can have the Wrapper Injected using a DI container and thus mocked for unit testing. Here is how the wrapper looks…
fahadash
  • 3,133
  • 1
  • 30
  • 59
1
vote
1 answer

AutoMoq an abstract class with specific constructor

Is there a way to setup AutoFixture.AutoMoq such that when mocking an abstract class it uses a specific constructor? I need to test the implementation done in my abstract class. However, I do need to use one specific constructor. public abstract…
Adanay Martín
  • 397
  • 1
  • 3
  • 15
1
vote
1 answer

Mocked interface gets two phantom invocations on each property

I have a simple class that writes a message to the Console prefixed with the current time. It has a dependency on an IDateTimeProvider interface as an abstraction over DateTime.Now public interface IDateTimeProvider { DateTime Now { get; } …
Rik
  • 28,507
  • 14
  • 48
  • 67
1
vote
1 answer

In xUnit/Shouldly/AutoMoq/Autofixture, can we pass in a Type using InlineAutoMoqData that can be used as a in the test itself?

I've got an issue in Unit Testing that I've been unable to solve. I think the most succinct way to say it is: I want to be able to use a Type provided in a Theory InlineAutoMoqData's parameters as the T in Shouldly's Should.Throw method. This…
Omnideth
  • 51
  • 7
1
vote
1 answer

Unit Test Null Parameters in Constructor

I have coded a constructor for a class and I am testing for each parameter being null. See example below: public MyClass(IObjectA objA, IObjectB objB) : IMyClass { if (objA == null) { throw new ArgumentNullException("objA"); } …
Adrian Thompson Phillips
  • 6,893
  • 6
  • 38
  • 69
1
vote
2 answers

What is the correct way to setup mocking for this unit test involving named Unity resources?

I am wanting to write up a unit test that checks that a specific Unity IoC object was instantiated. For example, here is the class I am testing. using Microsoft.Practices.Unity; using System.Threading; namespace Client.Engine { public sealed…
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
1
vote
1 answer

Prevent Moq from creating singleton Mocks

It seems like mocked services are being shared with consumers, as if the mocked interfaces are singleton. I'm using AutoMoq/Moq combination if that's relevant. class TestableClass { public IService service; public TestableClass(IService…
Josh Smeaton
  • 47,939
  • 24
  • 129
  • 164
0
votes
0 answers

Problems with trying to AutoMock.Mock with non-interface or delegate factory args present

I am trying to understand why I am unable to AutoMock.Mock an interface, and whether the presence of non-interfaces (like string key) or delegates (like Foo.Factory) are part of the problem and what to do about them. I know about RegisterSource(new…
redgiant
  • 474
  • 5
  • 14
0
votes
1 answer

Create type with internal constructor and self referencing constructor parameter type in AutoFixture

We are using AutoFixture.AutoMoq 4.17.0. The following code throws an exception during Create: AutoFixture.ObjectCreationExceptionWithPath: AutoFixture was unable to create an instance from XXX.TypeWithInternalConstructor, most likely because it…
donttellya
  • 452
  • 1
  • 3
  • 13
0
votes
0 answers

Disable Authorization filter extending TypeFilterAttribute unit testing

for below code I want to do setup in ConfigureTestServices so that this particular attribute gets disabled while running the test. `public class AuthorizePermissionAttribute : TypeFilterAttribute { public…
0
votes
1 answer

Mocking Azure ServiceBusClient dependency not working with AutoFixture.AutoMoq Freeze

The following class has a dependency on ServiceBusClient from the Azure.Messaging.ServiceBus NuGet package (for sending Azure Service Bus messages): public class MyService { private readonly ServiceBusClient _serviceBusClient; public…
NetFx
  • 13
  • 3