diff --git a/NzbDrone.App.Test/ContainerFixture.cs b/NzbDrone.App.Test/ContainerFixture.cs index 55d64e82c..16bb5e02e 100644 --- a/NzbDrone.App.Test/ContainerFixture.cs +++ b/NzbDrone.App.Test/ContainerFixture.cs @@ -14,19 +14,19 @@ public class ContainerFixture : TestBase [Test] public void should_be_able_to_resolve_event_handlers() { - ContainerBuilder.Instance.Resolve>().Should().NotBeEmpty(); + ContainerBuilder.BuildNzbDroneContainer().Resolve>().Should().NotBeEmpty(); } [Test] public void should_be_able_to_resolve_indexers() { - ContainerBuilder.Instance.Resolve>().Should().NotBeEmpty(); + ContainerBuilder.BuildNzbDroneContainer().Resolve>().Should().NotBeEmpty(); } [Test] public void should_be_able_to_resolve_downlodclients() { - ContainerBuilder.Instance.Resolve>().Should().NotBeEmpty(); + ContainerBuilder.BuildNzbDroneContainer().Resolve>().Should().NotBeEmpty(); } } } \ No newline at end of file diff --git a/NzbDrone.Smoke.Test/NzbDrone.Smoke.Test.csproj b/NzbDrone.Smoke.Test/NzbDrone.Smoke.Test.csproj new file mode 100644 index 000000000..ff2fc301a --- /dev/null +++ b/NzbDrone.Smoke.Test/NzbDrone.Smoke.Test.csproj @@ -0,0 +1,116 @@ + + + + + Debug + AnyCPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB} + Library + Properties + NzbDrone.Smoke.Test + NzbDrone.Smoke.Test + v4.0 + 512 + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Exceptron.Client.1.0.20\lib\net20\Exceptron.Client.dll + + + ..\packages\Exceptron.NLog.1.0.11\lib\net20\Exceptron.NLog.dll + + + ..\packages\FluentAssertions.2.0.1\lib\net40\FluentAssertions.dll + + + ..\packages\Nancy.0.16.1\lib\net40\Nancy.dll + + + ..\packages\Nancy.Hosting.Self.0.16.1\lib\net40\Nancy.Hosting.Self.dll + + + ..\packages\NLog.2.0.1.2\lib\net40\NLog.dll + + + ..\packages\NUnit.2.6.2\lib\nunit.framework.dll + + + ..\packages\RestSharp.104.1\lib\net4\RestSharp.dll + + + + + + + + + + + + + + + + + App.config + + + + + + {FD286DF8-2D3A-4394-8AD5-443FADE55FB2} + NzbDrone.Api + + + {f2be0fdf-6e47-4827-a420-dd4ef82407f8} + NzbDrone.Common + + + {ff5ee3b6-913b-47ce-9ceb-11c51b4e1205} + NzbDrone.Core + + + {CADDFCE0-7509-4430-8364-2074E1EEFCA2} + NzbDrone.Test.Common + + + {d12f7f2f-8a3c-415f-88fa-6dd061a84869} + NzbDrone + + + + + sqlite3.dll + Always + + + + + + \ No newline at end of file diff --git a/NzbDrone.Smoke.Test/Properties/AssemblyInfo.cs b/NzbDrone.Smoke.Test/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..d0d4dd2e0 --- /dev/null +++ b/NzbDrone.Smoke.Test/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.Smoke.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("NzbDrone.Smoke.Test")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[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("8a49cb1d-87ac-42f9-a582-607365a6bd79")] + +// 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.Smoke.Test/SmokeTest.cs b/NzbDrone.Smoke.Test/SmokeTest.cs new file mode 100644 index 000000000..12ae34695 --- /dev/null +++ b/NzbDrone.Smoke.Test/SmokeTest.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using NUnit.Framework; +using NzbDrone.Api.Series; +using RestSharp; + +namespace NzbDrone.Smoke.Test +{ + [TestFixture] + public class SmokeTest : SmokeTestBase + { + [Test] + public void start_application() + { + Get>(new RestRequest("series")); + } + + [Test] + [Ignore] + public void add_series_without_required_fields_should_return_400() + { + var addSeriesRequest = new RestRequest("series") { RequestFormat = DataFormat.Json }; + addSeriesRequest.AddBody(new SeriesResource()); + Post(addSeriesRequest); + } + + } +} \ No newline at end of file diff --git a/NzbDrone.Smoke.Test/SmokeTestBase.cs b/NzbDrone.Smoke.Test/SmokeTestBase.cs new file mode 100644 index 000000000..6c8b5ca4d --- /dev/null +++ b/NzbDrone.Smoke.Test/SmokeTestBase.cs @@ -0,0 +1,124 @@ +using System; +using System.IO; +using System.Net; +using FluentAssertions; +using NLog; +using NLog.Config; +using NLog.Targets; +using NUnit.Framework; +using Nancy.Hosting.Self; +using NzbDrone.Api; +using NzbDrone.Common; +using RestSharp; +using TinyIoC; + +namespace NzbDrone.Smoke.Test +{ + [TestFixture] + public abstract class SmokeTestBase + { + private TinyNancyBootstrapper _bootstrapper; + private NancyHost _host; + protected RestClient RestClient { get; private set; } + + private static readonly Logger RestLogger = LogManager.GetLogger("REST: "); + private static readonly Logger Logger = LogManager.GetLogger("TEST: "); + private EnvironmentProvider _environmentProvider; + + protected TinyIoCContainer Container { get; private set; } + + + static SmokeTestBase() + { + if (LogManager.Configuration == null || LogManager.Configuration is XmlLoggingConfiguration) + { + LogManager.Configuration = new LoggingConfiguration(); + var consoleTarget = new ConsoleTarget { Layout = "${message} ${exception}" }; + LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget); + LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget)); + } + + + LogManager.ReconfigExistingLoggers(); + } + + + [SetUp] + public void SmokeTestSetup() + { + + _environmentProvider = new EnvironmentProvider(); + + if (Directory.Exists(_environmentProvider.GetAppDataPath())) + { + Directory.Delete(_environmentProvider.GetAppDataPath(), true); + } + + Logger.Info("Working Folder: {0}", _environmentProvider.WorkingDirectory); + Logger.Info("Data Folder: {0}", _environmentProvider.GetAppDataPath()); + Logger.Info("DB Path: {0}", _environmentProvider.GetNzbDroneDatabase()); + + + Container = ContainerBuilder.BuildNzbDroneContainer(); + _bootstrapper = new TinyNancyBootstrapper(Container); + + const string url = "http://localhost:1313"; + + _host = new NancyHost(new Uri(url), _bootstrapper); + + RestClient = new RestClient(url + "/api/"); + + + _host.Start(); + } + + [TearDown] + public void SmokeTestTearDown() + { + _host.Stop(); + } + + + protected T Get(IRestRequest request, HttpStatusCode statusCode = HttpStatusCode.OK) where T : class,new() + { + RestLogger.Info("GET: {0}", RestClient.BuildUri(request)); + + var response = RestClient.Get(request); + + RestLogger.Info("Response: {0}", response.Content); + + if (response.ErrorException != null) + { + throw response.ErrorException; + } + + response.ErrorMessage.Should().BeBlank(); + + response.StatusCode.Should().Be(statusCode); + + return response.Data; + } + + protected T Post(IRestRequest request, HttpStatusCode statusCode = HttpStatusCode.Created) where T : class,new() + { + RestLogger.Info("POST: {0}", RestClient.BuildUri(request)); + + var response = RestClient.Post(request); + + RestLogger.Info("Response: {0}", response.Content); + + if (response.ErrorException != null) + { + throw response.ErrorException; + } + + response.ErrorMessage.Should().BeBlank(); + + + response.StatusCode.Should().Be(statusCode); + + return response.Data; + } + + } +} diff --git a/NzbDrone.Smoke.Test/packages.config b/NzbDrone.Smoke.Test/packages.config new file mode 100644 index 000000000..00794e13d --- /dev/null +++ b/NzbDrone.Smoke.Test/packages.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index 8411a0249..daf500e89 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -31,9 +31,6 @@ public static void Main(string[] args) builder.RegisterAssemblyTypes(typeof(RestProvider).Assembly).SingleInstance(); _container = builder.Build(); - ReportingService.RestProvider = _container.Resolve(); - - logger.Info("Updating NzbDrone to version {0}", _container.Resolve().Version); _container.Resolve().Start(args); } diff --git a/NzbDrone.sln b/NzbDrone.sln index 23e96d1fd..10390a73c 100644 --- a/NzbDrone.sln +++ b/NzbDrone.sln @@ -48,6 +48,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marr.Data", "Marr.Data\Marr EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Libraries.Test", "NzbDrone.Libraries.Test\NzbDrone.Libraries.Test.csproj", "{CBF6B8B0-A015-413A-8C86-01238BB45770}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Smoke.Test", "NzbDrone.Smoke.Test\NzbDrone.Smoke.Test.csproj", "{8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -258,6 +260,16 @@ Global {CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|Mixed Platforms.Build.0 = Release|Any CPU {CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|x86.ActiveCfg = Release|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|x86.ActiveCfg = Debug|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Any CPU.Build.0 = Release|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -270,6 +282,7 @@ Global {BEC74619-DDBB-4FBA-B517-D3E20AFC9997} = {57A04B72-8088-4F75-A582-1158CF8291F7} {D18A5DEB-5102-4775-A1AF-B75DAAA8907B} = {57A04B72-8088-4F75-A582-1158CF8291F7} {CBF6B8B0-A015-413A-8C86-01238BB45770} = {57A04B72-8088-4F75-A582-1158CF8291F7} + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB} = {57A04B72-8088-4F75-A582-1158CF8291F7} {FAFB5948-A222-4CF6-AD14-026BE7564802} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97} {CADDFCE0-7509-4430-8364-2074E1EEFCA2} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97} {6BCE712F-846D-4846-9D1B-A66B858DA755} = {F9E67978-5CD6-4A5F-827B-4249711C0B02} diff --git a/NzbDrone/AppMain.cs b/NzbDrone/AppMain.cs index 0b8c1c4f4..11014e85c 100644 --- a/NzbDrone/AppMain.cs +++ b/NzbDrone/AppMain.cs @@ -41,7 +41,9 @@ public static void Main(string[] args) return; } - ContainerBuilder.Instance.Resolve().Route(args); + var container = ContainerBuilder.BuildNzbDroneContainer(); + + container.Resolve().Route(args); } catch (Exception e) { diff --git a/NzbDrone/ContainerBuilder.cs b/NzbDrone/ContainerBuilder.cs index 07eec9ccf..002366a0b 100644 --- a/NzbDrone/ContainerBuilder.cs +++ b/NzbDrone/ContainerBuilder.cs @@ -21,18 +21,20 @@ namespace NzbDrone public static class ContainerBuilder { private static readonly Logger Logger = LogManager.GetLogger("ContainerBuilder"); - public static TinyIoCContainer Instance { get; private set; } private static readonly List NzbDroneTypes; static ContainerBuilder() { - var container = new TinyIoCContainer(); - NzbDroneTypes = new List(); NzbDroneTypes.AddRange(Assembly.Load("NzbDrone").GetTypes()); NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Common").GetTypes()); NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Core").GetTypes()); NzbDroneTypes.AddRange(Assembly.Load("NzbDrone.Api").GetTypes()); + } + + public static TinyIoCContainer BuildNzbDroneContainer() + { + var container = new TinyIoCContainer(); container.AutoRegisterInterfaces(); @@ -48,7 +50,9 @@ static ContainerBuilder() container.InitDatabase(); - Instance = container; + ReportingService.RestProvider = container.Resolve(); + + return container; } private static void InitDatabase(this TinyIoCContainer container) @@ -58,7 +62,7 @@ private static void InitDatabase(this TinyIoCContainer container) //TODO: move this to factory var environmentProvider = new EnvironmentProvider(); var appDataPath = environmentProvider.GetAppDataPath(); - + if (!Directory.Exists(appDataPath)) { Directory.CreateDirectory(appDataPath); diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index ae628352f..538ad4313 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -119,7 +119,6 @@ Component - diff --git a/NzbDrone/NzbDroneBootstrapper.cs b/NzbDrone/NzbDroneBootstrapper.cs deleted file mode 100644 index 2b1cd20fe..000000000 --- a/NzbDrone/NzbDroneBootstrapper.cs +++ /dev/null @@ -1,28 +0,0 @@ -using NLog; -using NzbDrone.Common; -using TinyIoC; -using NzbDrone.Core; -using NzbDrone.Api; - -namespace NzbDrone -{ - public static class NzbDroneBootstrapper - { - private static readonly Logger logger = LogManager.GetLogger("NzbDroneBootstrapper"); - - static NzbDroneBootstrapper() - { - InitializeApp(); - } - - - private static void InitializeApp() - { - var environmentProvider = ContainerBuilder.Instance.Resolve(); - - ReportingService.RestProvider = ContainerBuilder.Instance.Resolve(); - - logger.Info("Start-up Path:'{0}'", environmentProvider.WorkingDirectory); - } - } -}