AutoFixture.AutoMoq supply a known value for one constructor parameter

后端 未结 6 1305
悲哀的现实
悲哀的现实 2020-12-13 14:52

I\'ve just started to use AutoFixture.AutoMoq in my unit tests and I\'m finding it very helpful for creating objects where I don\'t care about the specific

6条回答
  •  伪装坚强ぢ
    2020-12-13 15:02

    You have to replace:

    string knownValue = fixture.Freeze("My known value");
    

    with:

    fixture.Inject("My known value");
    

    You can read more about Inject here.


    Actually the Freeze extension method does:

    var value = fixture.Create();
    fixture.Inject(value);
    return value;
    

    Which means that the overload you used in the test actually called Create with a seed: My known value resulting in "My known value4d41f94f-1fc9-4115-9f29-e50bc2b4ba5e".

提交回复
热议问题