Skip to content

Commit

Permalink
[UWP] Fix RendererRegistration error handling and fix inheritance iss…
Browse files Browse the repository at this point in the history
…ue with WholeItemsPanel (#3710)
  • Loading branch information
RebeccaAnne committed Jan 30, 2020
1 parent fdd0f76 commit 10ce1cf
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 56 deletions.
4 changes: 2 additions & 2 deletions source/uwp/Renderer/idl/AdaptiveCards.Rendering.Uwp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -2123,8 +2123,8 @@ AdaptiveNamespaceStart
contract(InternalContract, 1),
internal
#endif
]
runtimeclass WholeItemsPanel
]
runtimeclass WholeItemsPanel : Windows.UI.Xaml.Controls.Panel
{
String GetAltText();
Boolean IsAllContentClippedOut();
Expand Down
22 changes: 20 additions & 2 deletions source/uwp/UWPUnitTests/RenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,31 @@ public async Task RenderInDispatcher(AdaptiveCard card)

// Need to move the test to the UI Thread to render the card
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
Exception dispatcherException = null;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
var renderer = new AdaptiveCardRenderer();
try
{

renderedCard = renderer.RenderAdaptiveCard(card);
var renderer = new AdaptiveCardRenderer();

renderedCard = renderer.RenderAdaptiveCard(card);
}
catch (Exception e)
{
// If we throw an exception from inside the dispatcher the test infrastructure loses its
// connection with the tests. Hold onto this and throw it from the main test thread so
// it is reported properly as a test failure.
dispatcherException = e;
}
});

if (dispatcherException != null)
{
// Rethrow any exceptions that may have happened within the dispatcher
throw dispatcherException;
}

Assert.AreEqual(0, renderedCard.Warnings.Count);
Assert.AreEqual(0, renderedCard.Errors.Count);
}
Expand Down
139 changes: 87 additions & 52 deletions source/uwp/UWPUnitTests/RendererRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,32 @@ public async Task ActionRendererRegistraton_DefaultActionsPresent()
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;

// Need to move the test to the UI Thread
Exception dispatcherException = null;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
AdaptiveCardRenderer renderer = new AdaptiveCardRenderer();
try
{
AdaptiveCardRenderer renderer = new AdaptiveCardRenderer();

Assert.IsNotNull(renderer.ActionRenderers.Get("Action.OpenUrl"));
Assert.IsNotNull(renderer.ActionRenderers.Get("Action.ShowCard"));
Assert.IsNotNull(renderer.ActionRenderers.Get("Action.Submit"));
Assert.IsNotNull(renderer.ActionRenderers.Get("Action.ToggleVisibility"));
Assert.IsNotNull(renderer.ActionRenderers.Get("Action.OpenUrl"));
Assert.IsNotNull(renderer.ActionRenderers.Get("Action.ShowCard"));
Assert.IsNotNull(renderer.ActionRenderers.Get("Action.Submit"));
Assert.IsNotNull(renderer.ActionRenderers.Get("Action.ToggleVisibility"));
}
catch (Exception e)
{
// If we throw an exception from inside the dispatcher the test infrastructure loses its
// connection with the tests. Hold onto this and throw it from the main test thread so
// it is reported properly as a test failure.
dispatcherException = e;
}
});

if (dispatcherException != null)
{
// Rethrow any exceptions that may have happened within the dispatcher
throw dispatcherException;
}
}

class TestCustomAction : IAdaptiveActionElement
Expand Down Expand Up @@ -95,59 +111,78 @@ public async Task ActionRendererRegistraton_CustomActionTest()
{
var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;

// Need to move the test to the UI Thread
AdaptiveActionParserRegistration actionParserRegistration = new AdaptiveActionParserRegistration();
List<AdaptiveWarning> warnings = new List<AdaptiveWarning>();

actionParserRegistration.Set("TestCustomAction", new TestActionParser());

String testCard =
"{" +
" \"type\":\"AdaptiveCard\"," +
" \"version\":\"1.0\"," +
" \"body\":" +
" [" +
" ]," +
" \"actions\":" +
" [" +
" {" +
" \"type\":\"TestCustomAction\"" +
" }," +
" {" +
" \"type\":\"Action.Submit\"" +
" }" +
" ]" +
"}";

AdaptiveCard card = AdaptiveCard.FromJsonString(testCard, null, actionParserRegistration).AdaptiveCard;
Assert.IsNotNull(card);


// Need to move the test to the UI Thread to render
Exception dispatcherException = null;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
AdaptiveActionParserRegistration actionParserRegistration = new AdaptiveActionParserRegistration();
List<AdaptiveWarning> warnings = new List<AdaptiveWarning>();

actionParserRegistration.Set("TestCustomAction", new TestActionParser());

String testCard =
"{" +
" \"type\":\"AdaptiveCard\"," +
" \"version\":\"1.0\"," +
" \"body\":" +
" [" +
" ]," +
" \"actions\":" +
" [" +
" {" +
" \"type\":\"TestCustomAction\"" +
" }," +
" {" +
" \"type\":\"Action.Submit\"" +
" }" +
" ]" +
"}";

AdaptiveCard card = AdaptiveCard.FromJsonString(testCard, null, actionParserRegistration).AdaptiveCard;
Assert.IsNotNull(card);

AdaptiveCardRenderer renderer = new AdaptiveCardRenderer();

renderer.ActionRenderers.Set("TestCustomAction", new TestCustomActionRenderer());
renderer.ActionRenderers.Set("Action.Submit", new TestSubmitActionRenderer());

Assert.IsNotNull(renderer.ActionRenderers.Get("TestCustomAction") as TestCustomActionRenderer);
Assert.IsNotNull(renderer.ActionRenderers.Get("Action.Submit") as TestSubmitActionRenderer);

FrameworkElement renderedCard = renderer.RenderAdaptiveCard(card).FrameworkElement;

bool submitFound = false;
bool customFound = false;
foreach (var radioButton in RenderTestHelpers.GetAllDescendants(renderedCard).OfType<RadioButton>())
try
{
customFound |= radioButton.Name == "CustomActionRadioButton";
submitFound |= radioButton.Name == "SubmitActionRadioButton";
}
AdaptiveCardRenderer renderer = new AdaptiveCardRenderer();

renderer.ActionRenderers.Set("TestCustomAction", new TestCustomActionRenderer());
renderer.ActionRenderers.Set("Action.Submit", new TestSubmitActionRenderer());

Assert.IsNotNull(renderer.ActionRenderers.Get("TestCustomAction") as TestCustomActionRenderer);
Assert.IsNotNull(renderer.ActionRenderers.Get("Action.Submit") as TestSubmitActionRenderer);

Assert.IsTrue(customFound && submitFound);
FrameworkElement renderedCard = renderer.RenderAdaptiveCard(card).FrameworkElement;

renderer.ActionRenderers.Remove("TestCustomAction");
renderer.ActionRenderers.Remove("Action.Submit");
renderer.ActionRenderers.Remove("TestCustomActionThatDoesntExist");
bool submitFound = false;
bool customFound = false;
foreach (var radioButton in RenderTestHelpers.GetAllDescendants(renderedCard).OfType<RadioButton>())
{
customFound |= radioButton.Name == "CustomActionRadioButton";
submitFound |= radioButton.Name == "SubmitActionRadioButton";
}

Assert.IsTrue(customFound && submitFound);

renderer.ActionRenderers.Remove("TestCustomAction");
renderer.ActionRenderers.Remove("Action.Submit");
renderer.ActionRenderers.Remove("TestCustomActionThatDoesntExist");
}
catch (Exception e)
{
// If we throw an exception from inside the dispatcher the test infrastructure loses its
// connection with the tests. Hold onto this and throw it from the main test thread so
// it is reported properly as a test failure.
dispatcherException = e;
}
});


if (dispatcherException != null)
{
// Rethrow any exceptions that may have happened within the dispatcher
throw dispatcherException;
}
}
}
}

0 comments on commit 10ce1cf

Please sign in to comment.