Skip to content

Commit 08ad8cb

Browse files
authored
Fix serialization for container style (#806)
* Fix serialization for container style * add assemblyinfo back * fix tests
1 parent 3f6ff23 commit 08ad8cb

File tree

6 files changed

+52
-61
lines changed

6 files changed

+52
-61
lines changed

source/dotnet/Library/AdaptiveCards/AdaptiveContainer.cs

+1-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Collections.Generic;
22
using Newtonsoft.Json;
3-
using System;
43

54
namespace AdaptiveCards
65
{
@@ -31,27 +30,7 @@ public AdaptiveContainer()
3130
/// <summary>
3231
/// The style in which the image is displayed.
3332
/// </summary>
34-
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
33+
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
3534
public AdaptiveContainerStyle Style { get; set; }
3635
}
37-
38-
[JsonConverter(typeof(IgnoreDefaultStringEnumConverter<AdaptiveContainerStyle>), true)]
39-
public enum AdaptiveContainerStyle
40-
{
41-
/// <summary>
42-
/// The container is a default container
43-
/// </summary>
44-
Default = 0,
45-
46-
/// <summary>
47-
/// The container is a normal container
48-
/// </summary>
49-
[Obsolete("ContainerStyle.Normal has been deprecated. Use ContainerStyle.Default", false)]
50-
Normal = 0,
51-
52-
/// <summary>
53-
/// The container should be emphasized as a grouping of elements
54-
/// </summary>
55-
Emphasis = 1
56-
}
5736
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
4+
namespace AdaptiveCards
5+
{
6+
[JsonConverter(typeof(IgnoreDefaultStringEnumConverter<AdaptiveContainerStyle>), true)]
7+
public enum AdaptiveContainerStyle
8+
{
9+
/// <summary>
10+
/// The container is a default container
11+
/// </summary>
12+
Default = 0,
13+
14+
/// <summary>
15+
/// The container is a normal container
16+
/// </summary>
17+
[Obsolete("ContainerStyle.Normal has been deprecated. Use ContainerStyle.Default", false)]
18+
Normal = 0,
19+
20+
/// <summary>
21+
/// The container should be emphasized as a grouping of elements
22+
/// </summary>
23+
Emphasis = 1
24+
}
25+
}

source/dotnet/Test/AdaptiveCards.Test/AdaptiveCardSerializationTests.cs

-38
This file was deleted.

source/dotnet/Test/AdaptiveCards.Test/AdaptiveCards.Test.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
<Reference Include="System.Core" />
4949
</ItemGroup>
5050
<ItemGroup>
51-
<Compile Include="AdaptiveCardSerializationTests.cs" />
5251
<Compile Include="Properties\AssemblyInfo.cs" />
5352
<Compile Include="AdaptiveCardApiTests.cs" />
5453
<Compile Include="HostConfigApiTests.cs" />

source/dotnet/Test/AdaptiveCards.Test/SerializationTests.cs

+25
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,30 @@ public void TestCardsSerializeInTheCorrectOrder()
4747
Assert.AreEqual(expected, card.ToJson());
4848

4949
}
50+
51+
[TestMethod]
52+
public void TestSerializingTextBlock()
53+
{
54+
var card = new AdaptiveCard()
55+
{
56+
Body =
57+
{
58+
new AdaptiveTextBlock()
59+
{
60+
Text = "Hello world"
61+
}
62+
}
63+
};
64+
65+
string json = card.ToJson();
66+
67+
// Re-parse the card
68+
card = AdaptiveCard.FromJson(json).Card;
69+
70+
// Ensure there's a text element
71+
Assert.AreEqual(1, card.Body.Count);
72+
Assert.IsInstanceOfType(card.Body[0], typeof(AdaptiveTextBlock));
73+
Assert.AreEqual("Hello world", (card.Body[0] as AdaptiveTextBlock).Text);
74+
}
5075
}
5176
}
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)