diff --git a/appveyor.yml b/appveyor.yml
index 93cac22c2..0f341baed 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -14,6 +14,7 @@ before_build:
- gulp publish
build_script:
- dotnet build
+- dotnet xunit
after_build:
- dotnet publish -c Release -r win10-x64
- dotnet publish -c Release -r osx.10.12-x64
diff --git a/src/Ombi.Tests.Core/Ombi.Tests.Core.csproj b/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj
similarity index 75%
rename from src/Ombi.Tests.Core/Ombi.Tests.Core.csproj
rename to src/Ombi.Core.Tests/Ombi.Core.Tests.csproj
index 245cb749e..204b0d1b0 100644
--- a/src/Ombi.Tests.Core/Ombi.Tests.Core.csproj
+++ b/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj
@@ -5,16 +5,14 @@
-
-
+
-
diff --git a/src/Ombi.Core.Tests/Rule/AutoApproveRuleTests.cs b/src/Ombi.Core.Tests/Rule/AutoApproveRuleTests.cs
new file mode 100644
index 000000000..7f7202e3e
--- /dev/null
+++ b/src/Ombi.Core.Tests/Rule/AutoApproveRuleTests.cs
@@ -0,0 +1,87 @@
+using Ombi.Core.Rule.Rules;
+using Xunit;
+using System.Security.Principal;
+using Moq;
+using Ombi.Core.Models.Requests;
+using Ombi.Core.Claims;
+
+namespace Ombi.Core.Tests
+{
+ public class AutoApproveRuleTests
+ {
+ public AutoApproveRuleTests()
+ {
+ PrincipalMock = new Mock();
+ Rule = new AutoApproveRule(PrincipalMock.Object);
+ }
+
+ private AutoApproveRule Rule { get; }
+ private Mock PrincipalMock { get; }
+
+ [Fact]
+ public void Should_ReturnSuccess_WhenAdminAndRequestMovie()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ Assert.Equal(request.Approved, true);
+ }
+
+ [Fact]
+ public void Should_ReturnSuccess_WhenAdminAndRequestTV()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ Assert.Equal(request.Approved, true);
+ }
+
+ [Fact]
+ public void Should_ReturnSuccess_WhenAutoApproveMovieAndRequestMovie()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.AutoApproveMovie)).Returns(true);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ Assert.Equal(request.Approved, true);
+ }
+
+ [Fact]
+ public void Should_ReturnSuccess_WhenAutoApproveTVAndRequestTV()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.AutoApproveTv)).Returns(true);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ Assert.Equal(request.Approved, true);
+ }
+
+ [Fact]
+ public void Should_ReturnFail_WhenNoClaimsAndRequestMovie()
+ {
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ Assert.Equal(request.Approved, false);
+ }
+
+ [Fact]
+ public void Should_ReturnFail_WhenNoClaimsAndRequestTV()
+ {
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ Assert.Equal(request.Approved, false);
+ }
+
+
+ }
+}
diff --git a/src/Ombi.Core.Tests/Rule/CanRequestRuleTests.cs b/src/Ombi.Core.Tests/Rule/CanRequestRuleTests.cs
new file mode 100644
index 000000000..e7e8d11e3
--- /dev/null
+++ b/src/Ombi.Core.Tests/Rule/CanRequestRuleTests.cs
@@ -0,0 +1,83 @@
+using Ombi.Core.Rule.Rules;
+using Xunit;
+using System.Security.Principal;
+using Moq;
+using Ombi.Core.Models.Requests;
+using Ombi.Core.Claims;
+
+namespace Ombi.Core.Tests
+{
+ public class CanRequestRuleTests
+ {
+ public CanRequestRuleTests()
+ {
+ PrincipalMock = new Mock();
+ Rule = new CanRequestRule(PrincipalMock.Object);
+ }
+
+ private CanRequestRule Rule { get; }
+ private Mock PrincipalMock { get; }
+
+ [Fact]
+ public void Should_ReturnSuccess_WhenRequestingMovieWithMovieRole()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestMovie)).Returns(true);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ }
+
+ [Fact]
+ public void Should_ReturnFail_WhenRequestingMovieWithoutMovieRole()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestMovie)).Returns(false);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, false);
+ Assert.Equal(string.IsNullOrEmpty(result.Message), false);
+ }
+
+ [Fact]
+ public void Should_ReturnSuccess_WhenRequestingMovieWithAdminRole()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.Movie };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ }
+
+ [Fact]
+ public void Should_ReturnSuccess_WhenRequestingTVWithAdminRole()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.Admin)).Returns(true);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ }
+
+ [Fact]
+ public void Should_ReturnSuccess_WhenRequestingTVWithTVRole()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestTv)).Returns(true);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, true);
+ }
+
+ [Fact]
+ public void Should_ReturnFail_WhenRequestingTVWithoutTVRole()
+ {
+ PrincipalMock.Setup(x => x.IsInRole(OmbiClaims.RequestTv)).Returns(false);
+ var request = new BaseRequestModel() { Type = Store.Entities.RequestType.TvShow };
+ var result = Rule.Execute(request);
+
+ Assert.Equal(result.Success, false);
+ Assert.Equal(string.IsNullOrEmpty(result.Message), false);
+ }
+ }
+}
diff --git a/src/Ombi.Core/Rule/RuleEvaluator.cs b/src/Ombi.Core/Rule/RuleEvaluator.cs
index 4bc9ab955..010cea33c 100644
--- a/src/Ombi.Core/Rule/RuleEvaluator.cs
+++ b/src/Ombi.Core/Rule/RuleEvaluator.cs
@@ -2,6 +2,7 @@
using Ombi.Core.Rule;
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
namespace Ombi.Core.Rules
@@ -19,8 +20,17 @@ namespace Ombi.Core.Rules
{
if (ti?.BaseType?.FullName == baseType)
{
- var type = ti.GetType();
- var item = Activator.CreateInstance(ti.GetType(), provider.GetService(type));// ti.GetType is wrong
+ var type = ti.AsType();
+ var ctors = type.GetConstructors();
+ var ctor = ctors.FirstOrDefault();
+
+ var services = new List