File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed
tests/UnityMvvmToolkit.Test.Integration Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff 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.") ;
Original file line number Diff line number Diff line change 11using UnityMvvmToolkit . Core ;
2+ using UnityMvvmToolkit . Core . Attributes ;
23using UnityMvvmToolkit . Core . Interfaces ;
34using UnityMvvmToolkit . Test . Unit . TestCommands ;
45
56// ReSharper disable InconsistentNaming
6- // ReSharper disable UnusedMember.Global
77
88namespace UnityMvvmToolkit . Test . Integration . TestBindingContext ;
99
1010public 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 ; }
You can’t perform that action at this time.
0 commit comments