microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
Tests/Microsoft.Teams.Api.Tests/Activities/Invokes/MessageExtensions/QuerySettingsUrlMEActivityTests.cs
173lines · modecode
| 1 | using System.Text.Json; |
| 2 | |
| 3 | using Microsoft.Teams.Api.Activities; |
| 4 | using Microsoft.Teams.Api.Activities.Invokes; |
| 5 | using Microsoft.Teams.Api.Entities; |
| 6 | using Microsoft.Teams.Api.MessageExtensions; |
| 7 | |
| 8 | using static Microsoft.Teams.Api.Activities.Invokes.MessageExtensions; |
| 9 | |
| 10 | namespace Microsoft.Teams.Api.Tests.Activities.Invokes; |
| 11 | |
| 12 | public class QuerySettingsUrlMEActivityTests |
| 13 | { |
| 14 | private QuerySettingUrlActivity SetupQuerySettingsUrlActivity() |
| 15 | { |
| 16 | IList<IEntity> _entityList = |
| 17 | [ |
| 18 | new ClientInfoEntity() |
| 19 | { |
| 20 | Platform = "Windows", |
| 21 | Locale = "en-US", |
| 22 | Country = "US", |
| 23 | Timezone = "GMT-8", |
| 24 | } |
| 25 | ]; |
| 26 | return new QuerySettingUrlActivity() |
| 27 | { |
| 28 | Value = new Query() |
| 29 | { |
| 30 | CommandId = "searchCmd", |
| 31 | Parameters = new List<Parameter>() |
| 32 | { |
| 33 | new Parameter() |
| 34 | { |
| 35 | Name = "Somelist", |
| 36 | Value = "Toronto" |
| 37 | } |
| 38 | }, |
| 39 | }, |
| 40 | Conversation = new Api.Conversation() |
| 41 | { |
| 42 | Id = "convId", |
| 43 | Type = ConversationType.Personal |
| 44 | }, |
| 45 | Id = "id:data", |
| 46 | ServiceUrl = "https://me-url", |
| 47 | From = new Account() |
| 48 | { |
| 49 | Id = "botId", |
| 50 | Name = "User Name", |
| 51 | AadObjectId = "aadObjectId" |
| 52 | }, |
| 53 | Recipient = new Account() |
| 54 | { |
| 55 | Id = "recipientId", |
| 56 | Name = "Recipient Name", |
| 57 | }, |
| 58 | Entities = _entityList, |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | [Fact] |
| 63 | public void QuerySettingsUrlMEActivity_JsonSerialize() |
| 64 | { |
| 65 | var activity = SetupQuerySettingsUrlActivity(); |
| 66 | |
| 67 | var json = JsonSerializer.Serialize(activity, new JsonSerializerOptions() |
| 68 | { |
| 69 | WriteIndented = true, |
| 70 | IndentSize = 2, |
| 71 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 72 | }); |
| 73 | |
| 74 | string expectedPath = "Activity.Invoke.ComposeExtension/querySettingUrl"; |
| 75 | Assert.Equal(expectedPath, activity.GetPath()); |
| 76 | Assert.Equal(File.ReadAllText( |
| 77 | @"../../../Json/Activity/Invokes/QuerySettingUrlMEActivity.json" |
| 78 | ), json); |
| 79 | } |
| 80 | |
| 81 | [Fact] |
| 82 | public void QuerySettingsUrlMEActivity_JsonSerialize_Derived() |
| 83 | { |
| 84 | MessageExtensionActivity activity = SetupQuerySettingsUrlActivity(); |
| 85 | |
| 86 | var json = JsonSerializer.Serialize(activity, new JsonSerializerOptions() |
| 87 | { |
| 88 | WriteIndented = true, |
| 89 | IndentSize = 2, |
| 90 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 91 | }); |
| 92 | |
| 93 | string expectedPath = "Activity.Invoke.ComposeExtension/querySettingUrl"; |
| 94 | Assert.Equal(expectedPath, activity.GetPath()); |
| 95 | Assert.Equal(File.ReadAllText( |
| 96 | @"../../../Json/Activity/Invokes/QuerySettingUrlMEActivity.json" |
| 97 | ), json); |
| 98 | } |
| 99 | |
| 100 | [Fact] |
| 101 | public void QuerySettingsUrlMEActivity_JsonSerialize_Derived_Interface() |
| 102 | { |
| 103 | InvokeActivity activity = SetupQuerySettingsUrlActivity(); |
| 104 | |
| 105 | var json = JsonSerializer.Serialize(activity, new JsonSerializerOptions() |
| 106 | { |
| 107 | WriteIndented = true, |
| 108 | IndentSize = 2, |
| 109 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 110 | }); |
| 111 | |
| 112 | string expectedPath = "Activity.Invoke.ComposeExtension/querySettingUrl"; |
| 113 | Assert.Equal(expectedPath, activity.GetPath()); |
| 114 | Assert.Equal(File.ReadAllText( |
| 115 | @"../../../Json/Activity/Invokes/QuerySettingUrlMEActivity.json" |
| 116 | ), json); |
| 117 | } |
| 118 | |
| 119 | [Fact] |
| 120 | public void QuerySettingsUrlMEActivity_JsonDeserialize() |
| 121 | { |
| 122 | var json = File.ReadAllText(@"../../../Json/Activity/Invokes/QuerySettingUrlMEActivity.json"); |
| 123 | var activity = JsonSerializer.Deserialize<QuerySettingUrlActivity>(json); |
| 124 | var expected = SetupQuerySettingsUrlActivity(); |
| 125 | |
| 126 | string expectedPath = "Activity.Invoke.ComposeExtension/querySettingUrl"; |
| 127 | Assert.Equal(expectedPath, activity!.GetPath()); |
| 128 | |
| 129 | Assert.Equal(expected.ToString(), activity.ToString()); |
| 130 | Assert.NotNull(activity.ToMessageExtension()); |
| 131 | } |
| 132 | |
| 133 | [Fact] |
| 134 | public void QuerySettingsUrlMEActivity_JsonDeserialize_Derived() |
| 135 | { |
| 136 | var json = File.ReadAllText(@"../../../Json/Activity/Invokes/QuerySettingUrlMEActivity.json"); |
| 137 | var activity = JsonSerializer.Deserialize<MessageExtensionActivity>(json); |
| 138 | var expected = SetupQuerySettingsUrlActivity(); |
| 139 | |
| 140 | Assert.Equal(expected.ToString(), activity!.ToString()); |
| 141 | Assert.NotNull(activity.ToMessageExtension()); |
| 142 | var expectedSubmitException = "Unable to cast object of type 'QuerySettingUrlActivity' to type 'Microsoft.Teams.Api.Activities.Invokes.TaskActivity'."; |
| 143 | var ex = Assert.Throws<System.InvalidCastException>(() => activity.ToTask()); |
| 144 | Assert.Equal(expectedSubmitException, ex.Message); |
| 145 | } |
| 146 | |
| 147 | [Fact] |
| 148 | public void QuerySettingsUrlMEActivity_JsonDeserialize_Derived_Interface() |
| 149 | { |
| 150 | var json = File.ReadAllText(@"../../../Json/Activity/Invokes/QuerySettingUrlMEActivity.json"); |
| 151 | var activity = JsonSerializer.Deserialize<InvokeActivity>(json); |
| 152 | var expected = SetupQuerySettingsUrlActivity(); |
| 153 | |
| 154 | Assert.NotNull(activity); |
| 155 | Assert.Equal(expected.ToString(), activity.ToString()); |
| 156 | Assert.NotNull(activity.ToMessageExtension()); |
| 157 | |
| 158 | var expectedSubmitException = "Unable to cast object of type 'QuerySettingUrlActivity' to type 'Microsoft.Teams.Api.Activities.Invokes.SignInActivity'."; |
| 159 | var ex = Assert.Throws<System.InvalidCastException>(() => activity.ToSignIn()); |
| 160 | Assert.Equal(expectedSubmitException, ex.Message); |
| 161 | } |
| 162 | |
| 163 | [Fact] |
| 164 | public void QuerySettingsUrlMEActivity_JsonDeserialize_Derived_Activity_Interface() |
| 165 | { |
| 166 | var json = File.ReadAllText(@"../../../Json/Activity/Invokes/QuerySettingUrlMEActivity.json"); |
| 167 | var activity = JsonSerializer.Deserialize<Activity>(json); |
| 168 | var expected = SetupQuerySettingsUrlActivity(); |
| 169 | |
| 170 | Assert.NotNull(activity); |
| 171 | Assert.Equal(expected.ToString(), activity.ToString()); |
| 172 | } |
| 173 | } |