c# - AutoFixture and fluent Moq syntax -


i've been using moq while, , brevity more not express setups using fluent syntax of mock.of...

var foo = mock.of<ifoo>(f => f.method(it.isany<string>()) == 7 && f.property == "hi"); var sut = new whatever(foo); 

recently, i've started playing around autofixture , can't seem find equivalent syntax expressing multiple setups @ once. understand can express same thing using freeze...

var foo = fixture.freeze<mock<ifoo>>(); foo.setup(f => f.method(it.isany<string>()).returns(7); foo.setup(f => f.property).returns("hi"); var sut = fixture.create<whatever>(); 

...but if @ possible, i'd benefits of automocking, , keep brevity of fluent moq setups. stylistic arguments aside, autofixture expose way me express setups fluently? if not, there optimization can use make autofixture setups more terse?

you create mock using moq's fluent api, , inject fixture:

var foo = mock.of<ifoo>(f => f.method(it.isany<string>()) == 7 && f.property == "hi"); fixture.inject(foo);  var sut = fixture.create<whatever>(); 

if you're using automoqcustomization, code above same thing code posted, apart not setting callbase = true , defaultvalue = defaultvalue.mock;.

if you're using autoconfiguredmoqcustomization, code not setup additional members, whereas customization would. if want reap benefits of autoconfiguredmoqcustomization and use moq's fluent api, i'm afraid that's not possible.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -