-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- split daemon up into multiple implementations - daemons now use cronmask to tick
- Loading branch information
1 parent
e60e056
commit 73429ed
Showing
21 changed files
with
428 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Moq; | ||
using Ninject; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Tetrifact.Tests | ||
{ | ||
public class MoqHelper | ||
{ | ||
private static MockRepository repo = new MockRepository(MockBehavior.Loose) { CallBase = true }; | ||
|
||
public static Mock CreateMock(Type typeToMock) | ||
{ | ||
var creator = typeof(Mock<>).MakeGenericType(typeToMock); | ||
return (Mock)Activator.CreateInstance(creator); | ||
} | ||
|
||
public static IEnumerable<object> CtorArgs(Type t, object overrid, bool forceMock) | ||
{ | ||
return CtorArgs(t, new object[] { overrid }, forceMock); | ||
} | ||
|
||
public static IEnumerable<object> CtorArgs(Type t, object[] overrides, bool forceMock) | ||
{ | ||
ConstructorInfo ctor = t.GetConstructors().FirstOrDefault(); | ||
if (ctor == null) | ||
throw new Exception("no ctor found"); | ||
|
||
StandardKernel kernel = NinjectHelper.Kernel(); | ||
|
||
List<object> args = new List<object>(); | ||
foreach (ParameterInfo p in ctor.GetParameters()) | ||
{ | ||
object arg = overrides.Where(r => r.GetType() == p.ParameterType).SingleOrDefault(); | ||
if (arg == null) | ||
arg = overrides.Where(r => p.ParameterType.IsAssignableFrom(r.GetType())).SingleOrDefault(); | ||
|
||
try | ||
{ | ||
if (arg == null && !forceMock) | ||
arg = kernel.Get(p.ParameterType); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// ignore | ||
} | ||
|
||
try | ||
{ | ||
arg = CreateMock(p.ParameterType).Object; | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new Exception($"failed to create ctor arg with both ninject and moq, type {t.Name}, parameter {p.ParameterType}", ex); | ||
} | ||
|
||
args.Add(arg); | ||
} | ||
|
||
return args; | ||
} | ||
|
||
public static T WithAllMocked<T>() where T : class | ||
{ | ||
return repo.Create<T>(CtorArgs(typeof(T), new object[]{ }, true).ToArray()).Object; | ||
} | ||
|
||
public static T With<T>(Mock dependencyMock) where T : class | ||
{ | ||
return repo.Create<T>(CtorArgs(typeof(T), dependencyMock.Object, false).ToArray()).Object; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Tetrifact.Web; | ||
|
||
namespace Tetrifact.Tests | ||
{ | ||
public class TestDaemon : IDaemon | ||
{ | ||
public void Dispose() | ||
{ | ||
|
||
} | ||
|
||
public void Start(Cron Daemon) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Moq; | ||
using System; | ||
using Tetrifact.Core; | ||
using Xunit; | ||
using W=Tetrifact.Web; | ||
|
||
namespace Tetrifact.Tests.Web.Core.Daemon | ||
{ | ||
public class Start : TestBase | ||
{ | ||
/// <summary> | ||
/// Coverage test | ||
/// </summary> | ||
[Fact] | ||
public void Happy_path() | ||
{ | ||
var cleanerCron = MoqHelper.WithAllMocked<W.CleanerCron>(); | ||
cleanerCron.Work(); | ||
} | ||
|
||
/// <summary> | ||
/// Coverage test | ||
/// </summary> | ||
[Fact] | ||
public void Archive_Exception() | ||
{ | ||
var archiveService = new Mock<IArchiveService>(); | ||
archiveService | ||
.Setup(r => r.PurgeOldArchives()) | ||
.Throws(new Exception("some error")); | ||
|
||
var cleanerCron = MoqHelper.With<W.CleanerCron>(archiveService); | ||
cleanerCron.Work(); | ||
} | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.