22 changed files with 825 additions and 0 deletions
@ -0,0 +1,24 @@ |
|||
namespace Perspex.Xaml.Base.UnitTest |
|||
{ |
|||
using System; |
|||
using Moq; |
|||
using Markup.Xaml.DataBinding; |
|||
using OmniXaml.TypeConversion; |
|||
using Xunit; |
|||
|
|||
public class BinderTest |
|||
{ |
|||
[Fact] |
|||
public void NullTarget_Throws() |
|||
{ |
|||
var typeConverter = new Mock<ITypeConverterProvider>(); |
|||
var perspexPropertyBinder = new PerspexPropertyBinder(typeConverter.Object); |
|||
var bindingDefinitionBuilder = new BindingDefinitionBuilder(); |
|||
var binding = bindingDefinitionBuilder |
|||
.WithNullTarget() |
|||
.Build(); |
|||
|
|||
var exception = Assert.Throws<InvalidOperationException>(() => perspexPropertyBinder.Create(binding)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using System; |
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest |
|||
{ |
|||
using Controls; |
|||
using Markup.Xaml.DataBinding; |
|||
using Markup.Xaml.DataBinding.ChangeTracking; |
|||
|
|||
public class BindingDefinitionBuilder |
|||
{ |
|||
private readonly BindingMode bindingMode; |
|||
private readonly PropertyPath sourcePropertyPath; |
|||
private Control target; |
|||
private PerspexProperty targetProperty; |
|||
|
|||
public BindingDefinitionBuilder() |
|||
{ |
|||
bindingMode = BindingMode.Default; |
|||
sourcePropertyPath = new PropertyPath(string.Empty); |
|||
} |
|||
|
|||
public BindingDefinitionBuilder WithNullTarget() |
|||
{ |
|||
target = null; |
|||
return this; |
|||
} |
|||
|
|||
public XamlBindingDefinition Build() |
|||
{ |
|||
return new XamlBindingDefinition( |
|||
bindingMode: bindingMode, |
|||
sourcePropertyPath: sourcePropertyPath, |
|||
target: target, |
|||
targetProperty: targetProperty); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
namespace Perspex.Xaml.Base.UnitTest |
|||
{ |
|||
using System; |
|||
using Markup.Xaml.DataBinding.ChangeTracking; |
|||
using SampleModel; |
|||
using Xunit; |
|||
|
|||
public class ChangeBranchTest |
|||
{ |
|||
[Fact] |
|||
public void GetValueOfMemberOfStruct() |
|||
{ |
|||
var level1 = new Level1(); |
|||
level1.DateTime = new DateTime(1, 2, 3, 4, 5, 6); |
|||
|
|||
var branch = new ObservablePropertyBranch(level1, new PropertyPath("DateTime.Minute")); |
|||
|
|||
var day = branch.Value; |
|||
Assert.Equal(day, branch.Value); |
|||
} |
|||
|
|||
[Fact] |
|||
public void OnePathOnly() |
|||
{ |
|||
var level1 = new Level1(); |
|||
|
|||
var branch = new ObservablePropertyBranch(level1, new PropertyPath("Text")); |
|||
var newValue = "Hey now"; |
|||
branch.Value = newValue; |
|||
|
|||
Assert.Equal(level1.Text, newValue); |
|||
} |
|||
|
|||
[Fact] |
|||
public void SettingValueToUnderlyingProperty_ChangesTheValueInBranch() |
|||
{ |
|||
var level1 = new Level1(); |
|||
|
|||
level1.Level2.Level3.Property = 3; |
|||
|
|||
var branch = new ObservablePropertyBranch(level1, new PropertyPath("Level2.Level3.Property")); |
|||
Assert.Equal(3, branch.Value); |
|||
} |
|||
|
|||
[Fact] |
|||
public void SettingValueToBranch_ChangesTheUnderlyingProperty() |
|||
{ |
|||
var level1 = new Level1(); |
|||
|
|||
var branch = new ObservablePropertyBranch(level1, new PropertyPath("Level2.Level3.Property")); |
|||
branch.Value = 3; |
|||
Assert.Equal(3, level1.Level2.Level3.Property); |
|||
} |
|||
|
|||
[Fact] |
|||
public void SettingValueProperty_RaisesChangeInBranch() |
|||
{ |
|||
var level1 = new Level1(); |
|||
|
|||
var branch = new ObservablePropertyBranch(level1, new PropertyPath("Level2.Level3.Property")); |
|||
bool hit = false; |
|||
ObservableExtensions.Subscribe(branch.Changed, _ => hit = true); |
|||
|
|||
level1.Level2.Level3.Property = 3; |
|||
|
|||
Assert.True(hit); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,105 @@ |
|||
namespace Perspex.Xaml.Base.UnitTest |
|||
{ |
|||
using System; |
|||
using Controls; |
|||
using GitHubClient.ViewModels; |
|||
using Markup.Xaml.DataBinding; |
|||
using Markup.Xaml.DataBinding.ChangeTracking; |
|||
using OmniXaml.Builder; |
|||
using OmniXaml.TypeConversion; |
|||
using OmniXaml.TypeConversion.BuiltInConverters; |
|||
using SampleModel; |
|||
using Xunit; |
|||
|
|||
public class DataContextChangeSynchronizerTest |
|||
{ |
|||
private TypeConverterProvider repo; |
|||
private SamplePerspexObject guiObject; |
|||
private ViewModelMock viewModel; |
|||
|
|||
public DataContextChangeSynchronizerTest() |
|||
{ |
|||
repo = new TypeConverterProvider(); |
|||
guiObject = new SamplePerspexObject(); |
|||
viewModel = new ViewModelMock(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void SameTypesFromUIToModel() |
|||
{ |
|||
var synchronizer = new DataContextChangeSynchronizer(guiObject, SamplePerspexObject.IntProperty, new PropertyPath("IntProp"), viewModel, repo); |
|||
synchronizer.SubscribeModelToUI(); |
|||
|
|||
const int someValue = 4; |
|||
guiObject.Int = someValue; |
|||
|
|||
Assert.Equal(someValue, viewModel.IntProp); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DifferentTypesFromUIToModel() |
|||
{ |
|||
var synchronizer = new DataContextChangeSynchronizer(guiObject, SamplePerspexObject.StringProperty, new PropertyPath("IntProp"), viewModel, repo); |
|||
synchronizer.SubscribeModelToUI(); |
|||
|
|||
guiObject.String = "2"; |
|||
|
|||
Assert.Equal(2, viewModel.IntProp); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DifferentTypesAndNonConvertibleValueFromUIToModel() |
|||
{ |
|||
var synchronizer = new DataContextChangeSynchronizer(guiObject, SamplePerspexObject.StringProperty, new PropertyPath("IntProp"), viewModel, repo); |
|||
synchronizer.SubscribeModelToUI(); |
|||
|
|||
guiObject.String = ""; |
|||
|
|||
Assert.Equal(default(int), viewModel.IntProp); |
|||
} |
|||
|
|||
|
|||
[Fact] |
|||
public void DifferentTypesFromModelToUI() |
|||
{ |
|||
var synchronizer = new DataContextChangeSynchronizer(guiObject, SamplePerspexObject.StringProperty, new PropertyPath("IntProp"), viewModel, repo); |
|||
synchronizer.SubscribeUIToModel(); |
|||
|
|||
viewModel.IntProp = 2; |
|||
|
|||
Assert.Equal("2", guiObject.String); |
|||
} |
|||
|
|||
[Fact] |
|||
public void SameTypesFromModelToUI() |
|||
{ |
|||
var synchronizer = new DataContextChangeSynchronizer(guiObject, SamplePerspexObject.IntProperty, new PropertyPath("IntProp"), viewModel, repo); |
|||
synchronizer.SubscribeUIToModel(); |
|||
|
|||
viewModel.IntProp = 2; |
|||
|
|||
Assert.Equal(2, guiObject.Int); |
|||
} |
|||
|
|||
[Fact] |
|||
public void GrokysTest() |
|||
{ |
|||
var mainWindowViewModel = new MainWindowViewModel(); |
|||
var contentControl = new ContentControl(); |
|||
|
|||
var synchronizer = new DataContextChangeSynchronizer( |
|||
contentControl, |
|||
ContentControl.ContentProperty, |
|||
new PropertyPath("Content"), |
|||
mainWindowViewModel, |
|||
repo); |
|||
|
|||
synchronizer.SubscribeUIToModel(); |
|||
|
|||
var logInViewModel = new LogInViewModel(); |
|||
mainWindowViewModel.Content = logInViewModel; |
|||
|
|||
Assert.Equal(logInViewModel, contentControl.Content); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,212 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props')" /> |
|||
<Import Project="..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" /> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{99135EAB-653D-47E4-A378-C96E1278CA44}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.Xaml.Base.UnitTest</RootNamespace> |
|||
<AssemblyName>Perspex.Xaml.Base.UnitTest</AssemblyName> |
|||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> |
|||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
|||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> |
|||
<IsCodedUITest>False</IsCodedUITest> |
|||
<TestProjectType>UnitTest</TestProjectType> |
|||
<TargetFrameworkProfile /> |
|||
<SccProjectName>SAK</SccProjectName> |
|||
<SccLocalPath>SAK</SccLocalPath> |
|||
<SccAuxPath>SAK</SccAuxPath> |
|||
<SccProvider>SAK</SccProvider> |
|||
<NuGetPackageImportStamp> |
|||
</NuGetPackageImportStamp> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="Glass, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\Glass.0.1.0\lib\portable-net45+win+Xamarin.iOS10+MonoAndroid10+MonoTouch10\Glass.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="Moq, Version=4.2.1409.1722, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="Octokit"> |
|||
<HintPath>..\..\packages\Octokit.0.14.0\lib\net45\Octokit.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="OmniXaml"> |
|||
<HintPath>..\..\packages\OmniXaml.0.1.0\lib\portable-net45+win+Xamarin.iOS10+MonoAndroid10+MonoTouch10\OmniXaml.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="Splat, Version=1.6.1.0, Culture=neutral, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\Splat.1.6.1\lib\Net45\Splat.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System" /> |
|||
<Reference Include="System.Reactive.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.Interfaces, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.Linq, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.PlatformServices, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="xunit.assert, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
<Reference Include="xunit.core, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> |
|||
<HintPath>..\..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath> |
|||
<Private>True</Private> |
|||
</Reference> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> |
|||
</ItemGroup> |
|||
</When> |
|||
<Otherwise /> |
|||
</Choose> |
|||
<ItemGroup> |
|||
<Compile Include="BindingDefinitionBuilder.cs" /> |
|||
<Compile Include="ChangeBranchTest.cs" /> |
|||
<Compile Include="DataContextChangeSynchronizerTest.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="TypeProviderMock.cs" /> |
|||
<Compile Include="BinderTest.cs" /> |
|||
<Compile Include="XamlBindingTest.cs" /> |
|||
<Compile Include="PropertyMountPointTest.cs" /> |
|||
<Compile Include="ViewModelMock.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Markup\Perspex.Markup.Xaml\Perspex.Markup.Xaml.csproj"> |
|||
<Project>{3E53A01A-B331-47F3-B828-4A5717E77A24}</Project> |
|||
<Name>Perspex.Markup.Xaml</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\NGenerics\NGenerics.csproj"> |
|||
<Project>{415e048e-4611-4815-9cf2-d774e29079ac}</Project> |
|||
<Name>NGenerics</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.Animation\Perspex.Animation.csproj"> |
|||
<Project>{d211e587-d8bc-45b9-95a4-f297c8fa5200}</Project> |
|||
<Name>Perspex.Animation</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.Base\Perspex.Base.csproj"> |
|||
<Project>{B09B78D8-9B26-48B0-9149-D64A2F120F3F}</Project> |
|||
<Name>Perspex.Base</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.Controls\Perspex.Controls.csproj"> |
|||
<Project>{d2221c82-4a25-4583-9b43-d791e3f6820c}</Project> |
|||
<Name>Perspex.Controls</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.Input\Perspex.Input.csproj"> |
|||
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project> |
|||
<Name>Perspex.Input</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.Interactivity\Perspex.Interactivity.csproj"> |
|||
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project> |
|||
<Name>Perspex.Interactivity</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.Layout\Perspex.Layout.csproj"> |
|||
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project> |
|||
<Name>Perspex.Layout</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.ReactiveUI\Perspex.ReactiveUI.csproj"> |
|||
<Project>{6417b24e-49c2-4985-8db2-3ab9d898ec91}</Project> |
|||
<Name>Perspex.ReactiveUI</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
|||
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
|||
<Name>Perspex.SceneGraph</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.Styling\Perspex.Styling.csproj"> |
|||
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project> |
|||
<Name>Perspex.Styling</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\..\src\Perspex.Themes.Default\Perspex.Themes.Default.csproj"> |
|||
<Project>{3e10a5fa-e8da-48b1-ad44-6a5b6cb7750f}</Project> |
|||
<Name>Perspex.Themes.Default</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="packages.config" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
</ItemGroup> |
|||
</When> |
|||
</Choose> |
|||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
|||
<PropertyGroup> |
|||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> |
|||
</PropertyGroup> |
|||
<Error Condition="!Exists('..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" /> |
|||
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.0.1\build\net20\xunit.runner.visualstudio.props'))" /> |
|||
</Target> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,3 @@ |
|||
using System.Reflection; |
|||
|
|||
[assembly: AssemblyTitle("Perspex.Markup.Xaml.UnitTests")] |
|||
@ -0,0 +1,15 @@ |
|||
namespace Perspex.Xaml.Base.UnitTest |
|||
{ |
|||
using Markup.Xaml.DataBinding.ChangeTracking; |
|||
using System; |
|||
using Xunit; |
|||
|
|||
public class PropertyMountPointTest |
|||
{ |
|||
[Fact] |
|||
public void SourceAndPathAreNull() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => new PropertyMountPoint(null, null)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
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(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
public class Level3 : PropertyChangeNotifier |
|||
{ |
|||
private int property = 10; |
|||
|
|||
public int Property |
|||
{ |
|||
get { return property; } |
|||
set |
|||
{ |
|||
property = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="LogInViewModel.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
using ReactiveUI; |
|||
|
|||
public class LogInViewModel : ReactiveObject |
|||
{ |
|||
private string username; |
|||
|
|||
public LogInViewModel() |
|||
{ |
|||
this.OkCommand = ReactiveCommand.Create( |
|||
this.WhenAnyValue( |
|||
x => x.Username, |
|||
x => !string.IsNullOrWhiteSpace(x))); |
|||
} |
|||
|
|||
public string Username |
|||
{ |
|||
get { return this.username; } |
|||
set { this.RaiseAndSetIfChanged(ref this.username, value); } |
|||
} |
|||
|
|||
public ReactiveCommand<object> OkCommand |
|||
{ |
|||
get; |
|||
private set; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="MainWindowViewModel.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace GitHubClient.ViewModels |
|||
{ |
|||
using System; |
|||
using Perspex.Xaml.Base.UnitTest.SampleModel; |
|||
using ReactiveUI; |
|||
|
|||
public class MainWindowViewModel : ReactiveObject |
|||
{ |
|||
private object content; |
|||
|
|||
private LogInViewModel login; |
|||
|
|||
public MainWindowViewModel() |
|||
{ |
|||
this.ShowLogin(); |
|||
} |
|||
|
|||
public object Content |
|||
{ |
|||
get { return this.content; } |
|||
set { this.RaiseAndSetIfChanged(ref this.content, value); } |
|||
} |
|||
|
|||
private void ShowLogin() |
|||
{ |
|||
this.login = new LogInViewModel(); |
|||
this.login.OkCommand.Subscribe(_ => this.ShowRepositories()); |
|||
this.Content = this.login; |
|||
} |
|||
|
|||
private void ShowRepositories() |
|||
{ |
|||
var vm = new UserRepositoriesViewModel(); |
|||
var task = vm.Load(this.login.Username); |
|||
this.Content = vm; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
using System.ComponentModel; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
public abstract class PropertyChangeNotifier : INotifyPropertyChanged |
|||
{ |
|||
public event PropertyChangedEventHandler PropertyChanged; |
|||
|
|||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
|||
{ |
|||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
namespace GitHubClient.ViewModels |
|||
{ |
|||
public class Repository |
|||
{ |
|||
private readonly string name; |
|||
|
|||
public Repository(string name) |
|||
{ |
|||
this.name = name; |
|||
} |
|||
|
|||
public string Name |
|||
{ |
|||
get { return name; } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="UserRepositoriesViewModel.cs" company="Steven Kirk">
|
|||
// Copyright 2015 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest.SampleModel |
|||
{ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using GitHubClient.ViewModels; |
|||
using ReactiveUI; |
|||
|
|||
public class UserRepositoriesViewModel : ReactiveObject |
|||
{ |
|||
private IReadOnlyList<Repository> repositories; |
|||
|
|||
public async Task Load(string username) |
|||
{ |
|||
this.Repositories = await new Task<IReadOnlyList<Repository>>(() => new List<Repository> { new Repository("Blah"), new Repository("Bleh") }); |
|||
} |
|||
|
|||
public IReadOnlyList<Repository> Repositories |
|||
{ |
|||
get { return this.repositories; } |
|||
private set { this.RaiseAndSetIfChanged(ref this.repositories, value); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System; |
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest |
|||
{ |
|||
internal class SamplePerspexObject : PerspexObject |
|||
{ |
|||
public static readonly PerspexProperty<string> StringProperty = |
|||
PerspexProperty.Register<PerspexObject, string>("StrProp", string.Empty); |
|||
|
|||
public static readonly PerspexProperty<int> IntProperty = |
|||
PerspexProperty.Register<PerspexObject, int>("IntProp"); |
|||
|
|||
public int Int |
|||
{ |
|||
get { return GetValue(IntProperty); } |
|||
set { this.SetValue(IntProperty, value); } |
|||
} |
|||
|
|||
public string String |
|||
{ |
|||
get { return GetValue(StringProperty); } |
|||
set { this.SetValue(StringProperty, value); } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
namespace Perspex.Xaml.Base.UnitTest |
|||
{ |
|||
using OmniXaml; |
|||
using System; |
|||
|
|||
class TypeProviderMock : ITypeProvider |
|||
{ |
|||
private readonly string typeName; |
|||
private readonly string clrNamespace; |
|||
private readonly string assemblyName; |
|||
private readonly Type typeToReturn; |
|||
|
|||
public TypeProviderMock(string typeName, string clrNamespace, string assemblyName, Type typeToReturn) |
|||
{ |
|||
this.typeName = typeName; |
|||
this.clrNamespace = clrNamespace; |
|||
this.assemblyName = assemblyName; |
|||
this.typeToReturn = typeToReturn; |
|||
} |
|||
|
|||
public TypeProviderMock() |
|||
{ |
|||
} |
|||
|
|||
public Type GetType(string typeName, string clrNamespace, string assemblyName) |
|||
{ |
|||
if (this.typeName == typeName && this.clrNamespace == clrNamespace && this.assemblyName == assemblyName) |
|||
{ |
|||
return typeToReturn; |
|||
} |
|||
|
|||
throw new TypeNotFoundException("The Type cannot be found"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System.ComponentModel; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
namespace Perspex.Xaml.Base.UnitTest |
|||
{ |
|||
class ViewModelMock : INotifyPropertyChanged |
|||
{ |
|||
private string str; |
|||
private int intProp; |
|||
|
|||
public int IntProp |
|||
{ |
|||
get { return intProp; } |
|||
set |
|||
{ |
|||
intProp = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
|
|||
public string StrProp |
|||
{ |
|||
get { return str; } |
|||
set |
|||
{ |
|||
str = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
|
|||
public event PropertyChangedEventHandler PropertyChanged; |
|||
|
|||
private void OnPropertyChanged([CallerMemberName] string propertyName = null) |
|||
{ |
|||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
namespace Perspex.Xaml.Base.UnitTest |
|||
{ |
|||
using Moq; |
|||
using Markup.Xaml.DataBinding; |
|||
using OmniXaml.TypeConversion; |
|||
using Xunit; |
|||
|
|||
public class XamlBindingTest |
|||
{ |
|||
[Fact] |
|||
public void TestNullDataContext() |
|||
{ |
|||
var t = new Mock<ITypeConverterProvider>(); |
|||
var sut = new XamlBinding(t.Object); |
|||
sut.Bind(null); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="Glass" version="0.1.0" targetFramework="net451" /> |
|||
<package id="Moq" version="4.2.1409.1722" targetFramework="net451" /> |
|||
<package id="Rx-Core" version="2.2.5" targetFramework="net451" /> |
|||
<package id="Rx-Interfaces" version="2.2.5" targetFramework="net451" /> |
|||
<package id="Rx-Linq" version="2.2.5" targetFramework="net451" /> |
|||
<package id="Rx-Main" version="2.2.5" targetFramework="net451" /> |
|||
<package id="Rx-PlatformServices" version="2.2.5" targetFramework="net451" /> |
|||
<package id="Splat" version="1.6.1" targetFramework="net451" /> |
|||
<package id="xunit" version="2.0.0" targetFramework="net451" /> |
|||
<package id="xunit.abstractions" version="2.0.0" targetFramework="net451" /> |
|||
<package id="xunit.assert" version="2.0.0" targetFramework="net451" /> |
|||
<package id="xunit.core" version="2.0.0" targetFramework="net451" /> |
|||
<package id="xunit.extensibility.core" version="2.0.0" targetFramework="net451" /> |
|||
<package id="xunit.runner.visualstudio" version="2.0.1" targetFramework="net451" /> |
|||
</packages> |
|||
Loading…
Reference in new issue