Refactor tests

Test are refactored to separate functionality and to enable reuse in users of the provider.
There is a TODO a little bit below (not in the diff) explaining the whole mess. I'll make a ticket.