-
Notifications
You must be signed in to change notification settings - Fork 24
/
EventMock.cs
41 lines (36 loc) · 1.36 KB
/
EventMock.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Keen.Core.EventCache;
using Newtonsoft.Json.Linq;
namespace Keen.Core.Test
{
/// <summary>
/// EventMock provides an implementation of IEvent with a constructor that
/// accepts delegates for each of the interface methods.
/// The purpose of this is to allow test methods to set up a customized
/// IEvent for each test.
/// </summary>
class EventMock : IEvent
{
private readonly IProjectSettings _settings;
private readonly Func<IProjectSettings, JArray> _getSchemas;
private readonly Func<JObject, IProjectSettings, IEnumerable<CachedEvent>> _addEvents;
public Task<JArray> GetSchemas()
{
return Task.Run(() => _getSchemas(_settings));
}
public Task<IEnumerable<CachedEvent>> AddEvents(JObject events)
{
return Task.Run(() => _addEvents(events, _settings));
}
public EventMock(IProjectSettings prjSettings,
Func<IProjectSettings, JArray> getSchemas = null,
Func<JObject, IProjectSettings, IEnumerable<CachedEvent>> addEvents = null)
{
_settings = prjSettings;
_getSchemas = getSchemas ?? ((p) => new JArray());
_addEvents = addEvents ?? ((p, e) => new List<CachedEvent>());
}
}
}