Ewk.UnitTests

Contains some base classes with functionality that I often use in UnitTests.

Here it's used in another project I made to access the SoundCloud Api:

    public abstract class SoundCloudTestBase<T> : UnitTestBase 
        where T: new()
    {
        protected ISoundCloudClient SoundCloudClient { get; private set; }
        protected SoundCloud SoundCloud { get; private set; }

        protected override void AdditionalSetup()
        {
            SoundCloudClient = MockHelper.CreateMock<ISoundCloudClient>();
            SoundCloud = new SoundCloud(SoundCloudClient);
        }

        protected void TestGetEntityList(string expectedPath, Func<IEnumerable<T>> function)
        {
            var task = new Task<IEnumerable<T>>(() => new List<T>());

            SoundCloudClient
                .Expect(client => client.GetListAsync<T>(
                    Arg<string>.Is.Equal(expectedPath)))
                .WhenCalled(invocation => task.Start())
                .Return(task)
                .Repeat.Once();
            SoundCloudClient.Replay();

            function();

            SoundCloudClient.VerifyAllExpectations();
        }
}

Another example of a base test class that registers a mock to a service locator.

using Ewk.BandWebsite.Repositories;
using Ewk.BandWebsite.UnitTests;

namespace Ewk.BandWebsite.Process.UnitTests
{
    public abstract class ProcessTestBase : UnitTestBase
    {
        protected IAppRepository AppRepository { get; private set; }
        protected IBandRepository BandRepository { get; private set; }

        protected override void AdditionalSetup()
        {
            base.AdditionalSetup();

            AppRepository = MockHelper.CreateAndRegisterMock<IAppRepository>();
            BandRepository = MockHelper.CreateAndRegisterMock<IBandRepository>();
        }
    }
}

The dll can be found on NuGet.

Last edited Oct 2, 2012 at 10:38 PM by Coilz, version 7

Comments

No comments yet.