Browse Source

Tidied up XAML tests.

Moved actual XAML loading tests into Xaml directory, removed unused
classes.
pull/464/head
Steven Kirk 11 years ago
parent
commit
102af14c4c
  1. 11
      tests/Perspex.Markup.Xaml.UnitTests/Perspex.Markup.Xaml.UnitTests.csproj
  2. 44
      tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level1.cs
  3. 20
      tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level2.cs
  4. 20
      tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level3.cs
  5. 32
      tests/Perspex.Markup.Xaml.UnitTests/SampleModel/LogInViewModel.cs
  6. 41
      tests/Perspex.Markup.Xaml.UnitTests/SampleModel/MainWindowViewModel.cs
  7. 18
      tests/Perspex.Markup.Xaml.UnitTests/SampleModel/PropertyChangeNotifier.cs
  8. 17
      tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Repository.cs
  9. 26
      tests/Perspex.Markup.Xaml.UnitTests/SampleModel/UserRepositoriesViewModel.cs
  10. 105
      tests/Perspex.Markup.Xaml.UnitTests/StyleTests.cs
  11. 5
      tests/Perspex.Markup.Xaml.UnitTests/Templates/DataTemplateTests.cs
  12. 122
      tests/Perspex.Markup.Xaml.UnitTests/Xaml/StyleTests.cs
  13. 2
      tests/Perspex.Markup.Xaml.UnitTests/Xaml/TreeDataTemplateTests.cs

11
tests/Perspex.Markup.Xaml.UnitTests/Perspex.Markup.Xaml.UnitTests.csproj

@ -100,20 +100,13 @@
<Compile Include="Converters\PerspexPropertyConverterTest.cs" />
<Compile Include="Parsers\SelectorGrammarTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SampleModel\Level1.cs" />
<Compile Include="SampleModel\Level2.cs" />
<Compile Include="SampleModel\Level3.cs" />
<Compile Include="SampleModel\LogInViewModel.cs" />
<Compile Include="SampleModel\MainWindowViewModel.cs" />
<Compile Include="SampleModel\PropertyChangeNotifier.cs" />
<Compile Include="SampleModel\Repository.cs" />
<Compile Include="SampleModel\UserRepositoriesViewModel.cs" />
<Compile Include="SamplePerspexObject.cs" />
<Compile Include="StyleTests.cs" />
<Compile Include="Templates\DataTemplateTests.cs" />
<Compile Include="Templates\TreeDataTemplateTests.cs" />
<Compile Include="Xaml\TreeDataTemplateTests.cs" />
<Compile Include="TypeProviderMock.cs" />
<Compile Include="ViewModelMock.cs" />
<Compile Include="Xaml\StyleTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Markup\Perspex.Markup.Xaml\Perspex.Markup.Xaml.csproj">

44
tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level1.cs

@ -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();
}
}
}
}

20
tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level2.cs

@ -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();
}
}
}
}

20
tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Level3.cs

@ -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();
}
}
}
}

32
tests/Perspex.Markup.Xaml.UnitTests/SampleModel/LogInViewModel.cs

@ -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;
}
}
}

41
tests/Perspex.Markup.Xaml.UnitTests/SampleModel/MainWindowViewModel.cs

@ -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;
}
}
}

18
tests/Perspex.Markup.Xaml.UnitTests/SampleModel/PropertyChangeNotifier.cs

@ -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));
}
}
}

17
tests/Perspex.Markup.Xaml.UnitTests/SampleModel/Repository.cs

@ -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;
}
}

26
tests/Perspex.Markup.Xaml.UnitTests/SampleModel/UserRepositoriesViewModel.cs

@ -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); }
}
}
}

105
tests/Perspex.Markup.Xaml.UnitTests/StyleTests.cs

@ -5,9 +5,7 @@ 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;
@ -16,109 +14,6 @@ namespace Perspex.Markup.Xaml.UnitTests
{
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());
}
}
[Fact]
public void Binding_Should_Be_Assigned_To_Setter_Value_Instead_Of_Bound()
{

5
tests/Perspex.Markup.Xaml.UnitTests/Templates/DataTemplateTests.cs

@ -1,11 +1,6 @@
// 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 System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Perspex.Markup.Xaml.Templates;
using Xunit;

122
tests/Perspex.Markup.Xaml.UnitTests/Xaml/StyleTests.cs

@ -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());
}
}
}
}

2
tests/Perspex.Markup.Xaml.UnitTests/Templates/TreeDataTemplateTests.cs → tests/Perspex.Markup.Xaml.UnitTests/Xaml/TreeDataTemplateTests.cs

@ -8,7 +8,7 @@ using Perspex.Markup.Xaml.Templates;
using Perspex.UnitTests;
using Xunit;
namespace Perspex.Markup.Xaml.UnitTests
namespace Perspex.Markup.Xaml.UnitTests.Xaml
{
public class TreeDataTemplateTests
{
Loading…
Cancel
Save