Skip to content

Commit

Permalink
Update outdated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrozsival authored and rmarinho committed Aug 24, 2024
1 parent ec09fb0 commit 9abbf9f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Controls/tests/Xaml.UnitTests/Issues/Gh2517.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Gh2517"
x:DataType="Label">
<Label Text="{Binding MissingProperty}" />
<Label Text="{Binding MissingProperty}" x:Name="Label" />
</ContentPage>
11 changes: 8 additions & 3 deletions src/Controls/tests/Xaml.UnitTests/Issues/Gh2517.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.Maui.Controls.Xaml.UnitTests
{
[XamlCompilation(XamlCompilationOptions.Skip)]
// related to https://github.com/dotnet/maui/issues/23711
public partial class Gh2517 : ContentPage
{
public Gh2517()
Expand All @@ -24,10 +24,15 @@ public Gh2517(bool useCompiledXaml)
class Tests
{
[TestCase(true)]
public void ErrorOnMissingBindingTarget(bool useCompiledXaml)
public void BindingWithInvalidPathIsNotCompiled(bool useCompiledXaml)
{
if (useCompiledXaml)
Assert.Throws<BuildException>(() => MockCompiler.Compile(typeof(Gh2517)));
MockCompiler.Compile(typeof(Gh2517));

var view = new Gh2517(useCompiledXaml);

var binding = view.Label.GetContext(Label.TextProperty).Bindings.GetValue();
Assert.That(binding, Is.TypeOf<Binding>());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/tests/Xaml.UnitTests/Issues/Gh3606.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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" x:Class="Microsoft.Maui.Controls.Xaml.UnitTests.Gh3606" x:Name="page">
<StackLayout x:DataType="x:String">
<Label Text="{Binding Content, Source={x:Reference page}}" />
<Label Text="{Binding Content, Source={x:Reference page}}" x:Name="Label" />
</StackLayout>
</ContentPage>
18 changes: 8 additions & 10 deletions src/Controls/tests/Xaml.UnitTests/Issues/Gh3606.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Microsoft.Maui.Controls.Xaml.UnitTests
{
[XamlCompilation(XamlCompilationOptions.Skip)]
// related to https://github.com/dotnet/maui/issues/23711
public partial class Gh3606 : ContentPage
{
public Gh3606()
Expand All @@ -30,17 +30,15 @@ class Tests

[TestCase(true)]
[TestCase(false)]
public void BindingsWithSourceAreCompiled(bool useCompiledXaml)
public void BindingsWithSourceAndInvalidPathAreNotCompiled(bool useCompiledXaml)
{
if (useCompiledXaml)
{
// The XAML file contains a mismatch between the source the x:DataType attribute so the compilation of the binding will fail
Assert.Throws(new BuildExceptionConstraint(4, 16), () => MockCompiler.Compile(typeof(Gh3606)));
}
else
{
Assert.DoesNotThrow(() => new Gh3606(useCompiledXaml: false));
}
MockCompiler.Compile(typeof(Gh3606));

var view = new Gh3606(useCompiledXaml);

var binding = view.Label.GetContext(Label.TextProperty).Bindings.GetValue();
Assert.That(binding, Is.TypeOf<Binding>());
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions src/Controls/tests/Xaml.UnitTests/Issues/Maui20768.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

namespace Microsoft.Maui.Controls.Xaml.UnitTests;

[XamlCompilation(XamlCompilationOptions.Skip)]
public partial class Maui20768
{
public Maui20768()
Expand Down Expand Up @@ -43,16 +42,12 @@ public void Setup()
[Test]
public void BindingsDoNotResolveStaticProperties([Values(false, true)] bool useCompiledXaml)
{
if (useCompiledXaml)
{
Assert.Throws(new BuildExceptionConstraint(6, 32), () => MockCompiler.Compile(typeof(Maui20768)));
}
else
{
var page = new Maui20768(useCompiledXaml);
page.TitleLabel.BindingContext = new ViewModel20768();
Assert.Null(page.TitleLabel.Text);
}
if (useCompiledXaml)
MockCompiler.Compile(typeof(Maui20768));

var page = new Maui20768(useCompiledXaml);
page.TitleLabel.BindingContext = new ViewModel20768();
Assert.Null(page.TitleLabel.Text);
}
}
}
Expand Down

0 comments on commit 9abbf9f

Please sign in to comment.