浏览代码

Fixing a null reference in ImmutableList<T>.

Bart De Smet 10 年之前
父节点
当前提交
8718bd37b9

+ 2 - 2
Rx.NET/Source/System.Reactive.Core/Reactive/Internal/ImmutableList.cs

@@ -48,10 +48,10 @@ namespace System.Reactive
             return new ImmutableList<T>(newData);
         }
 
-        public int IndexOf(T value)
+        private int IndexOf(T value)
         {
             for (var i = 0; i < _data.Length; ++i)
-                if (_data[i].Equals(value))
+                if (object.Equals(_data[i], value))
                     return i;
 
             return -1;

+ 1 - 0
Rx.NET/Source/Tests.System.Reactive/Tests.System.Reactive.csproj

@@ -88,6 +88,7 @@
     <Compile Include="Tests\Concurrency\ThreadPoolSchedulerTest.cs" />
     <Compile Include="Tests\Concurrency\VirtualSchedulerTest.cs" />
     <Compile Include="Tests\Disposables\DisposableTests.cs" />
+    <Compile Include="Tests\ImmutableListTest.cs" />
     <Compile Include="Tests\Linq\ObservableAggregateTest.cs" />
     <Compile Include="Tests\Linq\ObservableAsyncTest.cs" />
     <Compile Include="Tests\Linq\ObservableAwaiterTest.cs" />

+ 66 - 0
Rx.NET/Source/Tests.System.Reactive/Tests/ImmutableListTest.cs

@@ -0,0 +1,66 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Linq;
+using System.Reactive;
+
+namespace ReactiveTests.Tests
+{
+#if !SIGNED
+    [TestClass]
+    public class ImmutableListTest
+    {
+        [TestMethod]
+        public void ImmutableList_Basics()
+        {
+            var list = new ImmutableList<int>();
+
+            Assert.IsTrue(list.Data.SequenceEqual(new int[] { }));
+
+            list = list.Add(42);
+
+            Assert.IsTrue(list.Data.SequenceEqual(new int[] { 42 }));
+
+            list = list.Remove(42);
+
+            Assert.IsTrue(list.Data.SequenceEqual(new int[] { }));
+
+            list = list.Remove(42);
+
+            Assert.IsTrue(list.Data.SequenceEqual(new int[] { }));
+
+            list = list.Add(43);
+            list = list.Add(44);
+            list = list.Add(43);
+
+            Assert.IsTrue(list.Data.SequenceEqual(new int[] { 43, 44, 43 }));
+
+            list = list.Remove(43);
+
+            Assert.IsTrue(list.Data.SequenceEqual(new int[] { 44, 43 }));
+
+            list = list.Remove(43);
+
+            Assert.IsTrue(list.Data.SequenceEqual(new int[] { 44 }));
+
+            list = list.Remove(44);
+
+            Assert.IsTrue(list.Data.SequenceEqual(new int[] { }));
+        }
+
+        [TestMethod]
+        public void ImmutableList_Nulls()
+        {
+            var list = new ImmutableList<string>();
+
+            Assert.IsTrue(list.Data.SequenceEqual(new string[] { }));
+
+            list = list.Add(null);
+
+            Assert.IsTrue(list.Data.SequenceEqual(new string[] { null }));
+
+            list = list.Remove(null);
+
+            Assert.IsTrue(list.Data.SequenceEqual(new string[] { }));
+        }
+        }
+#endif
+}