AutoConfiguredMoqCustomization with an abstract class implementation interface

I am using AutoFixture 3.21.0, AutoFixture.AutoMoq 3.21.0, NUnit 2.6.3 and Moq 4.2.1409.1722.

I have the following interface, two abstract classes (one of them implements this interface) and two unit tests.

Pass tests.

public interface IMigration { IMigrationParameters MigrationParameters { get; set; } } public abstract class AbstractSutWithoutInterface { public IMigrationParameters MigrationParameters { get; set; } } public abstract class AbstractSutWithInterface : IMigration { public IMigrationParameters MigrationParameters { get; set; } } [TestFixture] public class UnitTests { [Test] public void TestAbstractSutWithoutInterface() { var fixture = new Fixture(); fixture.Customize( new AutoConfiguredMoqCustomization() ); var mock = fixture.Create<AbstractSutWithoutInterface>(); Assert.IsNotNull( mock.MigrationParameters ); // test passes } [Test] public void TestAbstractSutWithInterface() { var fixture = new Fixture(); fixture.Customize( new AutoConfiguredMoqCustomization() ); var mock = fixture.Create<AbstractSutWithInterface>(); Assert.IsNull( mock.MigrationParameters ); // test passes } } 

My question is why AutoConfiguredMoqCustomization has different behavior for abstract classes depending on whether a property is defined by interface or not? The first test property claims that it is not null, and in the second test it is zero. If the classes are not abstract, property injection works as expected for both classes.

+5
source share
1 answer

Update 2015/04/15

This bug has been fixed in AutoFixture.AutoMoq 3.24.2 . See here for more details.

Update 2014/11/03

Now it is tracked on AutoFixture GitHub, Problem 324 .

In addition, the latest working version of Moq is 4.2.1402.2112, you can upgrade to it instead of 4.0.


I can only reproduce this with the latest version of Moq (4.2.1409.1722).

I am studying this right now, and it looks like a bug that appeared in the latest version of Moq, but it may be by design, I'm not sure yet.

In the meantime, please use version 4.0.10827. To lower the rating, go to "Tools" → "NuGet Package Manager" → "Package Manager" and enter:

 Uninstall-Package Moq -Force Install-Package Moq -Version 4.0.10827 

I will update this answer with my findings.

+5
source

Source: https://habr.com/ru/post/1205341/


All Articles