I'll definately give this a go, even though the Assert*Ex* gives me
the creeps:-)

First impression (in being rather green on the linq'ish expressions)
is that the () => thingy feels a bit unintuitive. I'm sorta getting
used to it from the TypeMock Isolator stuff, but I still find it a
little bit..ehm.. nonexpressive.. Are there more advanced usages of
this semantic that might give me some more insight on the potential?

mads

On Jan 21, 12:09 am, Jeff Brown <[email protected]> wrote:
> Forwarding this here in case other people are curious about AssertEx.That.
>
> ---------- Forwarded message ----------
> From: Jeff Brown <[email protected]>
> Date: Tue, Jan 20, 2009 at 3:08 PM
> Subject: Re: MbUnit Re: and NUnit Syntax helper?
> To: Mads Nissen <[email protected]>
>
> Wow!  That's an old thread!
>
> Here's where we're at.  I decided not to try to support the NUnit syntax
> helpers themselves.  Instead I invested some effort to provide a mechanism
> for composing assertions together to create compound assertions over
> collections.  See "Assert.Over...." for more on this.
>
> In addition to that, I created an "AssertEx.That" method based on .Net 3.5
> Expression Trees.  Here's how you use it.
>
> 1. Add a reference to the MbUnit35 and Gallio35 assemblies.
>
> 2. Try something like this:
>
> string x = "Foo";
> AssertEx.That(() => x.Contains("Bar"));
>
> The assertion failure message will tell you not only that 'x' does not
> contain "Bar" but also the value of 'x' was "Foo".
>
> This syntax is quite flexible.  All captured variables are printed.  The
> last subexpression before a failure occurs is also printed.  This is
> particularly interesting with loops.
>
> [Test]
> public void Test()
> {
>     AssertIsFibonacci(new[] { 0, 1, 1, 2, 3, 5, 8, 12, 21 });
> }
>
> private void AssertIsFibonacci(IList<int> sequence)
> {
>     if (sequence.Count > 0)
>     {
>         AssertEx.That(() => sequence[0] == 0);
>
>        if (sequence.Count > 1)
>        {
>           AssertEx.That(() => sequence[1] == 1);
>
>           for (int i = 2; i < sequence.Count; i++)
>              AssertEx.That(() => sequence[i] == sequence[i - 1] + sequence[i
> - 2];
>        }
>    }
> }
>
> This test will fail.  However, in the failure message you will see the
> following information:
>
> a. That the value of 'i' at the time of the failure was 7.
> b. That 'sequence' contains 0, 1, 1, 2, 3, 5, 8, 12, 21.
> c. That 'sequence[i]' is 12.
> d. That 'sequence[i - 1]' is 5.
> e. That 'sequence[i - 2]' is 8.
> f. That 'sequence[i - 1] + sequence[i - 2]' is 13.
>
> And the whole thing failed of course because 12 != 13...
>
> Try it out!  It takes a little getting used to but I think you'll find it
> way more powerful than the NUnit Assert.That syntax helpers...  :-)
>
> Jeff.
>
> On Tue, Jan 20, 2009 at 1:28 PM, Mads Nissen <[email protected]> wrote:
>
> > I've probably missed out on something; but has this been implemented?
> > Running the latest Gallio distribution, but can't seem to find the
> > assert.that syntax anywhere..
>
> > thanks,
> > mads
>
> > On Jan 23 2008, 10:43 am, "Jeff Brown" <[email protected]> wrote:
> > > Nope.  Alpha 1 is really just an early technology preview.  There's tons
> > of
> > > stuff missing / incomplete in that release.
>
> > > Alpha 2 will be released in two weeks with much more stuff.  The syntax
> > > helpers and new constraint framework will go in Alpha 3.
>
> > > Wanna help out?
>
> > > Jeff.
>
> > > -----Original Message-----
> > > From: [email protected] [mailto:[email protected]]
> > On
>
> > > Behalf Of kementeus
> > > Sent: Tuesday, January 22, 2008 9:20 PM
> > > To: MbUnit.User
> > > Subject: MbUnit Re: and NUnit Syntax helper?
>
> > > I've been testing mbUnit v3 alpha 1 and I can't see where is the syntax
> > > helper support, well, there are not such namespace as
> > > MbUnit.Framework.SyntaxHelpers or any similar to Assert.That, do I miss
> > > something?
>
> > > On Dec 28 2007, 8:27 pm, "Jeff Brown" <[email protected]> wrote:
> > > > Not yet, but it's planned for MbUnit v3.
>
> > > > Also, if you're using .Net 3.5 there will be new syntax helpers to
> > > > take advantage of the expressive power of lambda's and extension
> > methods.
>
> > > > In the meantime, you can always use the NUnit syntax helpers together
> > > > with the MbUnit framework if you like.  :-)
>
> > > > Jeff.
>
> > > > -----Original Message-----
> > > > From: [email protected] [mailto:[email protected]]
> > > > On
>
> > > > Behalf Of kementeus
> > > > Sent: Friday, December 28, 2007 6:09 PM
> > > > To: MbUnit.User
> > > > Subject: MbUnit and NUnit Syntax helper?
>
> > > > Hi everybody!
>
> > > > I am a newbie in MbUnit and a user of NUnit, one of the troubles I got
> > > > when trying to switch from NUnit to MbUnit is the use of the NUnit
> > > > Syntax Helpers (NUnit.Framework.SyntaxHelpers), for example
>
> > > > [Test]
> > > > public void SyntaxHelperTest()
> > > > {
> > > >     int i = 5;
> > > >     int j = 5;
> > > >     Assert.That(i, Is.Equal(j));
> > > > }
>
> > > > I guess it is more clean that the Assert.AreEqual friend that everyone
> > > > of us know. Is any alternative in MbUnit for this?
>
> > > > Thanks a lot!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to