Permalink
Browse files

Merge remote-tracking branch 'origin/master' into xamarin-mobile

  • Loading branch information...
2 parents 7370bd7 + bad6143 commit 021f6d83b3b7a11ce078e61773a7b46a1ac76950 @paulcbetts paulcbetts committed Mar 21, 2013
@@ -52,6 +52,8 @@ public RoutedViewHost()
HorizontalContentAlignment = HorizontalAlignment.Stretch;
VerticalContentAlignment = VerticalAlignment.Stretch;
+ if (RxApp.InUnitTestRunner()) return;
+
this.WhenAny(x => x.Router.NavigationStack, x => x.Value)
.SelectMany(x => x.CollectionCountChanged.StartWith(x.Count).Select(_ => x.LastOrDefault()))
.Subscribe(vm => {
@@ -0,0 +1,96 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using Xunit;
+
+namespace ReactiveUI.Tests
+{
+ public class OrderedComparerTests
+ {
+ [DebuggerDisplay("{Name}")]
+ public class Employee
+ {
+ public string Name;
+ public int Age;
+ public int Salary;
+ }
+
+ [Fact]
+ public void SmokeTest()
+ {
+ var adam = new Employee { Name = "Adam", Age = 50, Salary = 125 };
+ var alice = new Employee { Name = "Alice", Age = 25, Salary = 100 };
+ var bob = new Employee { Name = "Bob", Age = 30, Salary = 75 };
+ var carol = new Employee { Name = "Carol", Age = 35, Salary = 100 };
+ var xavier = new Employee { Name = "Xavier", Age = 35, Salary = 100 };
+
+ var employees = new List<Employee> { adam, alice, bob, carol, xavier };
+
+ employees.Sort(OrderedComparer<Employee>.OrderBy(x => x.Name));
+ Assert.True(employees.SequenceEqual(new[] { adam, alice, bob, carol, xavier }));
+
+ employees.Sort(OrderedComparer<Employee>
+ .OrderByDescending(x => x.Age)
+ .ThenBy(x => x.Name)
+ );
+ Assert.True(employees.SequenceEqual(new[] { adam, carol, xavier, bob, alice }));
+
+ employees.Sort(OrderedComparer<Employee>
+ .OrderByDescending(x => x.Salary)
+ .ThenBy(x => x.Name, StringComparer.OrdinalIgnoreCase)
+ );
+ Assert.True(employees.SequenceEqual(new[] { adam, alice, carol, xavier, bob }));
+
+ employees.Sort(OrderedComparer<Employee>
+ .OrderByDescending(x => x.Age)
+ .ThenByDescending(x => x.Salary)
+ .ThenBy(x => x.Name)
+ );
+ Assert.True(employees.SequenceEqual(new[] { adam, carol, xavier, bob, alice }));
+ }
+
+ [Fact]
+ public void CustomComparerTest()
+ {
+ var items = new List<string> { "aaa", "AAA", "abb", "aaaa" };
+
+ items.Sort(OrderedComparer<string>.OrderBy(x => x, StringComparer.Ordinal));
+ Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "aaaa", "abb" }));
+
+ items.Sort(OrderedComparer<string>.OrderByDescending(x => x.Length).ThenBy(x => x, StringComparer.Ordinal));
+ Assert.True(items.SequenceEqual(new[] { "aaaa", "AAA", "aaa", "abb" }));
+
+ items.Sort(OrderedComparer<string>.OrderBy(x => x.Length).ThenBy(x => x, StringComparer.Ordinal));
+ Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "abb", "aaaa" }));
+
+ items.Sort(OrderedComparer<string>.OrderBy(x => x.Length).ThenBy(x => x, StringComparer.OrdinalIgnoreCase));
+ Assert.True(items.SequenceEqual(new[] { "AAA", "AAA", "abb", "aaaa" }, StringComparer.OrdinalIgnoreCase));
+ }
+
+ [Fact]
+ public void ChainOntoRegularIComparables()
+ {
+ var items = new List<string> { "aaa", "AAA", "abb", "aaaa" };
+ var comparer = StringComparer.OrdinalIgnoreCase;
+
+ items.Sort(comparer);
+ Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "aaaa", "abb" }, StringComparer.OrdinalIgnoreCase));
+
+ items.Sort(comparer.ThenByDescending(x => x, StringComparer.Ordinal));
+ Assert.True(items.SequenceEqual(new[] { "aaa", "AAA", "aaaa", "abb" }, StringComparer.Ordinal));
+ }
+
+ [Fact]
+ public void WorksWithAnonymousTypes()
+ {
+ var source = new List<string> { "abc", "bcd", "cde" };
+ var items = source.Select(x => new { FirstLetter = x[0], AllOfIt = x }).ToList();
+
+ items.Sort(OrderedComparer.For(items).OrderBy(x => x.FirstLetter));
+ Assert.True(items.Select(x => x.FirstLetter).SequenceEqual("abc"));
+
+ }
+ }
+}
@@ -9,6 +9,9 @@
using Xunit;
using Microsoft.Reactive.Testing;
+using System.Collections.Specialized;
+using System.Reactive.Subjects;
+using System.Reactive;
namespace ReactiveUI.Tests
{
@@ -342,6 +345,31 @@ public void DerivedCollectionShouldBeSorted()
Assert.True(new[] { "Bamf", "Bar", "Bar", "Baz", "Eoo", "Foo", "Roo" }.Zip(output, (expected, actual) => expected == actual).All(x => x));
}
+ [Fact]
+ public void DerivedCollectionSignalledToResetShouldFireExactlyOnce()
+ {
+ var input = new List<string> { "Foo" };
+ var resetSubject = new Subject<Unit>();
+ var derived = input.CreateDerivedCollection(x => x, signalReset: resetSubject);
+
+ var changeNotifications = new List<NotifyCollectionChangedEventArgs>();
+ derived.Changed.Subscribe(changeNotifications.Add);
+
+ Assert.Equal(0, changeNotifications.Count);
+ Assert.Equal(1, derived.Count);
+
+ input.Add("Bar");
+
+ // Shouldn't have picked anything up since the input isn't reactive
+ Assert.Equal(0, changeNotifications.Count);
+ Assert.Equal(1, derived.Count);
+
+ resetSubject.OnNext(Unit.Default);
+
+ Assert.Equal(1, changeNotifications.Count);
+ Assert.Equal(2, derived.Count);
+ }
+
[Fact]
public void AddRangeSmokeTest()
{
@@ -119,6 +119,7 @@
<Compile Include="MessageBusTest.cs" />
<Compile Include="ObservableAsPropertyHelperTest.cs" />
<Compile Include="ObservedChangedMixinTest.cs" />
+ <Compile Include="OrderedComparerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PropertyBindingTest.cs" />
<Compile Include="ReactiveCollectionTest.cs" />
@@ -67,6 +67,7 @@
<Compile Include="ObservableAsPropertyHelperTest.cs" />
<Compile Include="ObservableAsyncMRUCacheTest.cs" />
<Compile Include="ObservedChangedMixinTest.cs" />
+ <Compile Include="OrderedComparerTests.cs" />
<Compile Include="ReactiveCollectionTest.cs" />
<Compile Include="ReactiveCommandTest.cs" />
<Compile Include="ReactiveNotifyPropertyChangedMixinTest.cs" />
@@ -145,6 +145,7 @@
<Compile Include="MessageBusTest.cs" />
<Compile Include="ObservableAsPropertyHelperTest.cs" />
<Compile Include="ObservableAsyncMRUCacheTest.cs" />
+ <Compile Include="OrderedComparerTests.cs" />
<Compile Include="ObservedChangedMixinTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PropertyBindingTest.cs" />
Oops, something went wrong.

0 comments on commit 021f6d8

Please sign in to comment.