-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
defa9c4
commit 1598c55
Showing
2 changed files
with
63 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Autofac; | ||
using Autofac.Extensions.DependencyInjection; | ||
using Autofac.Extras.DynamicProxy; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using NUnit.Framework; | ||
using SIL.XForge.DataAccess; | ||
using SIL.XForge.EventMetrics; | ||
|
||
namespace SIL.XForge.Services; | ||
|
||
[TestFixture] | ||
public class EventMetricLoggerTests | ||
{ | ||
[Test] | ||
public void MyTest_Success() | ||
{ | ||
var env = new TestEnvironment(); | ||
|
||
// SUT | ||
bool actual = env.TestClass.TestNoArguments(); | ||
Assert.IsTrue(actual); | ||
|
||
// TODO: The interceptor starts an asynchronous task, so we need to wait for that | ||
// Maybe use TaskCompletionSource? | ||
} | ||
|
||
private class TestEnvironment | ||
{ | ||
public TestEnvironment() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddSingleton<TestClass>(); | ||
var containerBuilder = new ContainerBuilder(); | ||
containerBuilder.Populate(services); | ||
containerBuilder.RegisterEventMetrics(); | ||
containerBuilder.RegisterEventMetrics<TestClass>(); | ||
containerBuilder.RegisterInstance(EventMetrics); | ||
containerBuilder.RegisterInstance<ILogger<EventMetric>>(MockLogger); | ||
var container = containerBuilder.Build(); | ||
EventMetricLogger = container.Resolve<EventMetricLogger>(); | ||
TestClass = container.Resolve<TestClass>(); | ||
} | ||
|
||
public EventMetricLogger EventMetricLogger { get; } | ||
public IRepository<EventMetric> EventMetrics { get; } = new MemoryRepository<EventMetric>(); | ||
public MockLogger<EventMetric> MockLogger { get; } = new MockLogger<EventMetric>(); | ||
public TestClass TestClass { get; } | ||
} | ||
|
||
/// <summary> | ||
/// The class that will test the interceptor. | ||
/// </summary> | ||
[Intercept(typeof(EventMetricLogger))] | ||
public class TestClass | ||
{ | ||
[LogEventMetric(EventScope.Drafting)] | ||
public virtual bool TestNoArguments() => true; | ||
} | ||
} |