Thursday, August 9, 2012

What’s new in ApprovalTests.Net v.20?

ASP routing support

As community contributor, Krzysztof Koźmic  said in his NDC talk
Using ApprovalTests makes what was implicit,
explicit so that the item can now be tested
Inspired by his talk, Jim Counts and I created a new method in AspApprovals to make the formerly implicit ASP routing explicit and now easily able to be tested.  Here’s an example
var urls = new[] {"/Home/Index/Hello", "/"};
AspApprovals.VerifyRouting(MvcApplication.RegisterRoutes, urls);

In the sample above, the delegate (MvcApplication.RegisterRoutes) will be invokes against a mock route collection, and then fed the URLs provided.  A sample output would look like this:

/Home/Index/Hello => [[controller, Home], [action, Index], [id, Hello]] 
/ => [[controller, Cool], [action, Index], [id, ]]

Event approvals

Similar to the example above, another aspect of code which is often hidden (or implicit) is which events are wired-up to your form.  This can be particularly troublesome when changing an existing, unfamiliar piece of code.  For example, it it easy to accidentally remove a button-click event.

Event approvals allows you to easily lock down existing events which are associated with an object or a form.  To do this, simply call the following:


This new method will only allow you to verify events which are directly associated to the object which is passed in.  Unfortunately, many times you don’t want to say ‘What are the events associated with this button"? rather you actually want to say ‘What are the events associated to this form, even though the button is on the form and the event is associated to the button (rather than the form)?’  This is now no problem, since we took this scenario into consideration and also created a convenience method for the latter scenario.

To test all the events on a form and its immediate children, simply call code as shown below:

WinFormsApprovals.VerifyEventsFor(new DemoForm());

WPF support for Controls

It’s always been possible to test WPF windows with a simple:


This would render the window to a .png image and verify against .approved file.

But sometimes you want to scope smaller to an individual control. Unfortunately, we had previously neglected this scenario – no longer!  You can now test an individual WPF control with the same call as shown below:

var menu = new ContextMenu();
menu.Items.Add(new MenuItem() {Header = "Add Element"});
menu.Items.Add(new MenuItem() {Header = "Delete"});
menu.Items.Add(new MenuItem() {Header = "Edit"});
menu.IsOpen = true;

This code will produce a *.png image, such as the one shown below:

Entity Framework support

People have long pondered how to test Entity Framework.  We have talked about this before, but previously testing EF with ApprovalTests had always required a large number of steps.  Now you can test EF by simply calling

using (var db = new ModelContainer())
    EntityFrameworkApprovals.Verify(db, CreateCompanyLoaderByName2(db, "Mic"));

This method will implement a ‘test-the-weather’ scenario which will verify the resulting SQL without the need to be able to connect to a database.  However, if this method fails, then it will connect to referenced database and will execute the generated query and will return extra information about WHY the test failed.  I plan to create more detailed tutorials on the inner workings of this new method soon.

Let’s give you one more look at this method signature.

public static void Verify<T>(ObjectContext db, IQueryable<T> queryable)

Email support for attachments

Previously, we added the method


Unfortunately, when the email message contained attachments, then the GUIDs that those attachments created caused issues with test output because they were not consistent over multiple test runs.  This bug has been fixed in this release.  To learn more about approving email messages, watch this video.

Testing Email with ApprovalTests

FileLauncher with DelayReporter

There has been a great deal of demand to use Cassini-dev after Jim Counts demo’d it during his ASPConf video on testing ASP.MVC views. Unfortunately, when using this method it’s a bit tricky to use a file launcher, since the web server dies BEFORE the browser can hit it.  We came up with a simple solution which adds a tiny delay into the method execution so that this is no longer an issue.


Well, that’s all for this release. As always, if you have any questions about ApprovalTests, tweet them with the hashtag #ApprovalTests, I monitor that and will answer you promptly.

Happy testing.


Naviya Nair said...

Very interesting and good Explanation on asp .net ..
ASP.NET Training
ASP NET Training
ASP.NET Online Training

C# Training
Dot Net Training in Chennai
Dot Net Training institutes in Chennai
ASP.NET Training

Ranveer Patil said...

Nice to see read that you have some knowledge about acne treatment cure...
ICC T20 World Cup 2016 Time Table
ICC T20 World Cup 2016 Fixtures
ICC T20 World Cup 2016 Venues & Starting Date

Sunny ipank said...

jual rumah cluster michelia gading rumah di gading serpong sektor 7c rumah dijual di gading disewakan rumah di sektor 1a gading rumah di gading serpong sektor rumah kayu gading serpong rumah dijual di gading serpong sektor daftar harga rumah kayu gading rumah dijual di gading serpong sektor rumah dijual murah gading rumah dijual di gading rumah di crystal gading alamat restoran rumah kayu gading jual rumah cluster fluorite rumah dijual gading serpong sektor harga rumah di gading dijual rumah gading rumah dijual di gading serpong rumah kayu dijual rumah cluster

Rudolf suwiko said...

Harga Paving Tembok Koleksi Tas Terbaru Desain Rumah Gratis Jual Rumah Alam Sutera Pemutih Kulit Khusu Tas Fashion Rumah Dijual Di Ser Grosir Tas Import Jual Krim Pemutih Grosir Baju Korea Harga Kanopi Minimalis Baju Branded Murah Rumah Dijual Bsd Pemutih Kulit Jual Baju Korea Perumahan Gading Serpong Harga Pipa Besi Baju Korea Jual Beli Rumah Di

Maple edy said...

Distributor Tas Mur Dijual Rumah Cluster Pusat Grosir Tas Rumah Dijual Di The Jual Rumah Bsd Gree Dijual Rumah Di Bsd Tas Murah Batam pemutih wajah pria Baju Murah Bandung Rumah Dijual Di Serpong Rumah Murah di Alam Sutera Jual Rumah Bumi Ser Tas Cantik Produk Pemutih Wajah Ciri-Ciri Krim Pemutih Tas Tas Murah Nama Produk Pemutih Tas Cantik Harga Tanah Di Nusa Kosmetik Buat Wajah

for IT the said...

Great Article
C# Online Training | ASP.NET Training | ASP.NET MVC Training

Dot Net Interview Questions

.net training online | Dot Net Training in Chennai | .Net Training in Chennai | Dot Net Training Institutes in Chennai

Wesley yuniarty said...

Jual Rumah Di Alam Lelang Rumah Rumah Dijual Di Del Mobil Truk Pasir Daftar Produk Pemutih Baju Import Butik Online Baju Korea Rumah Dijual Bsd 40 Tas Branded Kw 1 Gudang Tas Tas Batam Grosir Interior Apartemen Minimalis Rumah Baru Bsd City Kosmetik Dan Aman Rumah Dijual Puspita Loka Kosmetik Pemutih Wa Krim Pemutih Selang Harga Baju Murah Reseller Baju Korea Fashion Grosir

Sunny ipank said...

Kursus Online Jasa Jual Beli biro jasa perijinan jasa bangun rumah jual rumah tangerang gading serpong grosi baju korea Jasa Akuntansi jasa kontraktor Promosi Bisnis Online jasa desain furniture Jasa Desain Interior jual apartemen bsd tangerang Jasa Pemasaran Online Konsultan Pajak Jasa Catering Jasa Video Shooting Catering Jakarta Rental Mobil Jakarta Rumah Dijual Alam Sutera biro jasa perijinan jasa bangun rumah jual rumah tangerang gading serpong grosi baju korea Jasa Akuntansi jasa kontraktor Promosi Bisnis Online jasa desain furniture Jasa Desain Interior

Benny carrolina said...

Denah Rumah Tinggal Pagar Balkon Tas Batam Murah Batu Garut Merah Design Interior Minimalis Tas Kw Branded Rumah Murah Di Gadi Model Kanopi Rumah Dijual Di Ala Jual Rumah Bsd Gree Cream Pemutih Muka Toko Wanita Online Harga Gula Pasir 1 Kg Harga Pagar Besi Minimalis Jual Rumah Bsd City Pusat Baju Murah Grosir Murah Cream Pemutih Yang Beton Ringan Kanopi Rumah