Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I attach an attribute to mocked properties? #190

Closed
gsscoder opened this issue Jul 11, 2015 · 3 comments
Closed

Can I attach an attribute to mocked properties? #190

gsscoder opened this issue Jul 11, 2015 · 3 comments

Comments

@gsscoder
Copy link

Hi there,
thanks for sharing this great project! 馃憤

Given that example:

public interface IEmptyInterface { }
public interface IScalarString { 
  string StringValue { get; set; }
}

mock = new Mock<IEmptyInterface>();
intf = mock.As<IScalarString>();
intf.SetupAllProperties();
var o = mock.Object;

I lock to attach an attribute to mocked IScalarString::StringValue. Is this possible?

This will be very interesting also when mocking anonymous objects.

P.S.: I'm using Moq from NuGet, version 4.2.1507.0118.

@kzu
Copy link
Contributor

kzu commented Jul 12, 2015

That's a very interesting scenario and potential new feature. Unfortunately this isn't possible right now :(

@gsscoder
Copy link
Author

@kzu, thank you for saying that!

Since I want to refactor a test project with non-programmatic fake, I'm writing a small helper class.
It's nothing exceptional, something I've done in 2-3 hours of work, but I hope it could inspire a Moq enhancement.
(For now it's designed to create mock of classes with property getters/setters and attach attributes to such properties).

For completeness, I want to refactor all this fake types: I'd like to be able to define types using a fluent dot-syntax.

@stakx
Copy link
Contributor

stakx commented Jun 24, 2017

I love reflection, metaprogramming, and runtime type generation stuff, so your proposition sounds interesting to me. That being said though, I am not sure Moq is quite the right place for this kind of functionality. After all, its main focus is on creating ad-hoc implementations of types having a specified behaviour. Adding or modifying custom attributes doesn't quite line up with that, IMHO.

@stakx stakx closed this as completed Jun 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants