microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
feature/oauthflow-fixes

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

68lines · modecode

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