Using this structure.
public class User
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public virtual bool IsAdministrator()
{
return false;
}
}
Is it possible to combine AutoFixture and Moq to accomplish the following?
- Ensure
User.FirstNameis auto-generated - Ensure
User.LastNameis always "Smith" (literal) - Ensure
User.MiddleNameis not populated (default) - Ensure User.IsAdministrator() returns
True - Verify
IsAdministrator()was called.
I know this seems so simple. Here's what I tried using AutoMoq.
var config = new AutoMoqCustomization()
{
ConfigureMembers = true
};
var fixture = new AutoFixture.Fixture();
fixture.Customize(config);
fixture.Freeze<Mock<User>>()
.Setup(x => x.IsAdministrator())
.Returns(true);
var model = fixture.Build<User>()
.With(x => x.LastName, "Smith")
.Without(x => x.MiddleName)
.Create();
But that is clearly wrong. :( I am sure the syntax is simple. Thank you for any help.
My goal: create an object with BOTH filled properties and mocked methods.