Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Added requested tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shimmy Weitzhandler authored and Shimmy Weitzhandler committed Sep 14, 2017
1 parent 6353a8f commit 4cba646
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,18 @@ protected static IEnumerable<object[]> ValidValues_ICollection()
yield return new object[] { new MaxLengthAttribute(15), new List<string>(new string[14]) };
yield return new object[] { new MaxLengthAttribute(16), new List<string>(new string[16]) };

//ICollection<T> but not ICollection
yield return new object[] { new MaxLengthAttribute(-1), new HashSet<int>(Enumerable.Range(1, 20)) };
yield return new object[] { new MaxLengthAttribute(15), new HashSet<string>(Enumerable.Range(1, 14).Select(i => i.ToString())) };
yield return new object[] { new MaxLengthAttribute(16), new HashSet<string>(Enumerable.Range(1, 16).Select(i => i.ToString())) };

//ICollection but not ICollection<T>
yield return new object[] { new MaxLengthAttribute(-1), new ArrayList(new int[20]) };
yield return new object[] { new MaxLengthAttribute(15), new ArrayList(new string[14]) };
yield return new object[] { new MaxLengthAttribute(16), new ArrayList(new string[16]) };

//Multi ICollection<T>
yield return new object[] { new MaxLengthAttribute(1), new MultiCollection() };
}

protected override IEnumerable<TestCase> InvalidValues()
Expand Down Expand Up @@ -127,4 +136,25 @@ class GenericIEnumerableClass : IEnumerable<int>
public IEnumerator<int> GetEnumerator() => Enumerable.Empty<int>().GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

public class MultiCollection : Collection<string>, ICollection<int>, ICollection<uint>
{
int ICollection<int>.Count => 0;
int ICollection<uint>.Count => 0;
bool ICollection<int>.IsReadOnly => throw new NotSupportedException();
bool ICollection<uint>.IsReadOnly => throw new NotSupportedException();
void ICollection<int>.Add(int item) => throw new NotSupportedException();
void ICollection<uint>.Add(uint item) => throw new NotSupportedException();
void ICollection<int>.Clear() => throw new NotSupportedException();
void ICollection<uint>.Clear() => throw new NotSupportedException();
bool ICollection<int>.Contains(int item) => throw new NotSupportedException();
bool ICollection<uint>.Contains(uint item) => throw new NotSupportedException();
void ICollection<int>.CopyTo(int[] array, int arrayIndex) => throw new NotSupportedException();
void ICollection<uint>.CopyTo(uint[] array, int arrayIndex) => throw new NotSupportedException();
IEnumerator<int> IEnumerable<int>.GetEnumerator() => throw new NotSupportedException();
IEnumerator IEnumerable.GetEnumerator() => throw new NotSupportedException();
IEnumerator<uint> IEnumerable<uint>.GetEnumerator() => throw new NotSupportedException();
bool ICollection<int>.Remove(int item) => throw new NotSupportedException();
bool ICollection<uint>.Remove(uint item) => throw new NotSupportedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
Expand Down Expand Up @@ -33,9 +34,18 @@ protected static IEnumerable<object[]> ValidValues_ICollection()
yield return new object[] { new MinLengthAttribute(12), new List<int>(new int[14]) };
yield return new object[] { new MinLengthAttribute(16), new List<string>(new string[16]) };

//ICollection<T> but not ICollection
yield return new object[] { new MinLengthAttribute(0), new HashSet<int>() };
yield return new object[] { new MinLengthAttribute(12), new HashSet<int>(Enumerable.Range(1, 14)) };
yield return new object[] { new MinLengthAttribute(16), new HashSet<string>(Enumerable.Range(1, 16).Select(i => i.ToString())) };

//ICollection but not ICollection<T>
yield return new object[] { new MinLengthAttribute(0), new ArrayList(new int[0]) };
yield return new object[] { new MinLengthAttribute(12), new ArrayList(new int[14]) };
yield return new object[] { new MinLengthAttribute(16), new ArrayList(new string[16]) };

//Multi ICollection<T>
yield return new object[] { new MinLengthAttribute(0), new MultiCollection() };
}

protected override IEnumerable<TestCase> InvalidValues()
Expand Down

0 comments on commit 4cba646

Please sign in to comment.