Skip to content

Commit a2c3340

Browse files
committed
Add extra property test.
1 parent e3ac1e5 commit a2c3340

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

tests/UnityMvvmToolkit.Test.Integration/BindingContextObjectProviderTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,26 @@ public void RentProperty_ShouldThrow_WhenBindingDataIsNotValid()
268268
.WithMessage(nameof(countPropertyBindingData.PropertyName));
269269
}
270270

271+
[Fact]
272+
public void RentPropertyWithConverter_ShouldThrow_WhenPropertyIsReadOnly()
273+
{
274+
// Arrange
275+
var objectProvider = new BindingContextObjectProvider(new IValueConverter[]
276+
{
277+
new IntToStrConverter()
278+
});
279+
280+
var bindingContext = new MyBindingContext();
281+
282+
var intValueBindingData = nameof(MyBindingContext.IntValue).ToPropertyBindingData();
283+
284+
// Assert
285+
objectProvider
286+
.Invoking(sut => sut.RentReadOnlyProperty<string>(bindingContext, intValueBindingData))
287+
.Should()
288+
.Throw<InvalidCastException>();
289+
}
290+
271291
[Fact]
272292
public void RentPropertyWithConverter_ShouldThrow_WhenConverterIsNotSet()
273293
{
@@ -279,7 +299,7 @@ public void RentPropertyWithConverter_ShouldThrow_WhenConverterIsNotSet()
279299

280300
// Assert
281301
objectProvider
282-
.Invoking(objProvider => objProvider.RentProperty<string>(bindingContext, countPropertyBindingData))
302+
.Invoking(sut => sut.RentProperty<string>(bindingContext, countPropertyBindingData))
283303
.Should()
284304
.Throw<NullReferenceException>()
285305
.WithMessage($"Property value converter from '{typeof(int)}' to '{typeof(string)}' not found.");

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
using UnityMvvmToolkit.Core;
2+
using UnityMvvmToolkit.Core.Attributes;
23
using UnityMvvmToolkit.Core.Interfaces;
34
using UnityMvvmToolkit.Test.Unit.TestCommands;
45

56
// ReSharper disable InconsistentNaming
6-
// ReSharper disable UnusedMember.Global
77

88
namespace UnityMvvmToolkit.Test.Integration.TestBindingContext;
99

1010
public class MyBindingContext : IBindingContext
1111
{
1212
private readonly IProperty<int> _count = new Property<int>();
13-
private readonly IProperty<string> m_description = new Property<string>();
13+
14+
[Observable(nameof(IntValue))]
15+
private readonly IReadOnlyProperty<int> m_intValue = new ReadOnlyProperty<int>(69);
1416

1517
public MyBindingContext(string title = "Title")
1618
{
@@ -32,11 +34,7 @@ public int Count
3234
set => _count.Value = value;
3335
}
3436

35-
public string Description
36-
{
37-
get => m_description.Value;
38-
set => m_description.Value = value;
39-
}
37+
public int IntValue => m_intValue.Value;
4038

4139
public ICommand FieldCommand;
4240
public ICommand IncrementCommand { get; }

0 commit comments

Comments
 (0)