diff --git a/NzbDrone.App.Test/ConfigProviderTest.cs b/NzbDrone.App.Test/ConfigProviderTest.cs
index 9bed9a381..87f133ee7 100644
--- a/NzbDrone.App.Test/ConfigProviderTest.cs
+++ b/NzbDrone.App.Test/ConfigProviderTest.cs
@@ -1,6 +1,7 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
+using NzbDrone.Common;
using NzbDrone.Providers;
namespace NzbDrone.App.Test
diff --git a/NzbDrone.App.Test/EnviromentProviderTest.cs b/NzbDrone.App.Test/EnviromentProviderTest.cs
index 919be960d..3340a11d7 100644
--- a/NzbDrone.App.Test/EnviromentProviderTest.cs
+++ b/NzbDrone.App.Test/EnviromentProviderTest.cs
@@ -1,5 +1,6 @@
using FluentAssertions;
using NUnit.Framework;
+using NzbDrone.Common;
using NzbDrone.Providers;
namespace NzbDrone.App.Test
diff --git a/NzbDrone.App.Test/IISProviderTest.cs b/NzbDrone.App.Test/IISProviderTest.cs
index 29de777be..00c3e548b 100644
--- a/NzbDrone.App.Test/IISProviderTest.cs
+++ b/NzbDrone.App.Test/IISProviderTest.cs
@@ -7,6 +7,7 @@ using AutoMoq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
+using NzbDrone.Common;
using NzbDrone.Providers;
namespace NzbDrone.App.Test
@@ -14,9 +15,6 @@ namespace NzbDrone.App.Test
[TestFixture]
public class IISProviderTest
{
-
-
-
[Test]
public void start_should_set_IISProccessId_property()
{
diff --git a/NzbDrone.App.Test/MonitoringProviderTest.cs b/NzbDrone.App.Test/MonitoringProviderTest.cs
index f2439d9d4..7b3bd0807 100644
--- a/NzbDrone.App.Test/MonitoringProviderTest.cs
+++ b/NzbDrone.App.Test/MonitoringProviderTest.cs
@@ -8,6 +8,8 @@ using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
+using NzbDrone.Common;
+using NzbDrone.Common.Model;
using NzbDrone.Model;
using NzbDrone.Providers;
diff --git a/NzbDrone.App.Test/NzbDrone.App.Test.csproj b/NzbDrone.App.Test/NzbDrone.App.Test.csproj
index 59728b4ca..df95ddc4e 100644
--- a/NzbDrone.App.Test/NzbDrone.App.Test.csproj
+++ b/NzbDrone.App.Test/NzbDrone.App.Test.csproj
@@ -90,6 +90,10 @@
+
+ {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}
+ NzbDrone.Common
+
{FAFB5948-A222-4CF6-AD14-026BE7564802}
NzbDrone.Test.Dummy
diff --git a/NzbDrone.App.Test/ProcessProviderTests.cs b/NzbDrone.App.Test/ProcessProviderTests.cs
index 35aea670c..d22a86bf9 100644
--- a/NzbDrone.App.Test/ProcessProviderTests.cs
+++ b/NzbDrone.App.Test/ProcessProviderTests.cs
@@ -1,11 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Text;
+using System.Diagnostics;
using FluentAssertions;
using NUnit.Framework;
-using NzbDrone.Providers;
+using NzbDrone.Common;
namespace NzbDrone.App.Test
{
diff --git a/NzbDrone.App.Test/RouterTest.cs b/NzbDrone.App.Test/RouterTest.cs
index 264277990..f48082ff9 100644
--- a/NzbDrone.App.Test/RouterTest.cs
+++ b/NzbDrone.App.Test/RouterTest.cs
@@ -3,8 +3,8 @@ using AutoMoq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
+using NzbDrone.Common;
using NzbDrone.Model;
-using NzbDrone.Providers;
namespace NzbDrone.App.Test
{
diff --git a/NzbDrone.App.Test/ServiceControllerTests.cs b/NzbDrone.App.Test/ServiceControllerTests.cs
index 05cab1154..73f24cb35 100644
--- a/NzbDrone.App.Test/ServiceControllerTests.cs
+++ b/NzbDrone.App.Test/ServiceControllerTests.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using FluentAssertions;
using NUnit.Framework;
+using NzbDrone.Common;
using NzbDrone.Providers;
namespace NzbDrone.App.Test
diff --git a/NzbDrone/Providers/ConsoleProvider.cs b/NzbDrone.Common/ConsoleProvider.cs
similarity index 86%
rename from NzbDrone/Providers/ConsoleProvider.cs
rename to NzbDrone.Common/ConsoleProvider.cs
index cd45ce4f4..aaf72a702 100644
--- a/NzbDrone/Providers/ConsoleProvider.cs
+++ b/NzbDrone.Common/ConsoleProvider.cs
@@ -1,7 +1,7 @@
using System;
using System.Diagnostics;
-namespace NzbDrone.Providers
+namespace NzbDrone.Common
{
public class ConsoleProvider
{
@@ -32,5 +32,10 @@ namespace NzbDrone.Providers
{
Console.WriteLine("Can't find service ({0})", ServiceProvider.NzbDroneServiceName);
}
+
+ public virtual void UpdateFolderDoestExist(string path)
+ {
+ Console.WriteLine("Unable to find update package in '{0}'", path);
+ }
}
}
\ No newline at end of file
diff --git a/NzbDrone/Providers/EnviromentProvider.cs b/NzbDrone.Common/EnviromentProvider.cs
similarity index 84%
rename from NzbDrone/Providers/EnviromentProvider.cs
rename to NzbDrone.Common/EnviromentProvider.cs
index 3373d37ae..fa1fdb9ae 100644
--- a/NzbDrone/Providers/EnviromentProvider.cs
+++ b/NzbDrone.Common/EnviromentProvider.cs
@@ -2,7 +2,7 @@
using System.IO;
using System.Reflection;
-namespace NzbDrone.Providers
+namespace NzbDrone.Common
{
public class EnviromentProvider
{
@@ -42,6 +42,14 @@ namespace NzbDrone.Providers
}
}
+ public virtual string StartUpPath
+ {
+ get
+ {
+ return new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
+ }
+ }
+
private static bool ContainsIIS(DirectoryInfo dir)
{
return dir.GetDirectories("iisexpress").Length != 0;
diff --git a/NzbDrone/Model/ProcessInfo.cs b/NzbDrone.Common/Model/ProcessInfo.cs
similarity index 86%
rename from NzbDrone/Model/ProcessInfo.cs
rename to NzbDrone.Common/Model/ProcessInfo.cs
index f1086c2ab..3bcd2b39b 100644
--- a/NzbDrone/Model/ProcessInfo.cs
+++ b/NzbDrone.Common/Model/ProcessInfo.cs
@@ -1,6 +1,6 @@
using System.Diagnostics;
-namespace NzbDrone.Model
+namespace NzbDrone.Common.Model
{
public class ProcessInfo
{
diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj
new file mode 100644
index 000000000..f978fa966
--- /dev/null
+++ b/NzbDrone.Common/NzbDrone.Common.csproj
@@ -0,0 +1,67 @@
+
+
+
+ Debug
+ AnyCPU
+ 8.0.30703
+ 2.0
+ {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}
+ Library
+ Properties
+ NzbDrone.Common
+ NzbDrone.Common
+ v4.0
+ 512
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NzbDrone/Providers/ProcessProvider.cs b/NzbDrone.Common/ProcessProvider.cs
similarity index 97%
rename from NzbDrone/Providers/ProcessProvider.cs
rename to NzbDrone.Common/ProcessProvider.cs
index da8822155..94fded59f 100644
--- a/NzbDrone/Providers/ProcessProvider.cs
+++ b/NzbDrone.Common/ProcessProvider.cs
@@ -2,9 +2,9 @@
using System.Diagnostics;
using System.Linq;
using NLog;
-using NzbDrone.Model;
+using NzbDrone.Common.Model;
-namespace NzbDrone.Providers
+namespace NzbDrone.Common
{
public class ProcessProvider
{
diff --git a/NzbDrone.Common/Properties/AssemblyInfo.cs b/NzbDrone.Common/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..182f9300e
--- /dev/null
+++ b/NzbDrone.Common/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("NzbDrone.Common")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("NzbDrone.Common")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("b6eaa144-e13b-42e5-a738-c60d89c0f728")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/NzbDrone.Common/ServiceProvider.cs b/NzbDrone.Common/ServiceProvider.cs
new file mode 100644
index 000000000..da14867d1
--- /dev/null
+++ b/NzbDrone.Common/ServiceProvider.cs
@@ -0,0 +1,136 @@
+using System;
+using System.Collections.Specialized;
+using System.Configuration.Install;
+using System.Linq;
+using System.Reflection;
+using System.ServiceProcess;
+using NLog;
+using TimeoutException = System.TimeoutException;
+
+namespace NzbDrone.Common
+{
+ public class ServiceProvider
+ {
+ public const string NzbDroneServiceName = "NzbDrone";
+
+ private static readonly Logger Logger = LogManager.GetLogger("Host.ServiceManager");
+
+ public virtual bool ServiceExist(string name)
+ {
+ Logger.Debug("Checking if service {0} exists.", name);
+ return
+ ServiceController.GetServices().Any(
+ s => String.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase));
+ }
+
+
+ public virtual void Install()
+ {
+ Logger.Info("Installing service '{0}'", NzbDroneServiceName);
+
+
+ var installer = new ServiceProcessInstaller
+ {
+ Account = ServiceAccount.LocalSystem
+ };
+
+ var serviceInstaller = new ServiceInstaller();
+
+
+ String[] cmdline = { @"/assemblypath=" + Assembly.GetExecutingAssembly().Location };
+
+ var context = new InstallContext("service_install.log", cmdline);
+ serviceInstaller.Context = context;
+ serviceInstaller.DisplayName = NzbDroneServiceName;
+ serviceInstaller.ServiceName = NzbDroneServiceName;
+ serviceInstaller.Description = "NzbDrone Application Server";
+ serviceInstaller.StartType = ServiceStartMode.Automatic;
+
+ serviceInstaller.Parent = installer;
+
+ serviceInstaller.Install(new ListDictionary());
+
+ Logger.Info("Service Has installed successfully.");
+ }
+
+ public virtual void UnInstall()
+ {
+ Logger.Info("Uninstalling NzbDrone service");
+ var serviceInstaller = new ServiceInstaller();
+
+ var context = new InstallContext("service_uninstall.log", null);
+ serviceInstaller.Context = context;
+ serviceInstaller.ServiceName = NzbDroneServiceName;
+ serviceInstaller.Uninstall(null);
+
+ Logger.Info("NzbDrone successfully uninstalled");
+ }
+
+
+ public virtual void Run(ServiceBase service)
+ {
+ ServiceBase.Run(service);
+ }
+
+ public virtual ServiceController GetService(string serviceName)
+ {
+ return ServiceController.GetServices().Where(
+ c => String.Equals(c.ServiceName, serviceName, StringComparison.InvariantCultureIgnoreCase))
+ .FirstOrDefault();
+ }
+
+ public virtual void Stop(string serviceName)
+ {
+ Logger.Info("Stopping {0} Service...");
+ var service = GetService(serviceName);
+ if (service == null)
+ {
+ Logger.Warn("Unable to stop {0}. no service with that name exists.", serviceName);
+ }
+
+ Logger.Info("Service is currently {0}", service.Status);
+
+ service.Stop();
+ service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(60));
+
+ service.Refresh();
+ if (service.Status == ServiceControllerStatus.Stopped)
+ {
+ Logger.Info("{0} has stopped successfully.");
+ }
+ else
+ {
+ Logger.Error("Service stop request has timed out. {0}", service.Status);
+ }
+ }
+
+ public virtual void Start(string serviceName)
+ {
+ Logger.Info("Starting {0} Service...");
+ var service = GetService(serviceName);
+ if (service == null)
+ {
+ Logger.Warn("Unable to start '{0}' no service with that name exists.", serviceName);
+ }
+
+ if (service.Status != ServiceControllerStatus.Paused || service.Status != ServiceControllerStatus.Stopped)
+ {
+ Logger.Warn("Service is in a state that can't be started {0}", service.Status);
+ }
+
+ service.Start();
+
+ service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(60));
+ service.Refresh();
+
+ if (service.Status == ServiceControllerStatus.Running)
+ {
+ Logger.Info("{0} has started successfully.");
+ }
+ else
+ {
+ Logger.Error("Service start request has timed out. {0}", service.Status);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/NzbDrone/Providers/WebClientProvider.cs b/NzbDrone.Common/WebClientProvider.cs
similarity index 87%
rename from NzbDrone/Providers/WebClientProvider.cs
rename to NzbDrone.Common/WebClientProvider.cs
index 3ffa1e920..baf0f0d64 100644
--- a/NzbDrone/Providers/WebClientProvider.cs
+++ b/NzbDrone.Common/WebClientProvider.cs
@@ -1,6 +1,6 @@
using System.Net;
-namespace NzbDrone.Providers
+namespace NzbDrone.Common
{
public class WebClientProvider
{
diff --git a/NzbDrone.Common/packages.config b/NzbDrone.Common/packages.config
new file mode 100644
index 000000000..4f6876419
--- /dev/null
+++ b/NzbDrone.Common/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/NzbDrone.Update.Test/AutoMoq/AutoMoqer.cs b/NzbDrone.Update.Test/AutoMoq/AutoMoqer.cs
new file mode 100644
index 000000000..27b2eee78
--- /dev/null
+++ b/NzbDrone.Update.Test/AutoMoq/AutoMoqer.cs
@@ -0,0 +1,166 @@
+// ReSharper disable RedundantUsingDirective
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Runtime.CompilerServices;
+using AutoMoq.Unity;
+using Microsoft.Practices.Unity;
+using Moq;
+using Moq.Language.Flow;
+
+[assembly: InternalsVisibleTo("AutoMoq.Tests")]
+
+namespace AutoMoq
+{
+ public class AutoMoqer
+ {
+ internal readonly MockBehavior DefaultBehavior = MockBehavior.Default;
+ internal Type ResolveType;
+ private IUnityContainer container;
+ private IDictionary registeredMocks;
+
+ public AutoMoqer()
+ {
+ SetupAutoMoqer(new UnityContainer());
+ }
+
+ public AutoMoqer(MockBehavior defaultBehavior)
+ {
+ DefaultBehavior = defaultBehavior;
+ SetupAutoMoqer(new UnityContainer());
+
+ }
+
+ internal AutoMoqer(IUnityContainer container)
+ {
+ SetupAutoMoqer(container);
+ }
+
+ public virtual T Resolve()
+ {
+ ResolveType = typeof(T);
+ var result = container.Resolve();
+ SetConstant(result);
+ ResolveType = null;
+ return result;
+ }
+
+ public virtual Mock GetMock() where T : class
+ {
+ return GetMock(DefaultBehavior);
+ }
+
+ public virtual Mock GetMock(MockBehavior behavior) where T : class
+ {
+ ResolveType = null;
+ var type = GetTheMockType();
+ if (GetMockHasNotBeenCalledForThisType(type))
+ {
+ CreateANewMockAndRegisterIt(type, behavior);
+ }
+
+ var mock = TheRegisteredMockForThisType(type);
+
+ if (behavior != MockBehavior.Default && mock.Behavior == MockBehavior.Default)
+ {
+ throw new InvalidOperationException("Unable to change be behaviour of a an existing mock.");
+ }
+
+ return mock;
+ }
+
+ internal virtual void SetMock(Type type, Mock mock)
+ {
+ if (registeredMocks.ContainsKey(type) == false)
+ registeredMocks.Add(type, mock);
+ }
+
+ public virtual void SetConstant(T instance)
+ {
+ container.RegisterInstance(instance);
+ SetMock(instance.GetType(), null);
+ }
+
+ public ISetup Setup(Expression> expression) where T : class
+ {
+ return GetMock().Setup(expression);
+ }
+
+ public ISetup Setup(Expression> expression) where T : class
+ {
+ return GetMock().Setup(expression);
+ }
+
+ public void Verify(Expression> expression) where T : class
+ {
+ GetMock().Verify(expression);
+ }
+
+ public void Verify(Expression> expression, string failMessage) where T : class
+ {
+ GetMock().Verify(expression, failMessage);
+ }
+
+ public void Verify(Expression> expression, Times times) where T : class
+ {
+ GetMock().Verify(expression, times);
+ }
+
+ public void Verify(Expression> expression, Times times, string failMessage) where T : class
+ {
+ GetMock().Verify(expression, times, failMessage);
+ }
+
+ public void VerifyAllMocks()
+ {
+ foreach (var registeredMock in registeredMocks)
+ {
+ var mock = registeredMock.Value as Mock;
+ if (mock != null)
+ mock.VerifyAll();
+ }
+ }
+
+ #region private methods
+
+ private void SetupAutoMoqer(IUnityContainer container)
+ {
+ this.container = container;
+ container.RegisterInstance(this);
+
+ registeredMocks = new Dictionary();
+ AddTheAutoMockingContainerExtensionToTheContainer(container);
+ }
+
+ private static void AddTheAutoMockingContainerExtensionToTheContainer(IUnityContainer container)
+ {
+ container.AddNewExtension();
+ return;
+ }
+
+ private Mock TheRegisteredMockForThisType(Type type) where T : class
+ {
+ return (Mock)registeredMocks.Where(x => x.Key == type).First().Value;
+ }
+
+ private void CreateANewMockAndRegisterIt(Type type, MockBehavior behavior) where T : class
+ {
+ var mock = new Mock(behavior);
+ container.RegisterInstance(mock.Object);
+ SetMock(type, mock);
+ }
+
+ private bool GetMockHasNotBeenCalledForThisType(Type type)
+ {
+ return registeredMocks.ContainsKey(type) == false;
+ }
+
+ private static Type GetTheMockType() where T : class
+ {
+ return typeof(T);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/NzbDrone.Update.Test/AutoMoq/AutoMoqerTest.cs b/NzbDrone.Update.Test/AutoMoq/AutoMoqerTest.cs
new file mode 100644
index 000000000..da0677763
--- /dev/null
+++ b/NzbDrone.Update.Test/AutoMoq/AutoMoqerTest.cs
@@ -0,0 +1,187 @@
+// ReSharper disable RedundantUsingDirective
+using System;
+using AutoMoq;
+using Moq;
+using NUnit.Framework;
+
+namespace NzbDrone.App.Test
+{
+ [TestFixture]
+ // ReSharper disable InconsistentNaming
+ public class AutoMoqerTest
+ {
+ [Test]
+ public void GetMock_on_interface_returns_mock()
+ {
+ //Arrange
+ var mocker = new AutoMoqer();
+
+ //Act
+ var mock = mocker.GetMock();
+
+ //Assert
+ Assert.IsNotNull(mock);
+ }
+
+ [Test]
+ public void GetMock_on_concrete_returns_mock()
+ {
+ //Arrange
+ var mocker = new AutoMoqer();
+
+ //Act
+ var mock = mocker.GetMock();
+
+ //Assert
+ Assert.IsNotNull(mock);
+ }
+
+
+ [Test]
+ public void Resolve_doesnt_return_mock()
+ {
+ //Arrange
+ var mocker = new AutoMoqer();
+
+ //Act
+ var result = mocker.Resolve().Do();
+
+ //Assert
+ Assert.AreEqual("hello", result);
+ }
+
+ [Test]
+ public void Resolve_with_dependency_doesnt_return_mock()
+ {
+ //Arrange
+ var mocker = new AutoMoqer();
+
+ //Act
+ var result = mocker.Resolve().VirtualMethod();
+
+ //Assert
+ Assert.AreEqual("hello", result);
+ }
+
+ [Test]
+ public void Resolve_with_mocked_dependency_uses_mock()
+ {
+ //Arrange
+ var mocker = new AutoMoqer();
+
+ mocker.GetMock()
+ .Setup(m => m.VirtualMethod())
+ .Returns("mocked");
+
+ //Act
+ var result = mocker.Resolve().CallVirtualChild();
+
+ //Assert
+ Assert.AreEqual("mocked", result);
+ }
+
+
+ [Test]
+ public void Resolve_with_unbound_concerete_dependency_uses_mock()
+ {
+ //Arrange
+ var mocker = new AutoMoqer();
+
+ //Act
+ var result = mocker.Resolve().CallVirtualChild();
+
+ var mockedResult = new Mock().Object.VirtualMethod();
+
+ //Assert
+ Assert.AreEqual(mockedResult, result);
+ }
+
+
+ [Test]
+ public void Resolve_with_constant_concerete_dependency_uses_constant()
+ {
+ //Arrange
+ var mocker = new AutoMoqer();
+
+ var constant = new VirtualDependency { PropValue = Guid.NewGuid().ToString() };
+
+ mocker.SetConstant(constant);
+
+ //Act
+ var result = mocker.Resolve().GetVirtualProperty();
+
+ //Assert
+ Assert.AreEqual(constant.PropValue, result);
+ }
+ }
+
+ public class ConcreteClass
+ {
+ public string Do()
+ {
+ return "hello";
+ }
+ }
+
+ public class Dependency : IDependency
+ {
+ }
+
+ public interface IDependency
+ {
+ }
+
+ public class ClassWithDependencies
+ {
+ public ClassWithDependencies(IDependency dependency)
+ {
+ Dependency = dependency;
+ }
+
+ public IDependency Dependency { get; set; }
+ }
+
+ public class ClassWithVirtualDependencies
+ {
+ private readonly VirtualDependency _virtualDependency;
+
+ public ClassWithVirtualDependencies(IDependency dependency, VirtualDependency virtualDependency)
+ {
+ _virtualDependency = virtualDependency;
+ Dependency = dependency;
+ }
+
+ public IDependency Dependency { get; set; }
+
+ public string CallVirtualChild()
+ {
+ return _virtualDependency.VirtualMethod();
+ }
+
+ public string GetVirtualProperty()
+ {
+ return _virtualDependency.PropValue;
+ }
+ }
+
+ public class VirtualDependency
+ {
+ private readonly IDependency _dependency;
+
+ public VirtualDependency()
+ {
+ }
+
+ public VirtualDependency(IDependency dependency)
+ {
+ _dependency = dependency;
+ }
+
+ public string PropValue { get; set; }
+
+ public virtual string VirtualMethod()
+ {
+ return "hello";
+ }
+ }
+}
\ No newline at end of file
diff --git a/NzbDrone.Update.Test/AutoMoq/License.txt b/NzbDrone.Update.Test/AutoMoq/License.txt
new file mode 100644
index 000000000..5ead6991a
--- /dev/null
+++ b/NzbDrone.Update.Test/AutoMoq/License.txt
@@ -0,0 +1,22 @@
+ Copyright (c) 2010 Darren Cauthon
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the "Software"), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
diff --git a/NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs b/NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs
new file mode 100644
index 000000000..af393fbee
--- /dev/null
+++ b/NzbDrone.Update.Test/AutoMoq/Unity/AutoMockingBuilderStrategy.cs
@@ -0,0 +1,84 @@
+// ReSharper disable RedundantUsingDirective
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using Microsoft.Practices.ObjectBuilder2;
+using Microsoft.Practices.Unity;
+using Moq;
+
+namespace AutoMoq.Unity
+{
+ internal class AutoMockingBuilderStrategy : BuilderStrategy
+ {
+ private readonly IUnityContainer _container;
+ private readonly MockRepository _mockFactory;
+ private readonly IEnumerable _registeredTypes;
+
+ public AutoMockingBuilderStrategy(IEnumerable registeredTypes, IUnityContainer container)
+ {
+ var autoMoqer = container.Resolve();
+ _mockFactory = new MockRepository(autoMoqer.DefaultBehavior);
+ _registeredTypes = registeredTypes;
+ _container = container;
+ }
+
+ public override void PreBuildUp(IBuilderContext context)
+ {
+ var autoMoqer = _container.Resolve();
+
+ var type = GetTheTypeFromTheBuilderContext(context);
+ if (AMockObjectShouldBeCreatedForThisType(type))
+ {
+ var mock = CreateAMockObject(type);
+ context.Existing = mock.Object;
+ autoMoqer.SetMock(type, mock);
+ }
+ }
+
+ #region private methods
+
+ private bool AMockObjectShouldBeCreatedForThisType(Type type)
+ {
+ var mocker = _container.Resolve();
+ return TypeIsNotRegistered(type) && (mocker.ResolveType == null || mocker.ResolveType != type);
+ //return TypeIsNotRegistered(type) && type.IsInterface;
+ }
+
+ private static Type GetTheTypeFromTheBuilderContext(IBuilderContext context)
+ {
+ return (context.OriginalBuildKey).Type;
+ }
+
+ private bool TypeIsNotRegistered(Type type)
+ {
+ return _registeredTypes.Any(x => x.Equals(type)) == false;
+ }
+
+ private Mock CreateAMockObject(Type type)
+ {
+ var createMethod = GenerateAnInterfaceMockCreationMethod(type);
+
+ return InvokeTheMockCreationMethod(createMethod);
+ }
+
+ private Mock InvokeTheMockCreationMethod(MethodInfo createMethod)
+ {
+ return (Mock)createMethod.Invoke(_mockFactory, new object[] { new List
@@ -137,7 +131,12 @@
true
-
+
+
+ {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}
+ NzbDrone.Common
+
+
diff --git a/NzbDrone/Providers/ConfigProvider.cs b/NzbDrone/Providers/ConfigProvider.cs
index 3e4cf5dd6..42074d2fb 100644
--- a/NzbDrone/Providers/ConfigProvider.cs
+++ b/NzbDrone/Providers/ConfigProvider.cs
@@ -6,6 +6,7 @@ using System.Xml.XPath;
using NLog;
using NLog.Config;
using Ninject;
+using NzbDrone.Common;
using NzbDrone.Model;
namespace NzbDrone.Providers
diff --git a/NzbDrone/Providers/IISProvider.cs b/NzbDrone/Providers/IISProvider.cs
index ce2478f7d..5f5bc5776 100644
--- a/NzbDrone/Providers/IISProvider.cs
+++ b/NzbDrone/Providers/IISProvider.cs
@@ -3,6 +3,8 @@ using System.Diagnostics;
using System.IO;
using NLog;
using Ninject;
+using NzbDrone.Common;
+using NzbDrone.Common.Model;
namespace NzbDrone.Providers
{
diff --git a/NzbDrone/Providers/MonitoringProvider.cs b/NzbDrone/Providers/MonitoringProvider.cs
index 1ebd317e8..821408ea1 100644
--- a/NzbDrone/Providers/MonitoringProvider.cs
+++ b/NzbDrone/Providers/MonitoringProvider.cs
@@ -5,6 +5,7 @@ using System.Timers;
using Exceptioneer.WindowsFormsClient;
using NLog;
using Ninject;
+using NzbDrone.Common;
namespace NzbDrone.Providers
{
diff --git a/NzbDrone/Providers/ServiceProvider.cs b/NzbDrone/Providers/ServiceProvider.cs
deleted file mode 100644
index 8667b28ad..000000000
--- a/NzbDrone/Providers/ServiceProvider.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-using System.Collections.Specialized;
-using System.Configuration.Install;
-using System.Linq;
-using System.Reflection;
-using System.ServiceProcess;
-using NLog;
-
-namespace NzbDrone.Providers
-{
- public class ServiceProvider
- {
- public const string NzbDroneServiceName = "NzbDrone";
-
- private static readonly Logger Logger = LogManager.GetLogger("Host.ServiceManager");
-
-
-
-
- public virtual bool ServiceExist(string name)
- {
- return
- ServiceController.GetServices().Any(
- s => String.Equals(s.ServiceName, name, StringComparison.InvariantCultureIgnoreCase));
- }
-
-
- public virtual void Install()
- {
- Logger.Info("Installing service '{0}'", NzbDroneServiceName);
-
-
- var installer = new ServiceProcessInstaller
- {
- Account = ServiceAccount.LocalSystem
- };
-
- var serviceInstaller = new ServiceInstaller();
-
-
- String[] cmdline = { @"/assemblypath=" + Assembly.GetExecutingAssembly().Location };
-
- var context = new InstallContext("service_install.log", cmdline);
- serviceInstaller.Context = context;
- serviceInstaller.DisplayName = NzbDroneServiceName;
- serviceInstaller.ServiceName = NzbDroneServiceName;
- serviceInstaller.Description = "NzbDrone Application Server";
- serviceInstaller.StartType = ServiceStartMode.Automatic;
-
- serviceInstaller.Parent = installer;
-
- serviceInstaller.Install(new ListDictionary());
-
- Logger.Info("Service Has installed successfully.");
- }
-
- public virtual void UnInstall()
- {
- var serviceInstaller = new ServiceInstaller();
-
- var context = new InstallContext("service_uninstall.log", null);
- serviceInstaller.Context = context;
- serviceInstaller.ServiceName = NzbDroneServiceName;
- serviceInstaller.Uninstall(null);
- }
-
-
- public virtual void Run(ServiceBase service)
- {
- ServiceBase.Run(service);
- }
- }
-}
\ No newline at end of file
diff --git a/NzbDrone/Router.cs b/NzbDrone/Router.cs
index 7e72b3906..a61b818e4 100644
--- a/NzbDrone/Router.cs
+++ b/NzbDrone/Router.cs
@@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
+using NzbDrone.Common;
using NzbDrone.Model;
-using NzbDrone.Providers;
namespace NzbDrone
{
diff --git a/packages/repositories.config b/packages/repositories.config
index c3ebed446..5219697f0 100644
--- a/packages/repositories.config
+++ b/packages/repositories.config
@@ -5,4 +5,7 @@
+
+
+
\ No newline at end of file