Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d3da804

Browse files
Add tests for TryRentProperty.
1 parent 7aec602 commit d3da804

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

‎tests/UnityMvvmToolkit.Test.Integration/BindingContextObjectProviderTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,55 @@ public void WarmupValueConverter_ShouldThrow_WhenValueConverterWasWarmup()
149149
.WithMessage("Warm up only during the initialization phase.");
150150
}
151151

152+
[Fact]
153+
public void TryRentProperty_ShouldReturnProperty_WhenDataIsValid()
154+
{
155+
// Arrange
156+
const int countValue = 69;
157+
158+
var objectProvider = new BindingContextObjectProvider(Array.Empty<IValueConverter>());
159+
var bindingContext = new MyBindingContext
160+
{
161+
Count = countValue,
162+
};
163+
164+
var countPropertyBindingData = nameof(MyBindingContext.Count).ToPropertyBindingData();
165+
166+
// Act
167+
var result =
168+
objectProvider.TryRentProperty<int>(bindingContext, countPropertyBindingData, out var countProperty);
169+
170+
// Assert
171+
countProperty
172+
.Should()
173+
.NotBeNull()
174+
.And
175+
.BeAssignableTo<IProperty<int>>()
176+
.And
177+
.BeAssignableTo<IReadOnlyProperty<int>>();
178+
179+
result.Should().BeTrue();
180+
countProperty.Value.Should().Be(countValue);
181+
}
182+
183+
[Fact]
184+
public void TryRentProperty_ShouldNotReturnProperty_WhenPropertyIsReadOnly()
185+
{
186+
// Arrange
187+
var objectProvider = new BindingContextObjectProvider(Array.Empty<IValueConverter>());
188+
var bindingContext = new MyBindingContext();
189+
190+
var readOnlyPropertyBindingData = nameof(MyBindingContext.IntReadOnlyValue).ToPropertyBindingData();
191+
192+
// Act
193+
var result =
194+
objectProvider.TryRentProperty<int>(bindingContext, readOnlyPropertyBindingData, out var countProperty);
195+
196+
// Assert
197+
result.Should().BeFalse();
198+
countProperty.Should().BeNull();
199+
}
200+
152201
[Fact]
153202
public void RentProperty_ShouldReturnProperty_WhenDataIsValid()
154203
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /