Skip to content

Commit f0c677e

Browse files
committed
Update tests
1 parent 92e3f0c commit f0c677e

File tree

5 files changed

+177
-49
lines changed

5 files changed

+177
-49
lines changed

src/ReactiveUI.Uno.Tests/Converters/BooleanToVisibilityTypeConverterTests.cs

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,75 @@
44
// See the LICENSE file in the project root for full license information.
55

66
using FluentAssertions;
7-
using Xunit;
8-
#if HAS_WINUI
97
using Microsoft.UI.Xaml;
10-
#else
11-
using Windows.UI.Xaml;
12-
#endif
8+
using NUnit.Framework;
139

1410
namespace ReactiveUI.Uno.Tests.Converters;
1511

12+
/// <summary>
13+
/// BooleanToVisibilityTypeConverterTests.
14+
/// </summary>
15+
[TestFixture]
1616
public class BooleanToVisibilityTypeConverterTests
1717
{
1818
private readonly BooleanToVisibilityTypeConverter _sut = new();
1919

20-
[Fact]
20+
/// <summary>
21+
/// Affinities the is high for bool to visibility.
22+
/// </summary>
23+
[Test]
2124
public void Affinity_is_high_for_bool_to_visibility()
2225
{
2326
_sut.GetAffinityForObjects(typeof(bool), typeof(Visibility)).Should().Be(10);
2427
_sut.GetAffinityForObjects(typeof(Visibility), typeof(bool)).Should().Be(10);
2528
}
2629

27-
[Theory]
28-
[InlineData(true, Visibility.Visible)]
29-
[InlineData(false, Visibility.Collapsed)]
30+
/// <summary>
31+
/// Convertses the bool to visibility.
32+
/// </summary>
33+
/// <param name="input">if set to <c>true</c> [input].</param>
34+
/// <param name="expected">The expected.</param>
35+
[TestCase(true, Visibility.Visible)]
36+
[TestCase(false, Visibility.Collapsed)]
3037
public void Converts_bool_to_visibility(bool input, Visibility expected)
3138
{
3239
_sut.TryConvert(input, typeof(Visibility), BooleanToVisibilityHint.None, out var result).Should().BeTrue();
3340
result.Should().Be(expected);
3441
}
3542

36-
[Theory]
37-
[InlineData(true, Visibility.Collapsed)]
38-
[InlineData(false, Visibility.Visible)]
43+
/// <summary>
44+
/// Convertses the bool to visibility inverse.
45+
/// </summary>
46+
/// <param name="input">if set to <c>true</c> [input].</param>
47+
/// <param name="expected">The expected.</param>
48+
[TestCase(true, Visibility.Collapsed)]
49+
[TestCase(false, Visibility.Visible)]
3950
public void Converts_bool_to_visibility_inverse(bool input, Visibility expected)
4051
{
4152
_sut.TryConvert(input, typeof(Visibility), BooleanToVisibilityHint.Inverse, out var result).Should().BeTrue();
4253
result.Should().Be(expected);
4354
}
4455

45-
[Theory]
46-
[InlineData(Visibility.Visible, true)]
47-
[InlineData(Visibility.Collapsed, false)]
56+
/// <summary>
57+
/// Convertses the visibility to bool.
58+
/// </summary>
59+
/// <param name="input">The input.</param>
60+
/// <param name="expected">if set to <c>true</c> [expected].</param>
61+
[TestCase(Visibility.Visible, true)]
62+
[TestCase(Visibility.Collapsed, false)]
4863
public void Converts_visibility_to_bool(Visibility input, bool expected)
4964
{
5065
_sut.TryConvert(input, typeof(bool), BooleanToVisibilityHint.None, out var result).Should().BeTrue();
5166
result.Should().Be(expected);
5267
}
5368

54-
[Theory]
55-
[InlineData(Visibility.Visible, false)]
56-
[InlineData(Visibility.Collapsed, true)]
69+
/// <summary>
70+
/// Convertses the visibility to bool inverse.
71+
/// </summary>
72+
/// <param name="input">The input.</param>
73+
/// <param name="expected">if set to <c>true</c> [expected].</param>
74+
[TestCase(Visibility.Visible, false)]
75+
[TestCase(Visibility.Collapsed, true)]
5776
public void Converts_visibility_to_bool_inverse(Visibility input, bool expected)
5877
{
5978
_sut.TryConvert(input, typeof(bool), BooleanToVisibilityHint.Inverse, out var result).Should().BeTrue();

src/ReactiveUI.Uno.Tests/Hooks/AutoDataTemplateBindingHookTests.cs

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,72 @@
33
// The reactiveui and contributors licenses this file to you under the MIT license.
44
// See the LICENSE file in the project root for full license information.
55

6+
using System.Linq.Expressions;
67
using FluentAssertions;
7-
using ReactiveUI;
8-
using Xunit;
9-
#if HAS_WINUI
10-
using Microsoft.UI.Xaml;
118
using Microsoft.UI.Xaml.Controls;
12-
#else
13-
using Windows.UI.Xaml;
14-
using Windows.UI.Xaml.Controls;
15-
#endif
9+
using NUnit.Framework;
1610

17-
namespace ReactiveUI.Uno.Tests.Hooks;
11+
namespace ReactiveUI.Uno.Tests;
1812

13+
/// <summary>
14+
/// AutoDataTemplateBindingHookTests.
15+
/// </summary>
16+
[TestFixture]
1917
public class AutoDataTemplateBindingHookTests
2018
{
21-
private class TestViewModel
19+
/// <summary>
20+
/// Executes the hook sets default template when eligible.
21+
/// </summary>
22+
[Test]
23+
public void ExecuteHook_Sets_DefaultTemplate_When_Eligible()
2224
{
23-
}
25+
var hook = new AutoDataTemplateBindingHook();
26+
ItemsControl ic;
27+
try
28+
{
29+
ic = new ItemsControl();
30+
}
31+
catch (System.Exception ex) when (ex is System.TypeInitializationException || ex is System.NotSupportedException)
32+
{
33+
Assert.Ignore("UI dispatcher not available for Uno/WinUI controls in this environment.");
34+
return;
35+
}
2436

25-
[Fact]
26-
public void Sets_default_item_template_when_binding_items_source()
27-
{
28-
// Arrange
29-
var hook = new ReactiveUI.Uno.AutoDataTemplateBindingHook();
30-
var items = new ItemsControl();
37+
var vmChanges = Array.Empty<IObservedChange<object, object>>();
38+
var expr = (Expression<System.Func<object?>>)(() => ic.ItemsSource);
39+
var viewChanges = new[]
40+
{
41+
new ObservedChange<object, object>(ic, expr, new object())
42+
};
3143

32-
// Build a member access expression body: x => x.ItemsSource
33-
var parameter = System.Linq.Expressions.Expression.Parameter(typeof(ItemsControl), "x");
34-
var body = System.Linq.Expressions.Expression.Property(parameter, nameof(ItemsControl.ItemsSource));
44+
var result = hook.ExecuteHook(null, ic, () => vmChanges, () => viewChanges, BindingDirection.OneWay);
45+
result.Should().BeTrue();
46+
ic.ItemTemplate.Should().NotBeNull();
47+
}
3548

36-
var change = new ObservedChange<object, object>(items, body, default!);
49+
/// <summary>
50+
/// Executes the hook does not override existing template.
51+
/// </summary>
52+
[Test]
53+
public void ExecuteHook_Does_Not_Override_Existing_Template()
54+
{
55+
var hook = new AutoDataTemplateBindingHook();
56+
ItemsControl ic;
57+
try
58+
{
59+
ic = new ItemsControl { ItemTemplate = AutoDataTemplateBindingHook.DefaultItemTemplate.Value };
60+
}
61+
catch (System.Exception ex) when (ex is System.TypeInitializationException || ex is System.NotSupportedException)
62+
{
63+
Assert.Ignore("UI dispatcher not available for Uno/WinUI controls in this environment.");
64+
return;
65+
}
3766

38-
// Act
39-
var ok = hook.ExecuteHook(null, items,
40-
() => System.Array.Empty<IObservedChange<object, object>>(),
41-
() => new[] { change },
42-
default);
67+
var expr = (Expression<System.Func<object?>>)(() => ic.ItemsSource);
68+
var viewChanges = new[] { new ObservedChange<object, object>(ic, expr, new object()) };
4369

44-
// Assert
45-
ok.Should().BeTrue();
46-
items.ItemTemplate.Should().NotBeNull();
70+
var result = hook.ExecuteHook(null, ic, Array.Empty<IObservedChange<object, object>>, () => viewChanges, BindingDirection.OneWay);
71+
result.Should().BeTrue();
72+
ic.ItemTemplate.Should().NotBeNull();
4773
}
4874
}

src/ReactiveUI.Uno.Tests/Platform/PlatformOperationsTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
// See the LICENSE file in the project root for full license information.
55

66
using FluentAssertions;
7-
using Xunit;
7+
using NUnit.Framework;
88

99
namespace ReactiveUI.Uno.Tests.Platform;
1010

11+
/// <summary>
12+
/// Tests for PlatformOperations.
13+
/// </summary>
14+
[TestFixture]
1115
public class PlatformOperationsTests
1216
{
13-
[Fact]
17+
/// <summary>
18+
/// Ensures GetOrientation returns either null or a string value without throwing.
19+
/// </summary>
20+
[Test]
1421
public void GetOrientation_has_valid_string_or_null()
1522
{
1623
var ops = new ReactiveUI.Uno.PlatformOperations();

src/ReactiveUI.Uno.Tests/Properties/DependencyObjectObservableForPropertyTests.cs

Whitespace-only changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) 2025 ReactiveUI and Contributors. All rights reserved.
2+
// Licensed to reactiveui and contributors under one or more agreements.
3+
// The reactiveui and contributors licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using FluentAssertions;
10+
using NUnit.Framework;
11+
using ReactiveUI;
12+
using ReactiveUI.Uno;
13+
14+
namespace ReactiveUI.Uno.Tests;
15+
16+
/// <summary>
17+
/// RegistrationsTests.
18+
/// </summary>
19+
[TestFixture]
20+
public class RegistrationsTests
21+
{
22+
/// <summary>
23+
/// Resets the schedulers.
24+
/// </summary>
25+
[SetUp]
26+
public void ResetSchedulers()
27+
{
28+
// Reset to defaults before each test to avoid cross-test pollution.
29+
RxApp.MainThreadScheduler = null!;
30+
RxApp.TaskpoolScheduler = null!;
31+
}
32+
33+
/// <summary>
34+
/// Registers the registers expected services and configures schedulers.
35+
/// </summary>
36+
[Test]
37+
public void Register_RegistersExpectedServices_And_ConfiguresSchedulers()
38+
{
39+
var registered = new List<Type>();
40+
41+
void Register(Func<object> factory, Type serviceType)
42+
{
43+
// Don't invoke the factory here to avoid loading UI types in headless tests.
44+
registered.Add(serviceType);
45+
}
46+
47+
var sut = new Registrations();
48+
sut.Invoking(x => x.Register(Register)).Should().NotThrow();
49+
50+
// Verify the set of required service interfaces are registered
51+
registered.Should().Contain(typeof(IPlatformOperations));
52+
registered.Should().Contain(typeof(IActivationForViewFetcher));
53+
registered.Should().Contain(typeof(ICreatesObservableForProperty));
54+
registered.Should().Contain(typeof(IPropertyBindingHook));
55+
registered.Should().Contain(typeof(ISuspensionDriver));
56+
57+
// The implementation registers 16 binding converters + 2 hooks/services + 3 core services = 21 total
58+
// (String/byte(short/int/long/float/double/decimal) + nullable versions + BooleanToVisibility)
59+
registered.Count.Should().Be(21);
60+
61+
// Verify schedulers are set to safe defaults for headless environment
62+
RxApp.TaskpoolScheduler.Should().BeSameAs(System.Reactive.Concurrency.TaskPoolScheduler.Default);
63+
RxApp.MainThreadScheduler.Should().BeSameAs(System.Reactive.Concurrency.CurrentThreadScheduler.Instance);
64+
}
65+
66+
/// <summary>
67+
/// Registers the throws on null register function.
68+
/// </summary>
69+
[Test]
70+
public void Register_Throws_On_Null_RegisterFunction()
71+
{
72+
var sut = new Registrations();
73+
Action act = () => sut.Register(null!);
74+
act.Should().Throw<ArgumentNullException>();
75+
}
76+
}

0 commit comments

Comments
 (0)