Closed GoogleCodeExporter closed 8 years ago
Example: http://www.thejoyofcode.com/Automatically_Unit_Test_your_Model.aspx
Original comment by jeff.br...@gmail.com
on 8 Sep 2007 at 10:19
Original comment by jeff.br...@gmail.com
on 30 Oct 2007 at 2:24
Original comment by jeff.br...@gmail.com
on 17 Mar 2008 at 10:57
Yann, this is in line with the contract verifier stuff we've been discussing.
Original comment by jeff.br...@gmail.com
on 11 Nov 2008 at 8:49
Could be done as a contract verifier of sorts...
Maybe use lambdas or expression trees to help select properties of interest for
testing.
Original comment by jeff.br...@gmail.com
on 31 Mar 2009 at 3:57
Actually, I am working on it right now.
I expect to commit an experimental version during the week.
In its most simple form, the syntax should be:
[VerifyContract]
public readonly IContract FooAccessorTests = new AccessorContract<Sample, Foo>
{
Getter = target => target.Foo,
Setter = (target, value) => target.Foo = value,
ValidValues = { new Foo(123), new Foo(456), new Foo(789) },
};
Various customizations are possible as well:
// To check automatically for ArgumentNullException.
AcceptNullValue = false|true,
// To provide a custom instance if no default constructor is available or if
the
user wants it for any reason.
GetDefaultInstance = () => new Sample("Hello"),
// And to check for various expected exceptions when settings invalid values.
InvalidValues =
{
{ typeof(ArgumentOutOfRangeException), new Foo(-123), new Foo(-456) },
{ typeof(ArgumentException), new Foo(666) }
}
Original comment by Yann.Tre...@gmail.com
on 31 Mar 2009 at 6:21
I wonder if we can combine several properties together.
new AccessorContract<...>
{
Properties =
{
Getter = ...
Setter = ...
ValidValues = ....
InvalidValues = ...
},
{
Getter = ...
Setter = ...
ValidValues = ....
InvalidValues = ...
},
{
Name = "PropertyNameToAccessViaReflection"
}
}
Doesn't look like it will work with the type inference you have on Foo though.
Original comment by jeff.br...@gmail.com
on 31 Mar 2009 at 9:03
Mmh... That possibility to combine several properties at once is a good idea.
I was relunctant to let the user identify a property by its name. It tends to
be a
fragile declaration which hardly survives any rename refactorisation. But to
let
both the possibilities (by the name and by explicit expressions defining getter
and
setter) is a good point too.
Well. I think you have too many good ideas. Are you not tired at the end of
day? :D
Original comment by Yann.Tre...@gmail.com
on 1 Apr 2009 at 1:00
AccessorContract<TTarget, TValue> is available.
Original comment by Yann.Tre...@gmail.com
on 6 Apr 2009 at 6:26
Original issue reported on code.google.com by
jeff.br...@gmail.com
on 27 Aug 2007 at 7:58