Skip to main content

Posts

Showing posts with the label testing

Testing when the culture changes in WPF

Recently I've do some work on a WPF app which required to support multiple languages in the UI - a spike to see how easy supporting multiple languages is in WPF, the test UI is shown below in English & French: The app is easy enough to understand - change the UI language and all the text based values are updated with the locale specific instances. I wanted to follow the standard pattern of using language specific resource files to store the translated text, these were placed in the standard location inside the project structure: One of the big advantages of using this mechanism is the resources are compiled into a class which can be used in your ViewModels and Views and this is why see above the 'Resource.resx' file - this contains the 'untranslated' resource strings etc: I've been aware for a long time there are 2 culturing settings per thread in .Net - Thread.CurrentCulture  & Thread.CurrentUICulture , the second is the one of interest here...

Self hosting a web service inside a test fixture using WebAPI

I have a class which handles all the communication to any back-end RESTful service, it wraps up all the complexity of using HttpWebRequest and provides a simple API: 1: public interface IRestClient 2: { 3: Task<RestResponse<T>> GetAsync<T>(Uri url) where T : class ; 4: Task<RestResponse> PutAsync<T>(Uri url, T resource) where T : class ; 5: Task<RestResponse<T>> PostAsync<T>(Uri url, T resource) where T : class ; 6: Task<RestResponse> DeleteAsync(Uri url); 7: } The implementation of this class isn't relevant for this post - it's all about the behaviour. The behaviour is what I'm trying to test not the internal implementation... So how can I test this in a standard test fixture? I knew it was possible but I didn't think it would so easy... Having used asp.net WebAPI  for hosting services in IIS I knew this was the tech stack I wanted to use, but could...

Testing time based observable in Rx is so easy...

If you've been doing Rx for a while it's very likely you're also be into testing with TDD. In which case you'll have come across testing observable timers but if not then what follows is how easy this is. So lets say I want to test the following method, it generates a 'tick' according to the time span parameter: 1: public IObservable<Unit> TickEvery(TimeSpan timeSpan) 2: { 3: return Observable.Interval(timeSpan).TimeInterval() 4: .Select(_ => new Unit()); 5: } When testing this I don't want to be dependent on the scheduler clock, what I mean is you don't want the test code to have to do some kind of 'wait' operation whilst the Observable.Interval is generating values. The answer is to use the Reactive Extensions Testing Library . It provides the TestScheduler  which allows to manipulate the underlying clock using the AdvanceBy & AdvanceTo methods which then means you can trigger any...

Getting MSpec working with Visual Studio 2012 RC & R# 7 EAP

These are the steps are used to get MSpec working with the release candidate for Visual Studio 2012 and the EAP for Resharper 7. I'm using the build 64 (09/06/2012) of R# 7 EAP - latest releases can be found here . Firstly, I have the following MSpec style fixture shown below, as you can see the Resharper icons aren't showing up on the left hand side: The next step is to add the correct Nuget package for MSpec - you have to get the pre-release version, not the current production release. I installed it using the package manager console in Visual Studio - don't forget the ' -Pre ' suffix to get the right version of the package: At this point you're probably thinking you're good-to-go, but there's one important step left - the pre-release MSpec assemblies have to be copied to the app data folder for Resharper. Luckily the MSpec guys have this in-hand and have created a set of batch files as part of the Nuget package installer. Browse...

faking data in WP7 and other .Net platforms

I needed to fake some data for a WP7 app yesterday and I was about to write a couple of classes when I thought why not check out what's available out there already... There were already a couple of NuGet packages out there but I wanted to try out my forking skills on GitHub :) I had a quick conversation with Ben Smith about faker-cs   and producing a NuGet package.  Introducing Faker.Net on NuGet, with support for .Net 3.5 SP1, .Net 4.0, Silverlight & WP7. Faker.Net support loads of different ways to fake data - addresses, names, phones numbers and more: It's very simple to use, shown below is the code for the following WP7 apps: It could be used anywhere you need fake data - proof of concept, testing, demo apps...

Playing around with jasmine

I believe like a lot of devs that javascript is going to become more prevalent in a lot if not all areas of application development, whether that be with a server side framework like  node.js or client side with frameworks like backbone.js & knockout.js . I've built a couple of sites with backbone and I'm very interested in what Derik Bailey is doing with marionette , but with all my investigations into backbone I haven't as yet put any of the javascript I've written under as serious testing strategy. A quick search for a BDD style testing framework lead me to jasmine , I've heard good things and I thought I'd give it ago. What to put under test with jasmine? Previously I implemented a simple undo-redo framework for .Net called  undoable.net , this was pushed out to GitHub and I thought I'd port this to javascript. The important issue here is not the ported-code but how easy I found it to get jasmine up and running. First off downloaded...