-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a little starting point thread safety and test coverage for Multi…
…SelectorBehaviours and TwoListSynchronizer.
- Loading branch information
Showing
14 changed files
with
769 additions
and
42 deletions.
There are no files selected for viewing
136 changes: 136 additions & 0 deletions
136
PrimS.SelectedItemsSynchronizer.CiTests/MultiSelectorBehavioursTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
namespace PrimS.SelectedItemsSynchronizer.CiTests | ||
{ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Windows.Controls; | ||
|
||
[TestClass] | ||
public class MultiSelectorBehavioursTests | ||
{ | ||
List<string> names; | ||
ObservableCollection<string> selectedNames; | ||
ListView listView; | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
names = new List<string>() { "Abraham", "Lincoln", "James", "Buchanan" }; | ||
selectedNames = new ObservableCollection<string>(); | ||
listView = new ListView(); | ||
listView.ItemsSource = names; | ||
listView.SelectionMode = SelectionMode.Extended; | ||
MultiSelectorBehaviours.SetSynchronizedSelectedItems(listView, (IList)selectedNames); | ||
} | ||
|
||
[TestMethod] | ||
public void InitialiseToNoSelection() | ||
{ | ||
this.selectedNames.Count().Should().Be(0); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldSynchroniseListViewSelectAll() | ||
{ | ||
// Act | ||
this.listView.SelectAll(); | ||
|
||
// Assert | ||
this.selectedNames.Count().Should().Be(this.names.Count()); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldSynchroniseListViewSetSelectedIndex() | ||
{ | ||
// Act | ||
this.listView.SelectedIndex = 0; | ||
|
||
// Assert | ||
this.selectedNames.Count().Should().Be(1); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldSynchroniseListViewSetSelectedItem() | ||
{ | ||
//Arrange | ||
Random random = new Random(DateTime.Now.Millisecond); | ||
object itemToSelect = this.listView.Items.GetItemAt(random.Next(this.names.Count)); | ||
|
||
// Act | ||
this.listView.SelectedItem = itemToSelect; | ||
|
||
// Assert | ||
this.selectedNames.Count().Should().Be(1); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldSynchroniseListViewAddSingleSelectedItem() | ||
{ | ||
//Arrange | ||
Random random = new Random(DateTime.Now.Millisecond); | ||
object itemToSelect = this.listView.Items.GetItemAt(random.Next(this.names.Count)); | ||
|
||
// Act | ||
this.listView.SelectedItems.Add(itemToSelect); | ||
|
||
// Assert | ||
this.selectedNames.Count().Should().Be(1); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldSynchroniseListViewAddMultipleSelectedItems() | ||
{ | ||
// Act | ||
this.listView.SelectedItems.Add(this.listView.Items.GetItemAt(0)); | ||
this.listView.SelectedItems.Add(this.listView.Items.GetItemAt(1)); | ||
|
||
// Assert | ||
this.selectedNames.ShouldBeEquivalentTo(this.listView.SelectedItems, opt => opt.WithStrictOrdering()); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldSynchroniseListAddMultipleSelectedItems() | ||
{ | ||
// Act | ||
this.selectedNames.Add(this.names.First()); | ||
this.selectedNames.Add(this.names.Last()); | ||
|
||
// Assert | ||
this.listView.SelectedItems.ShouldBeEquivalentTo(this.selectedNames, opt => opt.WithStrictOrdering()); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldNotSynchroniseListAddMultipleSelectedItems() | ||
{ | ||
//Arrange | ||
ObservableCollection<string> secondSelectedNames = new ObservableCollection<string>(); | ||
|
||
// Act | ||
MultiSelectorBehaviours.SetSynchronizedSelectedItems(listView, (IList)secondSelectedNames); | ||
this.selectedNames.Add(this.names.First()); | ||
this.selectedNames.Add(this.names.Last()); | ||
|
||
// Assert | ||
this.listView.SelectedItems.Should().NotBeEquivalentTo(this.selectedNames); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldSynchroniseChangedListAddMultipleSelectedItems() | ||
{ | ||
//Arrange | ||
ObservableCollection<string> secondSelectedNames = new ObservableCollection<string>(); | ||
|
||
// Act | ||
MultiSelectorBehaviours.SetSynchronizedSelectedItems(listView, (IList)secondSelectedNames); | ||
secondSelectedNames.Add(this.names.First()); | ||
secondSelectedNames.Add(this.names.Last()); | ||
|
||
// Assert | ||
this.listView.SelectedItems.ShouldBeEquivalentTo(secondSelectedNames); | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
PrimS.SelectedItemsSynchronizer.CiTests/PrimS.SelectedItemsSynchronizer.CiTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{918FE624-1E12-48BE-A3F0-FC1B5CF1412F}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>PrimS.SelectedItemsSynchronizer.CiTests</RootNamespace> | ||
<AssemblyName>PrimS.SelectedItemsSynchronizer.CiTests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<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> | ||
</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="FluentAssertions"> | ||
<HintPath>..\packages\FluentAssertions.3.3.0.20\lib\net45\FluentAssertions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="FluentAssertions.Core"> | ||
<HintPath>..\packages\FluentAssertions.3.3.0.20\lib\net45\FluentAssertions.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="PresentationCore" /> | ||
<Reference Include="PresentationFramework" /> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Xaml" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="WindowsBase" /> | ||
</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> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" /> | ||
</ItemGroup> | ||
</Otherwise> | ||
</Choose> | ||
<ItemGroup> | ||
<Compile Include="MultiSelectorBehavioursTests.cs" /> | ||
<Compile Include="TwoListSynchronizerDeletionBehaviour.cs" /> | ||
<Compile Include="TwoListSynchronizerInitialization.cs" /> | ||
<Compile Include="TwoListSynchronizerInsertionBehaviour.cs" /> | ||
<Compile Include="TwoListSynchronizerMoveBehaviour.cs" /> | ||
<Compile Include="TwoListSynchronizerReplacementBehaviour.cs" /> | ||
<Compile Include="TwoListSynchronizerAdditionBehaviour.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\SelectedItemsSynchronizer\PrimS.SelectedItemsSynchronizer.csproj"> | ||
<Project>{6fd3314f-9a43-4fcf-a073-6c97ca2d1e81}</Project> | ||
<Name>PrimS.SelectedItemsSynchronizer</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</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" /> | ||
<!-- 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> |
36 changes: 36 additions & 0 deletions
36
PrimS.SelectedItemsSynchronizer.CiTests/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("PrimS.SelectedItemsSynchronizer.CiTests")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("PrimS.SelectedItemsSynchronizer.CiTests")] | ||
[assembly: AssemblyCopyright("Copyright © 2014")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("5726167d-d6a5-4e8b-930f-e5d3009afd66")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
65 changes: 65 additions & 0 deletions
65
PrimS.SelectedItemsSynchronizer.CiTests/TwoListSynchronizerAdditionBehaviour.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
namespace PrimS.SelectedItemsSynchronizer.CiTests | ||
{ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class TwoListSynchronizerAdditionBehaviour | ||
{ | ||
private ObservableCollection<string> masterList; | ||
private ObservableCollection<string> targetList; | ||
private TwoListSynchronizer sut; | ||
|
||
[ClassInitialize] | ||
public static void ClassInitialize(TestContext context) | ||
{ | ||
} | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
this.masterList = new ObservableCollection<string>(); | ||
this.targetList = new ObservableCollection<string>(); | ||
this.sut = new TwoListSynchronizer(this.masterList, this.targetList); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldNotSynchroniseAddition() | ||
{ | ||
// Act | ||
this.masterList.Add("testString"); | ||
|
||
// Assert | ||
this.targetList.Count().Should().Be(0); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldSynchroniseAddition() | ||
{ | ||
// Arrange | ||
this.sut.StartSynchronizing(); | ||
|
||
// Act | ||
this.masterList.Add("testString"); | ||
|
||
// Assert | ||
this.targetList.Count().Should().Be(1); | ||
} | ||
|
||
[TestMethod] | ||
public void ShouldSynchroniseAdditionOnTarget() | ||
{ | ||
// Arrange | ||
this.sut.StartSynchronizing(); | ||
|
||
// Act | ||
this.targetList.Add("testString"); | ||
|
||
// Assert | ||
this.masterList.Count().Should().Be(1); | ||
} | ||
} | ||
} |
Oops, something went wrong.