|
1 | 1 | using System;
|
2 |
| -using ReactiveUI; |
3 | 2 | using Splat;
|
4 | 3 | using Xunit;
|
5 | 4 |
|
@@ -72,6 +71,29 @@ object IViewFor.ViewModel
|
72 | 71 | public IFooViewModel ViewModel { get; set; }
|
73 | 72 | }
|
74 | 73 |
|
| 74 | + public interface StrangeInterfaceNotFollowingConvention { } |
| 75 | + |
| 76 | + public class StrangeClassNotFollowingConvention : StrangeInterfaceNotFollowingConvention { } |
| 77 | + |
| 78 | + public interface IRoutableFooViewModel : IRoutableViewModel { } |
| 79 | + |
| 80 | + public class RoutableFooViewModel : ReactiveObject, IRoutableFooViewModel |
| 81 | + { |
| 82 | + public IScreen HostScreen { get; set; } |
| 83 | + public string UrlPathSegment { get; set; } |
| 84 | + } |
| 85 | + |
| 86 | + public class RoutableFooView : IViewFor<IRoutableFooViewModel> |
| 87 | + { |
| 88 | + object IViewFor.ViewModel |
| 89 | + { |
| 90 | + get { return ViewModel; } |
| 91 | + set { ViewModel = (IRoutableFooViewModel)value; } |
| 92 | + } |
| 93 | + public IRoutableFooViewModel ViewModel { get; set; } |
| 94 | + } |
| 95 | + |
| 96 | + |
75 | 97 | public class DefaultViewLocatorTests
|
76 | 98 | {
|
77 | 99 | [Fact]
|
@@ -332,5 +354,40 @@ public void AnErrorIsRaisedIfTheCreationOfTheViewFails()
|
332 | 354 | Assert.Equal("This is a test failure.", ex.Message);
|
333 | 355 | }
|
334 | 356 | }
|
| 357 | + |
| 358 | + [Fact] |
| 359 | + public void WithOddInterfaceNameDoesntThrowException() |
| 360 | + { |
| 361 | + var resolver = new ModernDependencyResolver(); |
| 362 | + |
| 363 | + resolver.InitializeSplat(); |
| 364 | + resolver.InitializeReactiveUI(); |
| 365 | + |
| 366 | + using (resolver.WithResolver()) { |
| 367 | + var fixture = new DefaultViewLocator(); |
| 368 | + |
| 369 | + var vm = new StrangeClassNotFollowingConvention(); |
| 370 | + |
| 371 | + fixture.ResolveView((StrangeInterfaceNotFollowingConvention)vm); |
| 372 | + } |
| 373 | + } |
| 374 | + |
| 375 | + [Fact] |
| 376 | + public void CanResolveViewFromViewModelWithIRoutableViewModelType() |
| 377 | + { |
| 378 | + var resolver = new ModernDependencyResolver(); |
| 379 | + |
| 380 | + resolver.InitializeSplat(); |
| 381 | + resolver.InitializeReactiveUI(); |
| 382 | + resolver.Register(() => new RoutableFooView(), typeof(IViewFor<IRoutableFooViewModel>)); |
| 383 | + |
| 384 | + using (resolver.WithResolver()) { |
| 385 | + var fixture = new DefaultViewLocator(); |
| 386 | + var vm = new RoutableFooViewModel(); |
| 387 | + |
| 388 | + var result = fixture.ResolveView<IRoutableViewModel>(vm); |
| 389 | + Assert.IsType<RoutableFooView>(result); |
| 390 | + } |
| 391 | + } |
335 | 392 | }
|
336 | 393 | }
|
0 commit comments