microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/test/Microsoft.Teams.Bot.Core.UnitTests/CoreActivityBuilderTests.cs
651lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Bot.Core.Schema; |
| 5 | |
| 6 | namespace Microsoft.Teams.Bot.Core.UnitTests; |
| 7 | |
| 8 | public class CoreActivityBuilderTests |
| 9 | { |
| 10 | [Fact] |
| 11 | public void Constructor_DefaultConstructor_CreatesNewActivity() |
| 12 | { |
| 13 | CoreActivityBuilder builder = new(); |
| 14 | CoreActivity activity = builder.Build(); |
| 15 | |
| 16 | Assert.NotNull(activity); |
| 17 | Assert.Null(activity.From); |
| 18 | Assert.Null(activity.Recipient); |
| 19 | Assert.Null(activity.Conversation); |
| 20 | } |
| 21 | |
| 22 | [Fact] |
| 23 | public void Constructor_WithExistingActivity_UsesProvidedActivity() |
| 24 | { |
| 25 | CoreActivity existingActivity = new() |
| 26 | { |
| 27 | Id = "test-id", |
| 28 | }; |
| 29 | |
| 30 | CoreActivityBuilder builder = new(existingActivity); |
| 31 | CoreActivity activity = builder.Build(); |
| 32 | |
| 33 | Assert.Equal("test-id", activity.Id); |
| 34 | } |
| 35 | |
| 36 | [Fact] |
| 37 | public void Constructor_WithNullActivity_ThrowsArgumentNullException() |
| 38 | { |
| 39 | Assert.Throws<ArgumentNullException>(() => new CoreActivityBuilder(null!)); |
| 40 | } |
| 41 | |
| 42 | [Fact] |
| 43 | public void WithId_SetsActivityId() |
| 44 | { |
| 45 | CoreActivity activity = new CoreActivityBuilder() |
| 46 | .WithId("test-activity-id") |
| 47 | .Build(); |
| 48 | |
| 49 | Assert.Equal("test-activity-id", activity.Id); |
| 50 | } |
| 51 | |
| 52 | [Fact] |
| 53 | public void WithServiceUrl_SetsServiceUrl() |
| 54 | { |
| 55 | Uri serviceUrl = new("https://smba.trafficmanager.net/teams/"); |
| 56 | |
| 57 | CoreActivity activity = new CoreActivityBuilder() |
| 58 | .WithServiceUrl(serviceUrl) |
| 59 | .Build(); |
| 60 | |
| 61 | Assert.Equal(serviceUrl, activity.ServiceUrl); |
| 62 | } |
| 63 | |
| 64 | [Fact] |
| 65 | public void WithChannelId_SetsChannelId() |
| 66 | { |
| 67 | CoreActivity activity = new CoreActivityBuilder() |
| 68 | .WithChannelId("msteams") |
| 69 | .Build(); |
| 70 | |
| 71 | Assert.Equal("msteams", activity.ChannelId); |
| 72 | } |
| 73 | |
| 74 | [Fact] |
| 75 | public void WithType_SetsActivityType() |
| 76 | { |
| 77 | CoreActivity activity = new CoreActivityBuilder() |
| 78 | .WithType(ActivityType.Message) |
| 79 | .Build(); |
| 80 | |
| 81 | Assert.Equal(ActivityType.Message, activity.Type); |
| 82 | } |
| 83 | |
| 84 | [Fact] |
| 85 | public void WithText_SetsTextContent_As_Property() |
| 86 | { |
| 87 | CoreActivity activity = new CoreActivityBuilder() |
| 88 | .WithProperty("text", "Hello, World!") |
| 89 | .Build(); |
| 90 | |
| 91 | Assert.Equal("Hello, World!", activity.Properties["text"]); |
| 92 | } |
| 93 | |
| 94 | [Fact] |
| 95 | public void WithFrom_SetsSenderAccount() |
| 96 | { |
| 97 | ConversationAccount fromAccount = new() |
| 98 | { |
| 99 | Id = "sender-id", |
| 100 | Name = "Sender Name" |
| 101 | }; |
| 102 | |
| 103 | CoreActivity activity = new CoreActivityBuilder() |
| 104 | .WithFrom(fromAccount) |
| 105 | .Build(); |
| 106 | |
| 107 | Assert.Equal("sender-id", activity.From?.Id); |
| 108 | Assert.Equal("Sender Name", activity.From?.Name); |
| 109 | } |
| 110 | |
| 111 | [Fact] |
| 112 | public void WithRecipient_SetsRecipientAccount() |
| 113 | { |
| 114 | ConversationAccount recipientAccount = new() |
| 115 | { |
| 116 | Id = "recipient-id", |
| 117 | Name = "Recipient Name" |
| 118 | }; |
| 119 | |
| 120 | CoreActivity activity = new CoreActivityBuilder() |
| 121 | .WithRecipient(recipientAccount) |
| 122 | .Build(); |
| 123 | |
| 124 | Assert.Equal("recipient-id", activity.Recipient?.Id); |
| 125 | Assert.Equal("Recipient Name", activity.Recipient?.Name); |
| 126 | } |
| 127 | |
| 128 | [Fact] |
| 129 | public void WithConversation_SetsConversationInfo() |
| 130 | { |
| 131 | Conversation conversation = new() |
| 132 | { |
| 133 | Id = "conversation-id" |
| 134 | }; |
| 135 | |
| 136 | CoreActivity activity = new CoreActivityBuilder() |
| 137 | .WithConversation(conversation) |
| 138 | .Build(); |
| 139 | |
| 140 | Assert.Equal("conversation-id", activity.Conversation?.Id); |
| 141 | } |
| 142 | |
| 143 | [Fact] |
| 144 | public void WithChannelData_SetsChannelData() |
| 145 | { |
| 146 | ChannelData channelData = new(); |
| 147 | |
| 148 | CoreActivity activity = new CoreActivityBuilder() |
| 149 | .WithChannelData(channelData) |
| 150 | .Build(); |
| 151 | |
| 152 | Assert.NotNull(activity.ChannelData); |
| 153 | } |
| 154 | |
| 155 | [Fact] |
| 156 | public void FluentAPI_CompleteActivity_BuildsCorrectly() |
| 157 | { |
| 158 | CoreActivity activity = new CoreActivityBuilder() |
| 159 | .WithType(ActivityType.Message) |
| 160 | .WithId("activity-123") |
| 161 | .WithChannelId("msteams") |
| 162 | .WithProperty("text", "Test message") |
| 163 | .WithServiceUrl(new Uri("https://smba.trafficmanager.net/teams/")) |
| 164 | .WithFrom(new ConversationAccount |
| 165 | { |
| 166 | Id = "sender-id", |
| 167 | Name = "Sender" |
| 168 | }) |
| 169 | .WithRecipient(new ConversationAccount |
| 170 | { |
| 171 | Id = "recipient-id", |
| 172 | Name = "Recipient" |
| 173 | }) |
| 174 | .WithConversation(new Conversation |
| 175 | { |
| 176 | Id = "conv-id" |
| 177 | }) |
| 178 | .Build(); |
| 179 | |
| 180 | Assert.Equal(ActivityType.Message, activity.Type); |
| 181 | Assert.Equal("activity-123", activity.Id); |
| 182 | Assert.Equal("msteams", activity.ChannelId); |
| 183 | Assert.Equal("Test message", activity.Properties["text"]?.ToString()); |
| 184 | Assert.Equal("sender-id", activity.From?.Id); |
| 185 | Assert.Equal("recipient-id", activity.Recipient?.Id); |
| 186 | Assert.Equal("conv-id", activity.Conversation?.Id); |
| 187 | } |
| 188 | |
| 189 | [Fact] |
| 190 | public void FluentAPI_MethodChaining_ReturnsBuilderInstance() |
| 191 | { |
| 192 | CoreActivityBuilder builder = new(); |
| 193 | |
| 194 | CoreActivityBuilder result1 = builder.WithId("id"); |
| 195 | CoreActivityBuilder result2 = builder.WithProperty("text", "text"); |
| 196 | CoreActivityBuilder result3 = builder.WithType(ActivityType.Message); |
| 197 | |
| 198 | Assert.Same(builder, result1); |
| 199 | Assert.Same(builder, result2); |
| 200 | Assert.Same(builder, result3); |
| 201 | } |
| 202 | |
| 203 | [Fact] |
| 204 | public void Build_CalledMultipleTimes_ReturnsSameInstance() |
| 205 | { |
| 206 | CoreActivityBuilder builder = new CoreActivityBuilder() |
| 207 | .WithId("test-id"); |
| 208 | |
| 209 | CoreActivity activity1 = builder.Build(); |
| 210 | CoreActivity activity2 = builder.Build(); |
| 211 | |
| 212 | Assert.Same(activity1, activity2); |
| 213 | } |
| 214 | |
| 215 | [Fact] |
| 216 | public void Builder_ModifyingExistingActivity_PreservesOriginalData() |
| 217 | { |
| 218 | CoreActivity original = new() |
| 219 | { |
| 220 | Id = "original-id", |
| 221 | Type = ActivityType.Message |
| 222 | }; |
| 223 | |
| 224 | CoreActivity modified = new CoreActivityBuilder(original) |
| 225 | .WithId("other-id") |
| 226 | .Build(); |
| 227 | |
| 228 | Assert.Equal("other-id", modified.Id); |
| 229 | Assert.Equal(ActivityType.Message, modified.Type); |
| 230 | } |
| 231 | |
| 232 | [Fact] |
| 233 | public void WithConversationReference_WithNullActivity_ThrowsArgumentNullException() |
| 234 | { |
| 235 | CoreActivityBuilder builder = new(); |
| 236 | |
| 237 | Assert.Throws<ArgumentNullException>(() => builder.WithConversationReference(null!)); |
| 238 | } |
| 239 | |
| 240 | [Fact] |
| 241 | public void WithConversationReference_WithNullChannelId_ThrowsArgumentNullException() |
| 242 | { |
| 243 | CoreActivityBuilder builder = new(); |
| 244 | CoreActivity sourceActivity = new() |
| 245 | { |
| 246 | ChannelId = null, |
| 247 | ServiceUrl = new Uri("https://test.com"), |
| 248 | Conversation = new Conversation(), |
| 249 | From = new ConversationAccount(), |
| 250 | Recipient = new ConversationAccount() |
| 251 | }; |
| 252 | |
| 253 | Assert.Throws<ArgumentNullException>(() => builder.WithConversationReference(sourceActivity)); |
| 254 | } |
| 255 | |
| 256 | [Fact] |
| 257 | public void WithConversationReference_WithNullServiceUrl_ThrowsArgumentNullException() |
| 258 | { |
| 259 | CoreActivityBuilder builder = new(); |
| 260 | CoreActivity sourceActivity = new() |
| 261 | { |
| 262 | ChannelId = "msteams", |
| 263 | ServiceUrl = null, |
| 264 | Conversation = new Conversation(), |
| 265 | From = new ConversationAccount(), |
| 266 | Recipient = new ConversationAccount() |
| 267 | }; |
| 268 | |
| 269 | Assert.Throws<ArgumentNullException>(() => builder.WithConversationReference(sourceActivity)); |
| 270 | } |
| 271 | |
| 272 | [Fact] |
| 273 | public void WithConversationReference_WithNullConversation_ThrowsArgumentNullException() |
| 274 | { |
| 275 | CoreActivityBuilder builder = new(); |
| 276 | CoreActivity sourceActivity = new() |
| 277 | { |
| 278 | ChannelId = "msteams", |
| 279 | ServiceUrl = new Uri("https://test.com"), |
| 280 | Conversation = null!, |
| 281 | From = new ConversationAccount(), |
| 282 | Recipient = new ConversationAccount() |
| 283 | }; |
| 284 | |
| 285 | Assert.Throws<ArgumentNullException>(() => builder.WithConversationReference(sourceActivity)); |
| 286 | } |
| 287 | |
| 288 | [Fact] |
| 289 | public void WithConversationReference_WithNullFrom_ThrowsArgumentNullException() |
| 290 | { |
| 291 | CoreActivityBuilder builder = new(); |
| 292 | CoreActivity sourceActivity = new() |
| 293 | { |
| 294 | ChannelId = "msteams", |
| 295 | ServiceUrl = new Uri("https://test.com"), |
| 296 | Conversation = new Conversation(), |
| 297 | From = null!, |
| 298 | Recipient = new ConversationAccount() |
| 299 | }; |
| 300 | |
| 301 | Assert.Throws<ArgumentNullException>(() => builder.WithConversationReference(sourceActivity)); |
| 302 | } |
| 303 | |
| 304 | [Fact] |
| 305 | public void WithConversationReference_WithNullRecipient_ThrowsArgumentNullException() |
| 306 | { |
| 307 | CoreActivityBuilder builder = new(); |
| 308 | CoreActivity sourceActivity = new() |
| 309 | { |
| 310 | ChannelId = "msteams", |
| 311 | ServiceUrl = new Uri("https://test.com"), |
| 312 | Conversation = new Conversation(), |
| 313 | From = new ConversationAccount(), |
| 314 | Recipient = null! |
| 315 | }; |
| 316 | |
| 317 | Assert.Throws<ArgumentNullException>(() => builder.WithConversationReference(sourceActivity)); |
| 318 | } |
| 319 | |
| 320 | [Fact] |
| 321 | public void WithConversationReference_AppliesConversationReference() |
| 322 | { |
| 323 | CoreActivity sourceActivity = new() |
| 324 | { |
| 325 | ChannelId = "msteams", |
| 326 | ServiceUrl = new Uri("https://smba.trafficmanager.net/teams/"), |
| 327 | Conversation = new Conversation { Id = "conv-123" }, |
| 328 | From = new ConversationAccount { Id = "user-1", Name = "User One" }, |
| 329 | Recipient = new ConversationAccount { Id = "bot-1", Name = "Bot" } |
| 330 | }; |
| 331 | |
| 332 | CoreActivity activity = new CoreActivityBuilder() |
| 333 | .WithConversationReference(sourceActivity) |
| 334 | .Build(); |
| 335 | |
| 336 | Assert.Equal("msteams", activity.ChannelId); |
| 337 | Assert.Equal(new Uri("https://smba.trafficmanager.net/teams/"), activity.ServiceUrl); |
| 338 | Assert.Equal("conv-123", activity.Conversation?.Id); |
| 339 | Assert.Equal("bot-1", activity.From?.Id); |
| 340 | Assert.Equal("Bot", activity.From?.Name); |
| 341 | //Assert.Equal("user-1", activity.Recipient?.Id); |
| 342 | //Assert.Equal("User One", activity.Recipient?.Name); |
| 343 | } |
| 344 | |
| 345 | [Fact] |
| 346 | public void WithConversationReference_SwapsFromAndRecipient() |
| 347 | { |
| 348 | CoreActivity incomingActivity = new() |
| 349 | { |
| 350 | ChannelId = "msteams", |
| 351 | ServiceUrl = new Uri("https://test.com"), |
| 352 | Conversation = new Conversation { Id = "conv-123" }, |
| 353 | From = new ConversationAccount { Id = "user-id", Name = "User" }, |
| 354 | Recipient = new ConversationAccount { Id = "bot-id", Name = "Bot" } |
| 355 | }; |
| 356 | |
| 357 | CoreActivity replyActivity = new CoreActivityBuilder() |
| 358 | .WithConversationReference(incomingActivity) |
| 359 | .Build(); |
| 360 | |
| 361 | Assert.Equal("bot-id", replyActivity.From?.Id); |
| 362 | Assert.Equal("Bot", replyActivity.From?.Name); |
| 363 | //Assert.Equal("user-id", replyActivity.Recipient?.Id); |
| 364 | //Assert.Equal("User", replyActivity.Recipient?.Name); |
| 365 | // TODO: review if recipient is required |
| 366 | } |
| 367 | |
| 368 | [Fact] |
| 369 | public void WithChannelData_WithNullValue_SetsToNull() |
| 370 | { |
| 371 | CoreActivity activity = new CoreActivityBuilder() |
| 372 | .WithChannelData(new ChannelData()) |
| 373 | .WithChannelData(null) |
| 374 | .Build(); |
| 375 | |
| 376 | Assert.Null(activity.ChannelData); |
| 377 | } |
| 378 | |
| 379 | [Fact] |
| 380 | public void WithId_WithEmptyString_SetsEmptyId() |
| 381 | { |
| 382 | CoreActivity activity = new CoreActivityBuilder() |
| 383 | .WithId(string.Empty) |
| 384 | .Build(); |
| 385 | |
| 386 | Assert.Equal(string.Empty, activity.Id); |
| 387 | } |
| 388 | |
| 389 | [Fact] |
| 390 | public void WithChannelId_WithEmptyString_SetsEmptyChannelId() |
| 391 | { |
| 392 | CoreActivity activity = new CoreActivityBuilder() |
| 393 | .WithChannelId(string.Empty) |
| 394 | .Build(); |
| 395 | |
| 396 | Assert.Equal(string.Empty, activity.ChannelId); |
| 397 | } |
| 398 | |
| 399 | [Fact] |
| 400 | public void WithType_WithEmptyString_SetsEmptyType() |
| 401 | { |
| 402 | CoreActivity activity = new CoreActivityBuilder() |
| 403 | .WithType(string.Empty) |
| 404 | .Build(); |
| 405 | |
| 406 | Assert.Equal(string.Empty, activity.Type); |
| 407 | } |
| 408 | |
| 409 | [Fact] |
| 410 | public void WithConversationReference_ChainedWithOtherMethods_MaintainsFluentInterface() |
| 411 | { |
| 412 | CoreActivity sourceActivity = new() |
| 413 | { |
| 414 | ChannelId = "msteams", |
| 415 | ServiceUrl = new Uri("https://test.com"), |
| 416 | Conversation = new Conversation { Id = "conv-123" }, |
| 417 | From = new ConversationAccount { Id = "user-1" }, |
| 418 | Recipient = new ConversationAccount { Id = "bot-1" } |
| 419 | }; |
| 420 | |
| 421 | CoreActivity activity = new CoreActivityBuilder() |
| 422 | .WithType(ActivityType.Message) |
| 423 | .WithConversationReference(sourceActivity) |
| 424 | .Build(); |
| 425 | |
| 426 | Assert.Equal(ActivityType.Message, activity.Type); |
| 427 | Assert.Equal("bot-1", activity.From?.Id); |
| 428 | //Assert.Equal("user-1", activity.Recipient?.Id); |
| 429 | |
| 430 | // TODO: review if recipient is required, if not, update WithConversationReference to not throw when recipient is null and update this test accordingly |
| 431 | } |
| 432 | |
| 433 | [Fact] |
| 434 | public void Build_AfterModificationThenBuild_ReflectsChanges() |
| 435 | { |
| 436 | CoreActivityBuilder builder = new CoreActivityBuilder() |
| 437 | .WithId("id-1"); |
| 438 | |
| 439 | CoreActivity activity1 = builder.Build(); |
| 440 | Assert.Equal("id-1", activity1.Id); |
| 441 | |
| 442 | builder.WithId("id-2"); |
| 443 | CoreActivity activity2 = builder.Build(); |
| 444 | |
| 445 | Assert.Same(activity1, activity2); |
| 446 | Assert.Equal("id-2", activity2.Id); |
| 447 | } |
| 448 | |
| 449 | [Fact] |
| 450 | public void IntegrationTest_CreateComplexActivity() |
| 451 | { |
| 452 | Uri serviceUrl = new("https://smba.trafficmanager.net/amer/test/"); |
| 453 | ChannelData channelData = new(); |
| 454 | |
| 455 | CoreActivity activity = new CoreActivityBuilder() |
| 456 | .WithType(ActivityType.Message) |
| 457 | .WithId("msg-001") |
| 458 | .WithServiceUrl(serviceUrl) |
| 459 | .WithChannelId("msteams") |
| 460 | .WithFrom(new ConversationAccount |
| 461 | { |
| 462 | Id = "bot-id", |
| 463 | Name = "Bot" |
| 464 | }) |
| 465 | .WithRecipient(new ConversationAccount |
| 466 | { |
| 467 | Id = "user-id", |
| 468 | Name = "User" |
| 469 | }) |
| 470 | .WithConversation(new Conversation |
| 471 | { |
| 472 | Id = "conv-001" |
| 473 | }) |
| 474 | .WithChannelData(channelData) |
| 475 | .Build(); |
| 476 | |
| 477 | Assert.Equal(ActivityType.Message, activity.Type); |
| 478 | Assert.Equal("msg-001", activity.Id); |
| 479 | Assert.Equal(serviceUrl, activity.ServiceUrl); |
| 480 | Assert.Equal("msteams", activity.ChannelId); |
| 481 | Assert.Equal("bot-id", activity.From?.Id); |
| 482 | Assert.Equal("user-id", activity.Recipient?.Id); |
| 483 | Assert.Equal("conv-001", activity.Conversation?.Id); |
| 484 | Assert.NotNull(activity.ChannelData); |
| 485 | } |
| 486 | |
| 487 | [Fact] |
| 488 | public void WithRecipient_DefaultsToNotTargeted() |
| 489 | { |
| 490 | CoreActivity activity = new CoreActivityBuilder() |
| 491 | .WithRecipient(new ConversationAccount { Id = "user-123" }) |
| 492 | .Build(); |
| 493 | |
| 494 | Assert.NotNull(activity.Recipient); |
| 495 | Assert.Null(activity.Recipient.IsTargeted); |
| 496 | Assert.Equal("user-123", activity.Recipient.Id); |
| 497 | } |
| 498 | |
| 499 | [Fact] |
| 500 | public void WithRecipient_WithIsTargetedTrue_SetsIsTargeted() |
| 501 | { |
| 502 | CoreActivity activity = new CoreActivityBuilder() |
| 503 | .WithRecipient(new ConversationAccount { Id = "user-123" }, true) |
| 504 | .Build(); |
| 505 | |
| 506 | Assert.NotNull(activity.Recipient); |
| 507 | Assert.True(activity.Recipient.IsTargeted); |
| 508 | Assert.Equal("user-123", activity.Recipient.Id); |
| 509 | } |
| 510 | |
| 511 | [Fact] |
| 512 | public void WithRecipient_WithIsTargetedFalse_SetsIsTargetedToNull() |
| 513 | { |
| 514 | CoreActivity activity = new CoreActivityBuilder() |
| 515 | .WithRecipient(new ConversationAccount { Id = "user-123" }, false) |
| 516 | .Build(); |
| 517 | |
| 518 | Assert.NotNull(activity.Recipient); |
| 519 | Assert.Null(activity.Recipient.IsTargeted); |
| 520 | Assert.Equal("user-123", activity.Recipient.Id); |
| 521 | } |
| 522 | |
| 523 | [Fact] |
| 524 | public void WithRecipient_Targeted_MaintainsFluentChaining() |
| 525 | { |
| 526 | CoreActivityBuilder builder = new(); |
| 527 | |
| 528 | CoreActivityBuilder result = builder.WithRecipient(new ConversationAccount { Id = "user-123" }, true); |
| 529 | |
| 530 | Assert.Same(builder, result); |
| 531 | } |
| 532 | |
| 533 | [Fact] |
| 534 | public void WithRecipient_Targeted_CanChainWithOtherMethods() |
| 535 | { |
| 536 | CoreActivity activity = new CoreActivityBuilder() |
| 537 | .WithType(ActivityType.Message) |
| 538 | .WithRecipient(new ConversationAccount { Id = "user-123", Name = "Test User" }, true) |
| 539 | .WithChannelId("msteams") |
| 540 | .Build(); |
| 541 | |
| 542 | Assert.Equal(ActivityType.Message, activity.Type); |
| 543 | Assert.NotNull(activity.Recipient); |
| 544 | Assert.True(activity.Recipient.IsTargeted); |
| 545 | Assert.Equal("user-123", activity.Recipient.Id); |
| 546 | Assert.Equal("Test User", activity.Recipient.Name); |
| 547 | Assert.Equal("msteams", activity.ChannelId); |
| 548 | } |
| 549 | |
| 550 | [Fact] |
| 551 | public void WithRecipient_Targeted_NullRecipient_DoesNotThrow() |
| 552 | { |
| 553 | CoreActivity activity = new CoreActivityBuilder() |
| 554 | .WithRecipient(null, true) |
| 555 | .Build(); |
| 556 | |
| 557 | Assert.Null(activity.Recipient); |
| 558 | } |
| 559 | |
| 560 | [Fact] |
| 561 | public void WithReplyToId_SetsReplyToId() |
| 562 | { |
| 563 | CoreActivity activity = new CoreActivityBuilder() |
| 564 | .WithReplyToId("reply-123") |
| 565 | .Build(); |
| 566 | |
| 567 | Assert.Equal("reply-123", activity.ReplyToId); |
| 568 | } |
| 569 | |
| 570 | [Fact] |
| 571 | public void WithServiceUrl_String_SetsServiceUrl() |
| 572 | { |
| 573 | CoreActivity activity = new CoreActivityBuilder() |
| 574 | .WithServiceUrl("https://smba.trafficmanager.net/teams/") |
| 575 | .Build(); |
| 576 | |
| 577 | Assert.Equal(new Uri("https://smba.trafficmanager.net/teams/"), activity.ServiceUrl); |
| 578 | } |
| 579 | |
| 580 | [Fact] |
| 581 | public void WithConversationReference_WithActivityId_SetsReplyToId() |
| 582 | { |
| 583 | CoreActivity sourceActivity = new() |
| 584 | { |
| 585 | Id = "activity-456", |
| 586 | ChannelId = "msteams", |
| 587 | ServiceUrl = new Uri("https://test.com"), |
| 588 | Conversation = new Conversation { Id = "conv-123" }, |
| 589 | From = new ConversationAccount { Id = "user-1" }, |
| 590 | Recipient = new ConversationAccount { Id = "bot-1" } |
| 591 | }; |
| 592 | |
| 593 | CoreActivity activity = new CoreActivityBuilder() |
| 594 | .WithConversationReference(sourceActivity) |
| 595 | .Build(); |
| 596 | |
| 597 | Assert.Equal("activity-456", activity.ReplyToId); |
| 598 | } |
| 599 | |
| 600 | [Fact] |
| 601 | public void WithConversationReference_WithoutActivityId_DoesNotSetReplyToId() |
| 602 | { |
| 603 | CoreActivity sourceActivity = new() |
| 604 | { |
| 605 | ChannelId = "msteams", |
| 606 | ServiceUrl = new Uri("https://test.com"), |
| 607 | Conversation = new Conversation { Id = "conv-123" }, |
| 608 | From = new ConversationAccount { Id = "user-1" }, |
| 609 | Recipient = new ConversationAccount { Id = "bot-1" } |
| 610 | }; |
| 611 | |
| 612 | CoreActivity activity = new CoreActivityBuilder() |
| 613 | .WithConversationReference(sourceActivity) |
| 614 | .Build(); |
| 615 | |
| 616 | Assert.Null(activity.ReplyToId); |
| 617 | } |
| 618 | |
| 619 | [Fact] |
| 620 | public void WithFrom_Null_SetsFromToNull() |
| 621 | { |
| 622 | CoreActivity activity = new CoreActivityBuilder() |
| 623 | .WithFrom(new ConversationAccount { Id = "user-1" }) |
| 624 | .WithFrom(null) |
| 625 | .Build(); |
| 626 | |
| 627 | Assert.Null(activity.From); |
| 628 | } |
| 629 | |
| 630 | [Fact] |
| 631 | public void WithRecipient_Null_SetsRecipientToNull() |
| 632 | { |
| 633 | CoreActivity activity = new CoreActivityBuilder() |
| 634 | .WithRecipient(new ConversationAccount { Id = "user-1" }) |
| 635 | .WithRecipient(null) |
| 636 | .Build(); |
| 637 | |
| 638 | Assert.Null(activity.Recipient); |
| 639 | } |
| 640 | |
| 641 | [Fact] |
| 642 | public void WithConversation_Null_SetsConversationToNull() |
| 643 | { |
| 644 | CoreActivity activity = new CoreActivityBuilder() |
| 645 | .WithConversation(new Conversation { Id = "conv-1" }) |
| 646 | .WithConversation(null) |
| 647 | .Build(); |
| 648 | |
| 649 | Assert.Null(activity.Conversation); |
| 650 | } |
| 651 | } |
| 652 | |