microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next/core

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/test/Microsoft.Teams.Bot.Apps.UnitTests/CitationEntityDeepCopyTests.cs

69lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Bot.Apps.Schema;
5using Microsoft.Teams.Bot.Apps.Schema.Entities;
6
7namespace Microsoft.Teams.Bot.Apps.UnitTests;
8
9/// <summary>
10/// Verifies that the CitationEntity copy constructor deep-copies CitationClaim instances
11/// so that mutations on the copy do not affect the original (COPY-01 / A-015).
12/// </summary>
13public class CitationEntityDeepCopyTests
14{
15 private static CitationEntity MakeCitation() => new CitationEntity
16 {
17 OType = "Message",
18 OContext = "https://schema.org",
19 Type = "message",
20 Citation =
21 [
22 new CitationClaim
23 {
24 Position = 1,
25 Appearance = new CitationAppearanceDocument
26 {
27 Name = "Source A",
28 Abstract = "Extract from Source A",
29 Url = new Uri("https://example.com/a"),
30 EncodingFormat = "text/plain"
31 }
32 }
33 ]
34 };
35
36 [Fact]
37 public void CopyConstructor_Citation_IsDeepCopied()
38 {
39 // Arrange
40 CitationEntity original = MakeCitation();
41
42 // Act – create a copy via the OMessageEntity copy constructor
43 CitationEntity copy = new(original);
44
45 // Mutate the copy's first claim
46 copy.Citation![0].Appearance.Name = "Mutated Name";
47
48 // Assert – original must be unaffected
49 Assert.Equal("Source A", original.Citation![0].Appearance.Name);
50 }
51
52 [Fact]
53 public void CopyConstructor_Citation_ListIsIndependent()
54 {
55 // Arrange
56 CitationEntity original = MakeCitation();
57 CitationEntity copy = new(original);
58
59 // Act – add an item to the copy's list
60 copy.Citation!.Add(new CitationClaim
61 {
62 Position = 99,
63 Appearance = new CitationAppearanceDocument { Name = "Extra", Abstract = "Extra abstract" }
64 });
65
66 // Assert – original list must not grow
67 Assert.Single(original.Citation!);
68 }
69}
70