Exemplo n.º 1
0
        /// <summary>
        /// Returns a ReadOnlyEnumerableOfT that is the result of <paramref name="source"/> plus <paramref name="item"/>.
        /// </summary>
        /// <typeparam name="T">The element type of the enumerable.</typeparam>
        /// <param name="source">The source enumerable to concat.</param>
        /// <param name="collectionName">The name of the collection to report in case there's an error.</param>
        /// <param name="item">Item to concat to the source enumerable.</param>
        /// <returns>Returns a ReadOnlyEnumerableOfT that is the result of <paramref name="source"/> plus <paramref name="item"/>.</returns>
        internal static ReadOnlyEnumerable <T> ConcatToReadOnlyEnumerable <T>(this IEnumerable <T> source, string collectionName, T item)
        {
            ReadOnlyEnumerable <T> readOnlyEnumerable = source.GetOrCreateReadOnlyEnumerable(collectionName);

            readOnlyEnumerable.AddToSourceList(item);
            return(readOnlyEnumerable);
        }
 public void AddToSourceListShouldAddToTheSourceList()
 {
     ReadOnlyEnumerable<int> enumerable = new ReadOnlyEnumerable<int>();
     enumerable.Should().BeEmpty();
     enumerable.AddToSourceList(1);
     enumerable.Count().Should().Be(1);
     enumerable.Should().OnlyContain(i => i == 1);
 }
 /// <summary>
 /// Creates a new instance of ATOM feed metadata.
 /// </summary>
 /// <returns>The newly created ATOM feed metadata.</returns>
 internal static AtomFeedMetadata CreateNewAtomFeedMetadata()
 {
     return(new AtomFeedMetadata
     {
         Authors = ReadOnlyEnumerable <AtomPersonMetadata> .Empty(),
         Categories = ReadOnlyEnumerable <AtomCategoryMetadata> .Empty(),
         Contributors = ReadOnlyEnumerable <AtomPersonMetadata> .Empty(),
         Links = ReadOnlyEnumerable <AtomLinkMetadata> .Empty(),
     });
 }
Exemplo n.º 4
0
        /// <summary>
        /// Casts an IEnumerableOfT to ReadOnlyEnumerableOfT.
        /// </summary>
        /// <typeparam name="T">The element type of the enumerable.</typeparam>
        /// <param name="source">The source enumerable.</param>
        /// <param name="collectionName">The name of the collection to report in case there's an error.</param>
        /// <returns>The casted ReadOnlyEnumerableOfT.</returns>
        internal static ReadOnlyEnumerable <T> ToReadOnlyEnumerable <T>(this IEnumerable <T> source, string collectionName)
        {
            Debug.Assert(!String.IsNullOrEmpty(collectionName), "!string.IsNullOrEmpty(collectionName)");

            ReadOnlyEnumerable <T> readonlyCollection = source as ReadOnlyEnumerable <T>;

            if (readonlyCollection == null)
            {
                throw new ODataException(Strings.ReaderUtils_EnumerableModified(collectionName));
            }

            return(readonlyCollection);
        }
 public void ConcatToReadOnlyEnumerableShouldAddForReadOnlyEnumerableSource()
 {
     var enumerable = new ReadOnlyEnumerable<ODataProperty>();
     enumerable.Count().Should().Be(0);
     enumerable.ConcatToReadOnlyEnumerable("Properties", new ODataProperty());
     enumerable.Count().Should().Be(1);
 }
 public void GetOrCreateReadOnlyEnumerableShouldGetForReadOnlyEnumerableSource()
 {
     var enumerable = new ReadOnlyEnumerable<int>();
     var enumerable2 = enumerable.GetOrCreateReadOnlyEnumerable("Integers");
     enumerable2.As<object>().Should().NotBeSameAs(ReadOnlyEnumerable<int>.Empty());
     enumerable2.As<object>().Should().BeSameAs(enumerable);
 }
Exemplo n.º 7
0
 /// <summary>
 /// true if <paramref name="source"/> is the same instance as ReadOnlyEnumerableOfT.Empty(). false otherwise.
 /// </summary>
 /// <typeparam name="T">The element type of the enumerable.</typeparam>
 /// <param name="source">The enumerable in question.</param>
 /// <returns>Returns true if <paramref name="source"/> is the empty ReadOnlyEnumerableOfT. false otherwise.</returns>
 internal static bool IsEmptyReadOnlyEnumerable <T>(this IEnumerable <T> source)
 {
     return(ReferenceEquals(source, ReadOnlyEnumerable <T> .Empty()));
 }