microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Tests/Microsoft.Teams.Api.Tests/Entities/StreamInfoEntityTests.cs
144lines · modecode
| 1 | using System.Text.Json; |
| 2 | |
| 3 | using Microsoft.Teams.Api.Entities; |
| 4 | |
| 5 | namespace Microsoft.Teams.Api.Tests.Entities; |
| 6 | |
| 7 | public class StreamInfoEntityTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void StreamInfoEntity_JsonSerialize() |
| 11 | { |
| 12 | var entity = new StreamInfoEntity() |
| 13 | { |
| 14 | StreamId = "strId", |
| 15 | StreamSequence = 3, |
| 16 | StreamType = new StreamType("streaming") |
| 17 | }; |
| 18 | |
| 19 | var json = JsonSerializer.Serialize(entity, new JsonSerializerOptions() |
| 20 | { |
| 21 | WriteIndented = true, |
| 22 | IndentSize = 2, |
| 23 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 24 | }); |
| 25 | |
| 26 | Assert.Equal(File.ReadAllText( |
| 27 | @"../../../Json/Entities/StreamInfoEntity.json" |
| 28 | ), json); |
| 29 | |
| 30 | Assert.True(entity.StreamType.IsStreaming); |
| 31 | Assert.False(entity.StreamType.IsFinal); |
| 32 | Assert.False(entity.StreamType.IsInformative); |
| 33 | } |
| 34 | |
| 35 | [Fact] |
| 36 | public void StreamInfoEntity_ValidateFinalStreamTypes() |
| 37 | { |
| 38 | var entity = new StreamInfoEntity() |
| 39 | { |
| 40 | StreamId = "strId", |
| 41 | StreamSequence = 3, |
| 42 | StreamType = new StreamType("final") |
| 43 | }; |
| 44 | |
| 45 | Assert.True(entity.StreamType.IsFinal); |
| 46 | Assert.False(entity.StreamType.IsInformative); |
| 47 | Assert.False(entity.StreamType.IsStreaming); |
| 48 | } |
| 49 | |
| 50 | [Fact] |
| 51 | public void StreamInfoEntity_ValidateInformativeStreamTypes() |
| 52 | { |
| 53 | var entity = new StreamInfoEntity() |
| 54 | { |
| 55 | StreamId = "strId", |
| 56 | StreamSequence = 3, |
| 57 | StreamType = new StreamType("informative") |
| 58 | }; |
| 59 | |
| 60 | Assert.True(entity.StreamType.IsInformative); |
| 61 | Assert.False(entity.StreamType.IsFinal); |
| 62 | Assert.False(entity.StreamType.IsStreaming); |
| 63 | } |
| 64 | |
| 65 | [Fact] |
| 66 | public void StreamInfoEntity_JsonSerialize_Derived() |
| 67 | { |
| 68 | StreamInfoEntity entity = new StreamInfoEntity() |
| 69 | { |
| 70 | StreamId = "strId", |
| 71 | StreamSequence = 3, |
| 72 | StreamType = new StreamType("streaming") |
| 73 | }; |
| 74 | |
| 75 | var json = JsonSerializer.Serialize(entity, new JsonSerializerOptions() |
| 76 | { |
| 77 | WriteIndented = true, |
| 78 | IndentSize = 2, |
| 79 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 80 | }); |
| 81 | |
| 82 | Assert.Equal(File.ReadAllText( |
| 83 | @"../../../Json/Entities/StreamInfoEntity.json" |
| 84 | ), json); |
| 85 | |
| 86 | |
| 87 | } |
| 88 | |
| 89 | [Fact] |
| 90 | public void StreamInfoEntity_JsonSerialize_Interface_Derived() |
| 91 | { |
| 92 | Entity entity = new StreamInfoEntity() |
| 93 | { |
| 94 | StreamId = "strId", |
| 95 | StreamSequence = 3, |
| 96 | StreamType = new StreamType("streaming") |
| 97 | }; |
| 98 | |
| 99 | var json = JsonSerializer.Serialize(entity, new JsonSerializerOptions() |
| 100 | { |
| 101 | WriteIndented = true, |
| 102 | IndentSize = 2, |
| 103 | DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull |
| 104 | }); |
| 105 | |
| 106 | Assert.Equal(File.ReadAllText( |
| 107 | @"../../../Json/Entities/StreamInfoEntity.json" |
| 108 | ), json); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | [Fact] |
| 113 | public void StreamInfoEntity_JsonDeserialize() |
| 114 | { |
| 115 | var json = File.ReadAllText(@"../../../Json/Entities/StreamInfoEntity.json"); |
| 116 | var entity = JsonSerializer.Deserialize<StreamInfoEntity>(json); |
| 117 | |
| 118 | var expected = new StreamInfoEntity() |
| 119 | { |
| 120 | StreamId = "strId", |
| 121 | StreamSequence = 3, |
| 122 | StreamType = new StreamType("streaming") |
| 123 | }; |
| 124 | |
| 125 | Assert.Equivalent(expected, entity); |
| 126 | } |
| 127 | |
| 128 | [Fact] |
| 129 | public void StreamInfoEntity_JsonDeserialize_Derived() |
| 130 | { |
| 131 | var json = File.ReadAllText(@"../../../Json/Entities/StreamInfoEntity.json"); |
| 132 | var entity = JsonSerializer.Deserialize<Entity>(json); |
| 133 | var expected = new StreamInfoEntity() |
| 134 | { |
| 135 | StreamId = "strId", |
| 136 | StreamSequence = 3, |
| 137 | StreamType = new StreamType("streaming") |
| 138 | }; |
| 139 | |
| 140 | Assert.Equivalent(expected, entity); |
| 141 | } |
| 142 | |
| 143 | |
| 144 | } |