共用方式為


If only you could set properties on fakes.

I'm using this library called FakeItEasy. The more I use it the more I like it.

While using it I suddenly thought:

var fakeIdentity = A.Fake<IIdentity>() { Name = "foo" };

Would be so much simpler than

var fakeIdentity = A.Fake<IIdentity>();
A.CallTo(() => fakeIdentity.Name).Returns("foo");

especially when it could be inlined without needing to introduce this fakeIdentity variable...

BUT! Obviously it doesn't work with this syntax for various reasons, like the compiler is not going to like that it is not a new statement...
Well, maybe we can't implement it, and we should just keep this in mind though for the next time we are designing a programming language. :)

Comments

  • Anonymous
    June 17, 2013
    The comment has been removed
  • Anonymous
    October 15, 2013
    Wait, that's almost exactly what I'm looking for! Thanks? :)