Skip to content

Commit 405b391

Browse files
committed
Add extra rent property test.
1 parent a2c3340 commit 405b391

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

tests/UnityMvvmToolkit.Test.Integration/BindingContextObjectProviderTests.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,37 @@ public void RentPropertyWithConverter_ShouldReturnProperty_WhenDataIsValid()
212212
countProperty.Value.Should().Be(countValue.ToString());
213213
}
214214

215+
[Fact]
216+
public void RentPropertyWithConverter_ShouldReturnReadOnlyProperty_WhenPropertyInstanceIsNotReadOnly()
217+
{
218+
// Arrange
219+
const int intValue = 25;
220+
221+
var objectProvider = new BindingContextObjectProvider(new IValueConverter[]
222+
{
223+
new IntToStrConverter()
224+
});
225+
226+
var bindingContext = new MyBindingContext(intValue: intValue);
227+
228+
IReadOnlyProperty<int> intProperty;
229+
var intPropertyBindingData = nameof(MyBindingContext.IntReadOnlyProperty).ToPropertyBindingData();
230+
231+
// Act
232+
intProperty = objectProvider.RentProperty<int>(bindingContext, intPropertyBindingData);
233+
234+
// Assert
235+
intProperty
236+
.Should()
237+
.NotBeNull()
238+
.And
239+
.BeAssignableTo<IProperty<int>>()
240+
.And
241+
.BeAssignableTo<IReadOnlyProperty<int>>();
242+
243+
intProperty.Value.Should().Be(intValue);
244+
}
245+
215246
[Fact]
216247
public void RentProperty_ShouldThrow_WhenPropertyIsNotFound()
217248
{
@@ -279,7 +310,7 @@ public void RentPropertyWithConverter_ShouldThrow_WhenPropertyIsReadOnly()
279310

280311
var bindingContext = new MyBindingContext();
281312

282-
var intValueBindingData = nameof(MyBindingContext.IntValue).ToPropertyBindingData();
313+
var intValueBindingData = nameof(MyBindingContext.IntReadOnlyValue).ToPropertyBindingData();
283314

284315
// Assert
285316
objectProvider

tests/UnityMvvmToolkit.Test.Integration/TestBindingContext/MyBindingContext.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
using UnityMvvmToolkit.Test.Unit.TestCommands;
55

66
// ReSharper disable InconsistentNaming
7+
// ReSharper disable UnusedAutoPropertyAccessor.Global
78

89
namespace UnityMvvmToolkit.Test.Integration.TestBindingContext;
910

1011
public class MyBindingContext : IBindingContext
1112
{
1213
private readonly IProperty<int> _count = new Property<int>();
1314

14-
[Observable(nameof(IntValue))]
15-
private readonly IReadOnlyProperty<int> m_intValue = new ReadOnlyProperty<int>(69);
15+
[Observable(nameof(IntReadOnlyValue))]
16+
private readonly IReadOnlyProperty<int> m_intReadOnlyValue = new ReadOnlyProperty<int>(69);
1617

17-
public MyBindingContext(string title = "Title")
18+
public MyBindingContext(string title = "Title", int intValue = default)
1819
{
1920
Title = new ReadOnlyProperty<string>(title);
21+
IntReadOnlyProperty = new Property<int>(intValue);
2022

2123
FieldCommand = new Command(default);
2224

@@ -26,15 +28,17 @@ public MyBindingContext(string title = "Title")
2628
SetValueCommand = new Command<int>(value => Count = value);
2729
}
2830

29-
public IReadOnlyProperty<string> Title { get; }
30-
3131
public int Count
3232
{
3333
get => _count.Value;
3434
set => _count.Value = value;
3535
}
3636

37-
public int IntValue => m_intValue.Value;
37+
public int IntReadOnlyValue => m_intReadOnlyValue.Value;
38+
39+
public IReadOnlyProperty<string> Title { get; }
40+
41+
public IReadOnlyProperty<int> IntReadOnlyProperty { get; }
3842

3943
public ICommand FieldCommand;
4044
public ICommand IncrementCommand { get; }

0 commit comments

Comments
 (0)