autofixture

How can I create and populate my mock classes with Autofixture?

雨燕双飞 提交于 2019-12-03 05:15:55
Currently I'm using EF6 to implement my repositories inside a UnitOfWork. I also have created an In-Memory mock implementations (MockUnitOfWork & MockRepository) so that I can use them in unit tests, however I now have to deal with the tedious setup of the objects. Isn't this what Autofixture is designed to do? How would I go about getting a MockUnitOfWork that I can use in my tests that contains Foo and Barr repositories that are populated? I'm using NSubstitute for my mocking framework. IUnitOfWork public interface IUnitOfWork { void Save(); void Commit(); void Rollback(); IRepository<Foo>

What is AutoFixture AutoMoq?

穿精又带淫゛_ 提交于 2019-12-02 20:04:15
I was looking at nuget and wanted to import moq when I noticed AutoFixture AutoMoq. I see that AutoFixture is to help write TDD faster but I can't find any examples of AutoMoq and how it is different then AutoFixture. Can someone point me to this AutoMoq so I can see what it is doing. Mark Seemann In short, AutoFixture.AutoMoq is an extension that turns AutoFixture into an Auto-Mocking Container using the Moq dynamic mock library. There's also a similar extension for AutoFixture that enables auto-mocking with Rhino Mocks . This article introduces auto-mocking for AutoFixture: http://blog.ploeh

Should I be using AutoFixture to test the Core element of my Onion, which has no dependancies?

China☆狼群 提交于 2019-12-02 16:40:09
问题 This question follows on from my previous question here: How to use OneTimeSetup? and specifically one of the answerers answer. Please see the code below: [TestFixture] public class MyFixture { IProduct Product; [OneTimeSetUp] public void OneTimeSetUp() { IFixture fixture = new Fixture().Customize(new AutoMoqCustomization()); Product = fixture.Create<Product>(); } //tests to follow } Is AutoMoq used to create mocks only? The reason I ask is because I was reading a question on here earlier

Likeness - polishing and packaging

Deadly 提交于 2019-12-02 12:01:22
问题 I'm using Ploeh.SemanticComparison 's Likeness as a way to effectively express intended outputs of a mapping process (as described in Mark Seemann's excellent Advanced Unit Testing course on PluralSight). I'm testing some data has mapped correctly, which looks like this: [Theory, AutoData] static void ShouldYieldIdentifierUpdatedEvent( Vendor sut, string name, string version, Guid id ) { var result = sut.SyncProduct( name, version, id ); var expected = new { ProductId = id, Name = name,

Should I be using AutoFixture to test the Core element of my Onion, which has no dependancies?

依然范特西╮ 提交于 2019-12-02 07:43:06
This question follows on from my previous question here: How to use OneTimeSetup? and specifically one of the answerers answer. Please see the code below: [TestFixture] public class MyFixture { IProduct Product; [OneTimeSetUp] public void OneTimeSetUp() { IFixture fixture = new Fixture().Customize(new AutoMoqCustomization()); Product = fixture.Create<Product>(); } //tests to follow } Is AutoMoq used to create mocks only? The reason I ask is because I was reading a question on here earlier where the answerer implied that it is also used to create normal types i.e. not Mocks. I want to test the

Using AutoMoq methods with generic signatures

拟墨画扇 提交于 2019-12-02 05:29:58
问题 I'm currently using a test framework I've thrown together using xUnit, AutoMoq, AutoFixture, and AutoFixture.XUnit2. I'm running into issues with mocking methods with generic signatures. AutoFixture seems to handle generic items just fine. If I ask for a CustomeObject<Task<List<Task<string>>>> , or some other ridiculous nested generic type, it seems to generate them as expected all the way down to the last node. However, if I have an interface like this: public interface ITestInterface{ T Get

Likeness - polishing and packaging

梦想与她 提交于 2019-12-02 04:15:00
I'm using Ploeh.SemanticComparison 's Likeness as a way to effectively express intended outputs of a mapping process (as described in Mark Seemann's excellent Advanced Unit Testing course on PluralSight ). I'm testing some data has mapped correctly, which looks like this: [Theory, AutoData] static void ShouldYieldIdentifierUpdatedEvent( Vendor sut, string name, string version, Guid id ) { var result = sut.SyncProduct( name, version, id ); var expected = new { ProductId = id, Name = name, Version = version }; expected.AsSource().OfLikeness<NewMappingsEvent>() .Without( y => y

AutoFixture constrained string parameter

霸气de小男生 提交于 2019-12-02 03:46:28
Is there a simple way to specify a list of possible values for the parameter orderBy? Not one by one please, otherwise I would not be making the question. I want to specify that orderby makes sense only if it is chosen from a predetermined list. Suppose the list is very large...still not random. This cannot be that hard...no single example of such a simple task. [Test, AutoData] public override void IndexReturnsView(int? pageIndex, int? pageSize, string orderBy, bool? desc) { ..... } EDIT: All I want is to read the possible values from a list as I would do with the ValueSource attribute.

Using AutoMoq methods with generic signatures

拜拜、爱过 提交于 2019-12-02 00:18:40
I'm currently using a test framework I've thrown together using xUnit, AutoMoq, AutoFixture, and AutoFixture.XUnit2. I'm running into issues with mocking methods with generic signatures. AutoFixture seems to handle generic items just fine. If I ask for a CustomeObject<Task<List<Task<string>>>> , or some other ridiculous nested generic type, it seems to generate them as expected all the way down to the last node. However, if I have an interface like this: public interface ITestInterface{ T Get<T>(); } and then try to call the method from the mock I got from AutoMoq it just returns null. So, for

How to setup more complicated (IoC like) registration in AutoFixture

[亡魂溺海] 提交于 2019-12-01 22:33:41
Is it possible to reuse production IoC container registration in integration tests when using AutoFixture? The problem is that I need the following fixture setup to inject mocks if dependency is not registered and inject "real" database related dependencies var fixture = new Fixture().WithMocks().WithRealDatabase() The solution I've tried internal static Fixture WithMocks(this Fixture fixture) { fixture.Customize(new AutoMoqCustomization()); } internal static Fixture WithRealDatabase(this Fixture fixture) { var containerBuilder = new Autofac.ContainerBuilder(); ... containerBuilder.Register(c