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
30
votes
3 answers

Automocking Web Api 2 controller

I am trying to auto mock ApiController class in my test cases. It worked perfectly when I was using WebApi1. I started to use WebApi2 on the new project and I am getting this exception thrown after I try to run my new…
user2910739
  • 313
  • 3
  • 7
11
votes
2 answers

How can I make AutoMoqCustomization use Strict MockBehavior?

Using AutoFixture with the AutoFixture.AutoMoq package, I sometimes find tests that weren't configured to correctly test the thing they meant to test, but the problem was never discovered because of the default (Loose) Mock behavior: public…
StriplingWarrior
  • 151,543
  • 27
  • 246
  • 315
9
votes
1 answer

AutoFixture fails to CreateAnonymous MVC Controller

The code: IFixture fixture = new Fixture().Customize(new AutoMoqCustomization()); fixture.Customize(c => c.Without(x => x.ModelMetadata)); var target = fixture.CreateAnonymous(); the…
Ruslan
  • 9,927
  • 15
  • 55
  • 89
6
votes
1 answer

How to mock SearchClient.SearchAsync with the Azure Cognitive Search SDK?

I am trying to unit test code that uses SearchClient.SearchAsync() method. I am using AutoFixture.AutoMoq nuget package. Here is what I tried: mockSearchClient.Setup(msc => msc.SearchAsync( It.IsAny(), …
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
6
votes
3 answers

Mocking a dependency with AutoFixture

I've recently started using AutoFixture+AutoMoq and I'm trying to create an instance of Func (i.e., a connection factory). var fixture = new Fixture().Customize(new AutoMoqCustomization()); var connectionFactory =…
dcastro
  • 66,540
  • 21
  • 145
  • 155
5
votes
1 answer

When setting up a custom AutoDataAttribute for auto mocking, what's the proper syntax to tell AutoFixture to ignore all recursive structures?

I have xUnit/Moq/AutoFixture successfully working together so that I am auto mocking objects via test method input parameters. I created a custom [AutoMoqData] attribute which I use on every test. Here's the code for the attribute: using…
Andr
  • 1,043
  • 4
  • 13
  • 15
5
votes
1 answer

AutoFixture with NUnit AutoMoq prevents tests from running

UPDATE: AutoFixture team released a fix for this in version 3.51. Simply extend the AutoDataAttribute doing so: public class AutoDataFixedNameAttribute : AutoDataAttribute { public AutoDataFixedNameAttribute() { …
xlecoustillier
  • 16,183
  • 14
  • 60
  • 85
5
votes
1 answer

C# – Mocking a method to return a different value when called a second time using Moq

i'm using Moq to mock repository with async method. This method must be called 2 times. In first call of this method i need to get null value. In second i need get some parametr. If this method wasn't async then i can use autoMockContext …
Dima Grigoriev
  • 357
  • 5
  • 22
5
votes
1 answer

AutoFixture AutoMoq not creating mocks for some properties

I am using AutoFixture with the AutoMoqCustomization and attempting to create an instance of a class which contains a readonly property thus: public override ILog Logger { get; } = LogManager.GetLogger(typeof(MyService)); The idea being that i…
RNDThoughts
  • 892
  • 3
  • 13
  • 30
4
votes
1 answer

Autofixture.Automoq - generics make bool always true

public interface IResult { bool Success { get; } } public interface IResult : IResult { } Using AutoFixure, and AutoMoq I am trying to find a way to to make Success always true, no matter what type T is. Registering a fake is easy enough…
Dylan Orr
  • 69
  • 1
  • 5
4
votes
1 answer

Making AutoMoq return Fixture-created values for methods

I'd like to explore wether we can save time by setting that all Moq-mocks created by AutoMoq should by default return Fixture-created values as method return values. This would be beneficial when doing a test like the following: [TestMethod] public…
user3638471
4
votes
1 answer

AutoFixture + AutoMoq: Create mock with excluded property

For example ISomething is a interface with three properties: string Name and int Count and some complex property ImComplex (with circular dependencies etc) that I don't wanna AutoFixture to build up. So I need AutoFixture to create a Mock of…
AsValeO
  • 2,859
  • 3
  • 27
  • 64
4
votes
2 answers

AutoMock setup with AutoFixture Data Theories

Ok, as was answered in my other question, AutoMoq does not use AutoFixture by default. That's fine and easily solved by doing a setup and setting ReturnsUsingFixture. But can that be setup with Auto Fixture Data Theories? So we have a custom…
Riplikash
  • 843
  • 8
  • 27
4
votes
1 answer

AutoFixture & AutoMoq: Overriding object generation behavior

I'm proposing using AutoFixture and AutoFixture.xUnit at our company, and have gotten the mandate that for certain objects and fields they want random data that is formatted in an expected way. For example, they want PersonName to only populate with…
Riplikash
  • 843
  • 8
  • 27
4
votes
1 answer

AutoFixture.Xunit's [Frozen] not working

I have a simple ViewModel which contains some buttons. The visibility of these buttons can be changed by events raised with the EventAggregator of PaP Prism which is also the only constructor parameter of this VM. The corresponding test works just…
HerrLoesch
  • 1,023
  • 1
  • 13
  • 24
1
2 3 4 5 6