-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMockUtils.cs
More file actions
38 lines (37 loc) · 1.18 KB
/
MockUtils.cs
File metadata and controls
38 lines (37 loc) · 1.18 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CogniteSdk;
namespace Cognite.Extractor.Testing.Mock
{
/// <summary>
/// Common utilities for mock implementations of CDF APIs.
/// </summary>
public class MockUtils
{
/// <summary>
/// Convert an Identity to a dictionary used in error responses.
/// </summary>
/// <param name="id">Identity to convert</param>
/// <returns>Multivalue dictionary</returns>
public static Dictionary<string, MultiValue> ToMultiValueDict(Identity id)
{
if (id == null) throw new ArgumentNullException(nameof(id));
var dict = new Dictionary<string, MultiValue>();
if (id.Id.HasValue)
{
dict["id"] = MultiValue.Create(id.Id.Value);
}
else if (id.InstanceId != null)
{
dict["instanceId"] = MultiValue.Create(id.InstanceId);
}
else if (!string.IsNullOrEmpty(id.ExternalId))
{
dict["externalId"] = MultiValue.Create(id.ExternalId);
}
return dict;
}
}
}