Browse Source
Moved actual XAML loading tests into Xaml directory, removed unused classes.pull/464/head
13 changed files with 125 additions and 338 deletions
@ -1,44 +0,0 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
public class Level1 : PropertyChangeNotifier |
|||
{ |
|||
private Level2 _level2 = new Level2(); |
|||
private DateTime _dateTime; |
|||
private string _text; |
|||
|
|||
public Level2 Level2 |
|||
{ |
|||
get { return _level2; } |
|||
set |
|||
{ |
|||
_level2 = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
|
|||
public string Text |
|||
{ |
|||
get { return _text; } |
|||
set |
|||
{ |
|||
_text = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
|
|||
public DateTime DateTime |
|||
{ |
|||
get { return _dateTime; } |
|||
set |
|||
{ |
|||
_dateTime = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
public class Level2 : PropertyChangeNotifier |
|||
{ |
|||
private Level3 _level3 = new Level3(); |
|||
|
|||
public Level3 Level3 |
|||
{ |
|||
get { return _level3; } |
|||
set |
|||
{ |
|||
_level3 = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
public class Level3 : PropertyChangeNotifier |
|||
{ |
|||
private int _property = 10; |
|||
|
|||
public int Property |
|||
{ |
|||
get { return _property; } |
|||
set |
|||
{ |
|||
_property = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,32 +0,0 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using ReactiveUI; |
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
public class LogInViewModel : ReactiveObject |
|||
{ |
|||
private string _username; |
|||
|
|||
public LogInViewModel() |
|||
{ |
|||
OkCommand = ReactiveCommand.Create( |
|||
this.WhenAnyValue( |
|||
x => x.Username, |
|||
x => !string.IsNullOrWhiteSpace(x))); |
|||
} |
|||
|
|||
public string Username |
|||
{ |
|||
get { return _username; } |
|||
set { this.RaiseAndSetIfChanged(ref _username, value); } |
|||
} |
|||
|
|||
public ReactiveCommand<object> OkCommand |
|||
{ |
|||
get; |
|||
private set; |
|||
} |
|||
} |
|||
} |
|||
@ -1,41 +0,0 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using Perspex.Xaml.Base.UnitTest.SampleModel; |
|||
using ReactiveUI; |
|||
|
|||
namespace GitHubClient.ViewModels |
|||
{ |
|||
public class MainWindowViewModel : ReactiveObject |
|||
{ |
|||
private object _content; |
|||
|
|||
private LogInViewModel _login; |
|||
|
|||
public MainWindowViewModel() |
|||
{ |
|||
ShowLogin(); |
|||
} |
|||
|
|||
public object Content |
|||
{ |
|||
get { return _content; } |
|||
set { this.RaiseAndSetIfChanged(ref _content, value); } |
|||
} |
|||
|
|||
private void ShowLogin() |
|||
{ |
|||
_login = new LogInViewModel(); |
|||
_login.OkCommand.Subscribe(_ => ShowRepositories()); |
|||
Content = _login; |
|||
} |
|||
|
|||
private void ShowRepositories() |
|||
{ |
|||
var vm = new UserRepositoriesViewModel(); |
|||
var task = vm.Load(_login.Username); |
|||
Content = vm; |
|||
} |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System.ComponentModel; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
public abstract class PropertyChangeNotifier : INotifyPropertyChanged |
|||
{ |
|||
public event PropertyChangedEventHandler PropertyChanged; |
|||
|
|||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
|||
{ |
|||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
namespace GitHubClient.ViewModels |
|||
{ |
|||
public class Repository |
|||
{ |
|||
private readonly string _name; |
|||
|
|||
public Repository(string name) |
|||
{ |
|||
_name = name; |
|||
} |
|||
|
|||
public string Name => _name; |
|||
} |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using GitHubClient.ViewModels; |
|||
using ReactiveUI; |
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
public class UserRepositoriesViewModel : ReactiveObject |
|||
{ |
|||
private IReadOnlyList<Repository> _repositories; |
|||
|
|||
public async Task Load(string username) |
|||
{ |
|||
Repositories = await new Task<IReadOnlyList<Repository>>(() => new List<Repository> { new Repository("Blah"), new Repository("Bleh") }); |
|||
} |
|||
|
|||
public IReadOnlyList<Repository> Repositories |
|||
{ |
|||
get { return _repositories; } |
|||
private set { this.RaiseAndSetIfChanged(ref _repositories, value); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,122 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System.Linq; |
|||
using System.Reactive.Linq; |
|||
using Perspex.Controls; |
|||
using Perspex.Data; |
|||
using Perspex.Input; |
|||
using Perspex.Markup.Xaml.Data; |
|||
using Perspex.Media; |
|||
using Perspex.Styling; |
|||
using Perspex.UnitTests; |
|||
using Xunit; |
|||
|
|||
namespace Perspex.Markup.Xaml.UnitTests.Xaml |
|||
{ |
|||
public class StyleTests |
|||
{ |
|||
[Fact] |
|||
public void Color_Can_Be_Added_To_Style_Resources() |
|||
{ |
|||
using (UnitTestApplication.Start(TestServices.MockPlatformWrapper)) |
|||
{ |
|||
var xaml = @"
|
|||
<UserControl xmlns='https://github.com/perspex'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|||
<UserControl.Styles> |
|||
<Style> |
|||
<Style.Resources> |
|||
<Color x:Key='color'>#ff506070</Color> |
|||
</Style.Resources> |
|||
</Style> |
|||
</UserControl.Styles> |
|||
</UserControl>";
|
|||
var loader = new PerspexXamlLoader(); |
|||
var userControl = (UserControl)loader.Load(xaml); |
|||
var color = (Color)((Style)userControl.Styles[0]).Resources["color"]; |
|||
|
|||
Assert.Equal(0xff506070, color.ToUint32()); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void SolidColorBrush_Can_Be_Added_To_Style_Resources() |
|||
{ |
|||
using (UnitTestApplication.Start(TestServices.MockPlatformWrapper)) |
|||
{ |
|||
var xaml = @"
|
|||
<UserControl xmlns='https://github.com/perspex'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|||
<UserControl.Styles> |
|||
<Style> |
|||
<Style.Resources> |
|||
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush> |
|||
</Style.Resources> |
|||
</Style> |
|||
</UserControl.Styles> |
|||
</UserControl>";
|
|||
var loader = new PerspexXamlLoader(); |
|||
var userControl = (UserControl)loader.Load(xaml); |
|||
var brush = (SolidColorBrush)((Style)userControl.Styles[0]).Resources["brush"]; |
|||
|
|||
Assert.Equal(0xff506070, brush.Color.ToUint32()); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void StyleResource_Can_Be_Assigned_To_Property() |
|||
{ |
|||
var xaml = @"
|
|||
<UserControl xmlns='https://github.com/perspex'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|||
<UserControl.Styles> |
|||
<Style> |
|||
<Style.Resources> |
|||
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush> |
|||
</Style.Resources> |
|||
</Style> |
|||
</UserControl.Styles> |
|||
|
|||
<Border Name='border' Background='{StyleResource brush}'/> |
|||
</UserControl>";
|
|||
|
|||
var loader = new PerspexXamlLoader(); |
|||
var userControl = (UserControl)loader.Load(xaml); |
|||
var border = userControl.FindControl<Border>("border"); |
|||
var brush = (SolidColorBrush)border.Background; |
|||
|
|||
Assert.Equal(0xff506070, brush.Color.ToUint32()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void StyleResource_Can_Be_Assigned_To_Setter() |
|||
{ |
|||
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|||
{ |
|||
var xaml = @"
|
|||
<Window xmlns='https://github.com/perspex'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|||
<Window.Styles> |
|||
<Style> |
|||
<Style.Resources> |
|||
<SolidColorBrush x:Key='brush'>#ff506070</SolidColorBrush> |
|||
</Style.Resources> |
|||
</Style> |
|||
<Style Selector='Button'> |
|||
<Setter Property='Background' Value='{StyleResource brush}'/> |
|||
</Style> |
|||
</Window.Styles> |
|||
<Button Name='button'/> |
|||
</Window>";
|
|||
|
|||
var loader = new PerspexXamlLoader(); |
|||
var window = (Window)loader.Load(xaml); |
|||
var button = window.FindControl<Button>("button"); |
|||
var brush = (SolidColorBrush)button.Background; |
|||
|
|||
Assert.Equal(0xff506070, brush.Color.ToUint32()); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue