XUnit: testing for exceptions

I think I’ve written about this before… but I can’t find it. Basically I find the paradigm for exception testing nicer in XUnit compared with MsTest, in my view. Note that there is no decoration, and you can test easily both for the exception type, and for a message (in this case) that accompanies it:

[Fact]
public void RequestForNotFoundFrequencyThrowsException() {
TraceExecutingMethod();
var toneSet = new Model.ToneUtility();
Exception ex = Assert.Throws<ArgumentException>(() => toneSet.GetNoteElements(9999));
Assert.Equal("[The frequency [9999] was not found in the set of available notes]", ex.Message);
}

Advertisements

Sorry… DNVM, DNU, DNX… again

Summary

As I found myself once again with the luxury of a bare machine, and having signed up for the FatSecret API , I thought I would combine those things to see if I could use Visual Studio Code to do something useful this time round. I eventually got the DLL built, with the major hurdle beings being a) the deprecation of the httputility class in favour of WebUtility for URLEncode (it’s not that these things are hard, it’s knowing the questions to ask when things  you expect aren’t there), b) ignorance of the frameworkAssemblies option in the project.json file, c) ignorance of the configurations option in the same file. At the end of the night, I haven’t actually made a call yet, so although syntactically ok, it might yet be semantically nonsense. The detail is just in the screenshots without context other than the usual borders. The screenshots are just about in sequence.

 

Links

http://platform.fatsecret.com/api/Default.aspx?screen=rapiauth

http://hueniverse.com/2007/10/04/beginners-guide-to-oauth-part-i-overview/

http://oauth.net/core/1.0/

http://deanhume.com/home/blogpost/a-simple-guide-to-using-oauth-with-c-/49

http://oauth.googlecode.com/svn/code/csharp/OAuthBase.cs

http://stackoverflow.com/questions/32434401/replacement-for-system-web-httputility-urlencode-urldecode-asp-net-5

http://bit.ly/1TD2yhD

http://www.lyalin.com/2014/04/25/the-type-system-object-is-defined-in-an-assembly-that-is-not-reference-mvc-pcl-issue/

This got me over the XDocument issue:

https://github.com/aspnet/dnx/issues/2803

https://github.com/aspnet/Home/wiki/Project.json-file

And this was really useful… but of course I found it once I had finished:

http://docs.asp.net/en/latest/dnx/projects.html

http://stackoverflow.com/questions/30747965/what-is-the-difference-between-dependencies-and-frameworkassemblies-in-proje

http://stackoverflow.com/questions/32004649/asp-net-vnext-and-xdocument