-
Notifications
You must be signed in to change notification settings - Fork 36
/
IntegrationTestBase.cs
67 lines (60 loc) · 2.81 KB
/
IntegrationTestBase.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using MongoDB.Driver;
using NUnit.Framework;
using W3C.Domain.MatchmakingService;
using W3ChampionsStatisticService.Services;
namespace WC3ChampionsStatisticService.Tests
{
public class IntegrationTestBase
{
//protected readonly MongoClient MongoClient = new MongoClient("mongodb://localhost:27017/");
protected readonly MongoClient MongoClient = new MongoClient("mongodb://157.90.1.251:3512/");
protected PersonalSettingsProvider personalSettingsProvider;
[SetUp]
public async Task Setup()
{
await MongoClient.DropDatabaseAsync("W3Champions-Statistic-Service");
personalSettingsProvider= new PersonalSettingsProvider(MongoClient);
}
protected async Task InsertMatchEvents(List<MatchFinishedEvent> newEvents)
{
foreach (var ev in newEvents)
{
await InsertMatchEvent(ev);
}
}
protected async Task InsertMatchEvent(MatchFinishedEvent newEvent)
{
var database = MongoClient.GetDatabase("W3Champions-Statistic-Service");
var mongoDatabase = database;
var mongoCollection = mongoDatabase.GetCollection<MatchFinishedEvent>(nameof(MatchFinishedEvent));
await mongoCollection.FindOneAndReplaceAsync(
(Expression<Func<MatchFinishedEvent, bool>>) (ev => ev.match.id == newEvent.match.id),
newEvent,
new FindOneAndReplaceOptions<MatchFinishedEvent> {IsUpsert = true});
}
protected async Task InsertMatchStartedEvent(MatchStartedEvent newEvent)
{
var database = MongoClient.GetDatabase("W3Champions-Statistic-Service");
var mongoDatabase = database;
var mongoCollection = mongoDatabase.GetCollection<MatchStartedEvent>(nameof(MatchStartedEvent));
await mongoCollection.FindOneAndReplaceAsync(
(Expression<Func<MatchStartedEvent, bool>>) (ev => ev.match.id == newEvent.match.id),
newEvent,
new FindOneAndReplaceOptions<MatchStartedEvent> {IsUpsert = true});
}
protected async Task InsertRankChangedEvent(RankingChangedEvent newEvent)
{
var database = MongoClient.GetDatabase("W3Champions-Statistic-Service");
var mongoDatabase = database;
var mongoCollection = mongoDatabase.GetCollection<RankingChangedEvent>(nameof(RankingChangedEvent));
await mongoCollection.FindOneAndReplaceAsync(
(Expression<Func<RankingChangedEvent, bool>>) (ev => ev.id == newEvent.id),
newEvent,
new FindOneAndReplaceOptions<RankingChangedEvent> {IsUpsert = true});
}
}
}