microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Tests/Microsoft.Teams.Api.Tests/Activities/Message/MessageUpdateActivityTests.cs
179lines · modecode
| 1 | using System.Text.Json; |
| 2 | |
| 3 | using Microsoft.Teams.Api.Activities; |
| 4 | |
| 5 | namespace Microsoft.Teams.Api.Tests.Activities; |
| 6 | |
| 7 | public class MessageUpdateActivityTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void JsonSerialize() |
| 11 | { |
| 12 | var activity = new MessageUpdateActivity("test") |
| 13 | { |
| 14 | Id = "1", |
| 15 | From = new() |
| 16 | { |
| 17 | Id = "1", |
| 18 | Name = "test", |
| 19 | Role = Role.User |
| 20 | }, |
| 21 | Conversation = new() |
| 22 | { |
| 23 | Id = "1", |
| 24 | Type = ConversationType.Personal |
| 25 | }, |
| 26 | Recipient = new() |
| 27 | { |
| 28 | Id = "2", |
| 29 | Name = "test-bot", |
| 30 | Role = Role.Bot |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | var json = JsonSerializer.Serialize(activity, new JsonSerializerOptions() |
| 35 | { |
| 36 | WriteIndented = true, |
| 37 | IndentSize = 4, |
| 38 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 39 | }); |
| 40 | |
| 41 | Assert.Equal(File.ReadAllText( |
| 42 | @"../../../Json/Activity/Message/MessageUpdateActivity.json" |
| 43 | ), json); |
| 44 | } |
| 45 | |
| 46 | [Fact] |
| 47 | public void JsonSerialize_Derived() |
| 48 | { |
| 49 | MessageUpdateActivity activity = new MessageUpdateActivity("test") |
| 50 | { |
| 51 | Id = "1", |
| 52 | From = new() |
| 53 | { |
| 54 | Id = "1", |
| 55 | Name = "test", |
| 56 | Role = Role.User |
| 57 | }, |
| 58 | Conversation = new() |
| 59 | { |
| 60 | Id = "1", |
| 61 | Type = ConversationType.Personal |
| 62 | }, |
| 63 | Recipient = new() |
| 64 | { |
| 65 | Id = "2", |
| 66 | Name = "test-bot", |
| 67 | Role = Role.Bot |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | var json = JsonSerializer.Serialize(activity, new JsonSerializerOptions() |
| 72 | { |
| 73 | WriteIndented = true, |
| 74 | IndentSize = 4, |
| 75 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 76 | }); |
| 77 | |
| 78 | Assert.Equal(File.ReadAllText( |
| 79 | @"../../../Json/Activity/Message/MessageUpdateActivity.json" |
| 80 | ), json); |
| 81 | } |
| 82 | |
| 83 | [Fact] |
| 84 | public void JsonSerialize_Derived_Interface() |
| 85 | { |
| 86 | Activity activity = new MessageUpdateActivity("test") |
| 87 | { |
| 88 | Id = "1", |
| 89 | From = new() |
| 90 | { |
| 91 | Id = "1", |
| 92 | Name = "test", |
| 93 | Role = Role.User |
| 94 | }, |
| 95 | Conversation = new() |
| 96 | { |
| 97 | Id = "1", |
| 98 | Type = ConversationType.Personal |
| 99 | }, |
| 100 | Recipient = new() |
| 101 | { |
| 102 | Id = "2", |
| 103 | Name = "test-bot", |
| 104 | Role = Role.Bot |
| 105 | } |
| 106 | }; |
| 107 | |
| 108 | var json = JsonSerializer.Serialize(activity, new JsonSerializerOptions() |
| 109 | { |
| 110 | WriteIndented = true, |
| 111 | IndentSize = 4, |
| 112 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 113 | }); |
| 114 | |
| 115 | Assert.Equal(File.ReadAllText( |
| 116 | @"../../../Json/Activity/Message/MessageUpdateActivity.json" |
| 117 | ), json); |
| 118 | } |
| 119 | |
| 120 | [Fact] |
| 121 | public void JsonDeserialize() |
| 122 | { |
| 123 | var json = File.ReadAllText(@"../../../Json/Activity/Message/MessageUpdateActivity.json"); |
| 124 | var activity = JsonSerializer.Deserialize<MessageUpdateActivity>(json); |
| 125 | var expected = new MessageUpdateActivity("test") |
| 126 | { |
| 127 | Id = "1", |
| 128 | From = new() |
| 129 | { |
| 130 | Id = "1", |
| 131 | Name = "test", |
| 132 | Role = Role.User |
| 133 | }, |
| 134 | Conversation = new() |
| 135 | { |
| 136 | Id = "1", |
| 137 | Type = ConversationType.Personal |
| 138 | }, |
| 139 | Recipient = new() |
| 140 | { |
| 141 | Id = "2", |
| 142 | Name = "test-bot", |
| 143 | Role = Role.Bot |
| 144 | } |
| 145 | }; |
| 146 | |
| 147 | Assert.Equivalent(expected, activity); |
| 148 | } |
| 149 | |
| 150 | [Fact] |
| 151 | public void JsonDeserialize_Derived() |
| 152 | { |
| 153 | var json = File.ReadAllText(@"../../../Json/Activity/Message/MessageUpdateActivity.json"); |
| 154 | var activity = JsonSerializer.Deserialize<Activity>(json); |
| 155 | var expected = new MessageUpdateActivity("test") |
| 156 | { |
| 157 | Id = "1", |
| 158 | From = new() |
| 159 | { |
| 160 | Id = "1", |
| 161 | Name = "test", |
| 162 | Role = Role.User |
| 163 | }, |
| 164 | Conversation = new() |
| 165 | { |
| 166 | Id = "1", |
| 167 | Type = ConversationType.Personal |
| 168 | }, |
| 169 | Recipient = new() |
| 170 | { |
| 171 | Id = "2", |
| 172 | Name = "test-bot", |
| 173 | Role = Role.Bot |
| 174 | } |
| 175 | }; |
| 176 | |
| 177 | Assert.Equivalent(expected, activity); |
| 178 | } |
| 179 | } |