|
1 | | -using System; |
2 | | -using System.Collections; |
3 | | -using System.Collections.Generic; |
4 | | -using System.Text; |
| 1 | +namespace Microsoft.Graph.Authentication.Test.Helpers |
| 2 | +{ |
5 | 3 |
|
6 | | -using Microsoft.Graph.PowerShell.Authentication.Helpers; |
| 4 | + using System.Collections; |
| 5 | + using System.Collections.Generic; |
| 6 | + using System.Management.Automation; |
7 | 7 |
|
8 | | -using Xunit; |
| 8 | + using Microsoft.Graph.PowerShell.Authentication.Helpers; |
| 9 | + |
| 10 | + using Xunit; |
9 | 11 |
|
10 | | -namespace Microsoft.Graph.Authentication.Test.Helpers |
11 | | -{ |
12 | 12 | public class StringUtilTests |
13 | 13 | { |
14 | 14 | private const string TestJsonArray = "{\"@odata.context\": \"https://graph.microsoft.com/v1.0/$metadata#users\"," + "\"value\": [{\"id\": \"6e7b768e-07e2-4810-8459-485f84f8f204\"},{\"id\": \"87d349ed-44d7-43e1-9a83-5f2406dee5bd\"}]}"; |
15 | 15 |
|
16 | 16 | private const string TestJsonObject = "{\"@odata.context\": \"https://graph.microsoft.com/v1.0/$metadata#users/$entity\",\"businessPhones\": [\"+1 412 555 0109\"],\"displayName\": \"Megan Bowen\",\"givenName\": \"Megan\",\"jobTitle\": \"Auditor\",\"mail\": \"MeganB@M365x214355.onmicrosoft.com\", \"mobilePhone\": null, \"officeLocation\": \"12/1110\",\"preferredLanguage\": \"en-US\",\"surname\": \"Bowen\",\"userPrincipalName\": \"MeganB@M365x214355.onmicrosoft.com\",\"id\": \"48d31887-5fad-4d73-a9f5-3c356e68a038\"}"; |
| 17 | + public static IEnumerable<object[]> TestJsonData => |
| 18 | + new List<object[]> |
| 19 | + { |
| 20 | + new object[] { TestJsonArray}, |
| 21 | + new object[] { TestJsonObject} |
| 22 | + }; |
17 | 23 |
|
18 | 24 | [Theory] |
19 | 25 | [MemberData(nameof(TestJsonData))] |
20 | 26 | public void ShouldReturnCaseInsensitiveDictionaries(string jsonString) |
21 | 27 | { |
22 | | - Exception ex = null; |
23 | | - var converted = jsonString.TryConvertToJson(out var jsonObj, ref ex); |
| 28 | + var hashTable = jsonString.ConvertFromJson(true, null, out _); |
24 | 29 |
|
25 | | - Assert.True(converted); |
26 | | - Assert.IsType<Hashtable>(jsonObj); |
27 | | - var jsonHashTable = (Hashtable)jsonObj; |
| 30 | + Assert.NotNull(hashTable); |
| 31 | + var jsonHashTable = (Hashtable)hashTable; |
28 | 32 | Assert.Equal(jsonHashTable["Value"], jsonHashTable["value"]); |
29 | 33 | } |
30 | | - public static IEnumerable<object[]> TestJsonData => |
31 | | - new List<object[]> |
32 | | - { |
33 | | - new object[] { TestJsonArray}, |
34 | | - new object[] { TestJsonObject} |
35 | | - }; |
| 34 | + |
| 35 | + [Theory] |
| 36 | + [MemberData(nameof(TestJsonData))] |
| 37 | + public void ShouldReturnPsObject(string jsonString) |
| 38 | + { |
| 39 | + var psObject = jsonString.ConvertFromJson(false, null, out _); |
| 40 | + |
| 41 | + Assert.NotNull(psObject); |
| 42 | + Assert.IsType<PSObject>(psObject); |
| 43 | + } |
| 44 | + |
| 45 | + [Theory] |
| 46 | + [MemberData(nameof(TestJsonData))] |
| 47 | + public void ShouldReturnHashTable(string jsonString) |
| 48 | + { |
| 49 | + var hashTable = jsonString.ConvertFromJson(true, null, out _); |
| 50 | + |
| 51 | + Assert.NotNull(hashTable); |
| 52 | + Assert.IsType<Hashtable>(hashTable); |
| 53 | + } |
36 | 54 | } |
37 | 55 | } |
0 commit comments