Skip to content

Commit

Permalink
add unit test for #13585 (#16578)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneDelcroix committed Aug 7, 2023
1 parent 3abb0a5 commit 7ba11db
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui13585.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://schemas.microsoft.com/dotnet/2021/maui/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Microsoft.Maui.Controls.Xaml.UnitTests"
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Maui13585">
<ContentPage.Resources>
<Color x:Key="MyPrimaryColor">Green</Color>
<Color x:Key="MyReadOnlyColor">Purple</Color>

<Style TargetType="Button" x:Key="MyStaticResourceButtonStyle">
<Setter Property="BackgroundColor" Value="{StaticResource MyPrimaryColor}" />
<Style.Triggers>
<Trigger TargetType="Button" Property="IsEnabled" Value="False" >
<Setter Property="BackgroundColor" Value="{StaticResource MyReadOnlyColor}" />
</Trigger>
</Style.Triggers>
</Style>

<Style TargetType="Button" x:Key="MyDynamicResourceButtonStyle">
<Setter Property="BackgroundColor" Value="{DynamicResource MyPrimaryColor}" />
<Style.Triggers>
<Trigger TargetType="Button" Property="IsEnabled" Value="False" >
<Setter Property="BackgroundColor" Value="{DynamicResource MyReadOnlyColor}" />
</Trigger>
</Style.Triggers>
</Style>
</ContentPage.Resources>
<StackLayout>
<Button x:Name="styleTriggerWithStaticResources" Style="{StaticResource MyStaticResourceButtonStyle}" />
<Button x:Name="styleTriggerWithDynamicResources" Style="{StaticResource MyDynamicResourceButtonStyle}" />
</StackLayout>
</ContentPage>
51 changes: 51 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui13585.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.ApplicationModel;
using Microsoft.Maui.Controls.Core.UnitTests;
using Microsoft.Maui.Devices;
using NUnit.Framework;


namespace Microsoft.Maui.Controls.Xaml.UnitTests
{


public partial class Maui13585 : ContentPage
{
public Maui13585() => InitializeComponent();
public Maui13585(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}



[TestFixture]
class Tests
{
[SetUp] public void Setup() => AppInfo.SetCurrent(new MockAppInfo());
[TearDown] public void TearDown() => AppInfo.SetCurrent(null);

[Test]
public void TriggerWithDynamicResource([Values(false, true)] bool useCompiledXaml)
{
var page = new Maui13585(useCompiledXaml);
Assert.That(page.styleTriggerWithStaticResources.BackgroundColor, Is.EqualTo(Colors.Green));
Assert.That(page.styleTriggerWithDynamicResources.BackgroundColor, Is.EqualTo(Colors.Green));

page.styleTriggerWithStaticResources.IsEnabled = false;
page.styleTriggerWithDynamicResources.IsEnabled = false;

Assert.That(page.styleTriggerWithStaticResources.BackgroundColor, Is.EqualTo(Colors.Purple));
Assert.That(page.styleTriggerWithDynamicResources.BackgroundColor, Is.EqualTo(Colors.Purple));

page.styleTriggerWithStaticResources.IsEnabled = true;
page.styleTriggerWithDynamicResources.IsEnabled = true;

Assert.That(page.styleTriggerWithStaticResources.BackgroundColor, Is.EqualTo(Colors.Green));
Assert.That(page.styleTriggerWithDynamicResources.BackgroundColor, Is.EqualTo(Colors.Green));

}
}
}
}

0 comments on commit 7ba11db

Please sign in to comment.