public void IListOfTInsertShouldThrowException()
        {
            // arrange
            var source = new ObservableKeyedCollection<string, object>( o => o.ToString() );
            IList<object> target = new ReadOnlyObservableKeyedCollection<string, object>( source );

            // act
            Assert.Throws<NotSupportedException>( () => target.Insert( 0, new object() ) );

            // assert
        }
        public void IndexerShouldReturnExpectedValue()
        {
            var source = new ObservableKeyedCollection<string, object>( o => o.ToString() );
            var target = new ReadOnlyObservableKeyedCollection<string, object>( source );
            var expected = new object();
            
            source.Add( expected );

            var actual = target[0];
            Assert.Equal( expected, actual );

            actual = target[expected.ToString()];
            Assert.Equal( expected, actual );
        }
        public void IndexOfShouldReturnExpectedValue()
        {
            // arrange
            var source = new ObservableKeyedCollection<string, object>( o => o.ToString() );
            var target = new ReadOnlyObservableKeyedCollection<string, object>( source );
            var item = new object();
            var expected = 0;

            source.Add( item );

            // act
            var actual = target.IndexOf( item );

            // assert
            Assert.Equal( expected, actual );
        }
        public void IListIndexerShouldThrowExceptionOnWrite()
        {
            // arrange
            var source = new ObservableKeyedCollection<string, object>( o => o.ToString() );
            IList target = new ReadOnlyObservableKeyedCollection<string, object>( source );

            source.Add( new object() );

            // act
            Assert.Throws<NotSupportedException>( () => target[0] = new object() );

            // assert
        }
        public void IListRemoveShouldThrowException()
        {
            // arrange
            var source = new ObservableKeyedCollection<string, object>( o => o.ToString() );
            IList target = new ReadOnlyObservableKeyedCollection<string, object>( source );
            var item = new object();

            source.Add( item );

            // act
            Assert.Throws<NotSupportedException>( () => target.Remove( item ) );

            // assert
        }
        public void IListIsReadOnlyShouldAlwaysReturnTrue()
        {
            // arrange
            var source = new ObservableKeyedCollection<string, object>( o => o.ToString() );
            IList target = new ReadOnlyObservableKeyedCollection<string, object>( source );

            // act
            var actual = target.IsReadOnly;

            // assert
            Assert.True( actual );
        }
        public void IListIndexOfShouldNotMatchIncompatibleItemType()
        {
            // arrange
            var source = new ObservableKeyedCollection<string, string>( o => o.ToString() );
            IList target = new ReadOnlyObservableKeyedCollection<string, string>( source );
            var expected = -1;

            source.Add( "test" );

            // act
            var actual = target.IndexOf( new object() );

            // assert
            Assert.Equal( expected, actual );
        }
        public void IListContainsShouldNotMatchIncompatibleItemType()
        {
            // arrange
            var source = new ObservableKeyedCollection<string, string>( o => o.ToString() );
            IList target = new ReadOnlyObservableKeyedCollection<string, string>( source );
            var item = "test";

            source.Add( item );

            // act
            var actual = target.Contains( new object() );

            // assert
            Assert.False( actual );
        }
        public void IListContainsShouldMatchSourceCollection()
        {
            // arrange
            var source = new ObservableKeyedCollection<string, object>( o => o.ToString() );
            IList target = new ReadOnlyObservableKeyedCollection<string, object>( source );
            var item = new object();

            source.Add( item );

            // act

            // assert
            Assert.True( target.Contains( item ) );
            Assert.False( target.Contains( new object() ) );
        }
        public void CopyToShouldCopySourceItems()
        {
            // arrange
            var source = new ObservableKeyedCollection<string, object>( o => o.GetHashCode().ToString() );
            var target = new ReadOnlyObservableKeyedCollection<string, object>( source );
            var expected = new[] { new object(), new object(), new object() };
            var actual = new object[3];

            source.AddRange( expected );

            // act
            target.CopyTo( actual, 0 );

            // assert
            Assert.True( actual.SequenceEqual( expected ) );
        }
 public void ICollectionOfTClearShouldThrowException()
 {
     var source = new ObservableKeyedCollection<string, object>( o => o.ToString() );
     ICollection<object> target = new ReadOnlyObservableKeyedCollection<string, object>( source );
     source.Add( new object() );
     Assert.Throws<NotSupportedException>( () => target.Clear() );
 }