Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ad92ba1083
Fetching contributors…

Cannot retrieve contributors at this time

file 101 lines (78 sloc) 2.533 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
using System;
using System.Linq;
using System.IO;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Test.Common.AutoMoq;

namespace NzbDrone.Test.Common
{
    public class TestBase : LoggingTest
    {

        protected const string INTEGRATION_TEST = "Integration Test";


        private AutoMoqer _mocker;
        protected AutoMoqer Mocker
        {
            get
            {
                if (_mocker == null)
                {
                    _mocker = new AutoMoqer();
                }

                return _mocker;
            }
        }

        protected Mock<RestProvider> MockedRestProvider { get; private set; }


        protected string VirtualPath
        {
            get
            {
                var virtualPath = Path.Combine(TempFolder, "VirtualNzbDrone");
                if (!Directory.Exists(virtualPath)) Directory.CreateDirectory(virtualPath);

                return virtualPath;
            }
        }

[SetUp]
        public void TestBaseSetup()
        {
            EnvironmentProvider.RegisterNewInstall = true;

            MockedRestProvider = new Mock<RestProvider>();
            ReportingService.RestProvider = MockedRestProvider.Object;
            ReportingService.SetupExceptronDriver();


            if (Directory.Exists(TempFolder))
            {
                Directory.Delete(TempFolder, true);
            }

            Directory.CreateDirectory(TempFolder);
        }

[TearDown]
        public void TestBaseTearDown()
        {
            _mocker = null;
        }

        protected void WithStrictMocker()
        {
            if (_mocker != null)
                throw new InvalidOperationException("Can not switch to a strict container after container has been used. make sure this is the first call in your test.");

            _mocker = new AutoMoqer(MockBehavior.Strict);
        }


        protected void WithTempAsAppPath()
        {
            Mocker.GetMock<EnvironmentProvider>()
                .SetupGet(c => c.ApplicationPath)
                .Returns(VirtualPath);
        }


        protected string TempFolder
        {
            get { return Path.Combine(Directory.GetCurrentDirectory(), "temp"); }
        }

        protected string GetTestFilePath(string fileName)
        {
            return Path.Combine(@".\Files\", fileName);
        }

        protected string ReadTestFile(string fileName)
        {
            return File.ReadAllText(GetTestFilePath(fileName));
        }
    }
}
Something went wrong with that request. Please try again.