-
Notifications
You must be signed in to change notification settings - Fork 0
/
IoTPartitionMapperServiceTest.cs
74 lines (63 loc) · 2.74 KB
/
IoTPartitionMapperServiceTest.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
68
69
70
71
72
73
74
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using IotPartitionMapService;
using Microsoft.ServiceFabric.Data;
using System.Fabric;
using System.Threading.Tasks;
using Microsoft.ServiceFabric.Data.Collections;
using System.Numerics;
using Mocks;
using System.Collections.Generic;
namespace IoTPartitionMapper.Tests
{
public class MockIoTPartitionMapper : IoTPartitionMapperService
{
public MockIoTPartitionMapper(StatefulServiceContext context) : base(context)
{
}
public MockIoTPartitionMapper(StatefulServiceContext context, IReliableStateManagerReplica replica) : base(context, replica)
{
}
protected override Task<string[]> GetPartitionListAsync()
{
return Task.FromResult<string[]>(new string[] { "0", "1", "2", "3" });
}
internal IReliableStateManager MockStateManager()
{
return this.StateManager;
}
public static MockIoTPartitionMapper MockObjectFactory()
{
var context = new StatefulServiceContext(new NodeContext("192.168.11.10", new NodeId(new BigInteger(3), new BigInteger(1)), new BigInteger(1), "Node1", "some"), new Mock<ICodePackageActivationContext>().Object, "aaaType", new Uri("fabric:/aaa"), null, new Guid(), 1);
IReliableStateManagerReplica replica = new MockReliableStateManager();
return new MockIoTPartitionMapper(context, replica);
}
}
[TestClass]
public class IoTPartitionMapperServiceTest
{
private MockIoTPartitionMapper service;
[TestInitialize]
public void Initialize()
{
var context = new StatefulServiceContext(new NodeContext("192.168.11.10", new NodeId(new BigInteger(3), new BigInteger(1)), new BigInteger(1), "Node1", "some"), new Mock<ICodePackageActivationContext>().Object, "aaaType", new Uri("fabric:/aaa"), null, new Guid(), 1);
IReliableStateManagerReplica replica = new MockReliableStateManager();
service = new MockIoTPartitionMapper(context, replica);
}
[TestMethod]
public async Task TestSetupStateManagerAsync()
{
await service.SetUpIoTPartitionsAsync();
var state = service.MockStateManager();
var dictionary = await state.GetOrAddAsync<IReliableDictionary<string, string[]>>("MyDictionary");
var result = await dictionary.TryGetValueAsync(new MockTransaction(), "partitionList");
Console.WriteLine(result);
var expected = new string[] { "0", "1", "2", "3" };
for (var i = 0; i > result.Value.Length; i++)
{
Assert.AreEqual(expected[i], result.Value[i]);
}
}
}
}