Esempio n. 1
0
        private void VerifyResult(bool after)
        {
            Search  search          = EverythingInFolders();
            XmlNode expectedResults = GetExpectedResults(after);

            MW(delegate() { ComparerAdapter.CompareResults(search, expectedResults); });
        }
        public void IEqualityComparerEqualsShouldReturnTrueWhenItemsAreEqual()
        {
            IEqualityComparer t1 = new ComparerAdapter<string, int>( s => s.Length );   // ref type
            Assert.True( t1.Equals( "TEST", "test" ) );                                 // compared by length

            IEqualityComparer t2 = new ComparerAdapter<DateTime, int>( d => d.Day );    // value type
            var actual = t2.Equals( new DateTime( 2012, 1, 1 ), new DateTime( 2013, 1, 1 ) );
            Assert.True( actual );                                                      // compared by day
        }
        public void GetHashCodeShouldReturnZeroForNull()
        {
            // arrange
            var target = new ComparerAdapter<string, int>( s => s.Length );

            // act
            var actual = target.GetHashCode( null );

            Assert.Equal( 0, actual );
        }
        public void IEqualityComparerEqualsShouldReturnTrueWhenItemsAreNull()
        {
            // arrange
            var target = new ComparerAdapter<string, int>( s => s.Length );

            // act
            var actual = target.Equals( null, null );

            // assert
            Assert.True( actual );
        }
        public void GetHashCodeShouldReturnExpectedValue()
        {
            // arrange
            var value = "test";
            var expected = EqualityComparer<int>.Default.GetHashCode( value.Length );
            var target = new ComparerAdapter<string, int>( s => s.Length );

            // act
            var actual = target.GetHashCode( value );

            // assert
            Assert.Equal( expected, actual );
        }
        public void IComparerCompareShouldReturnNegativeOneWhenRightSideIsGreater()
        {
            // arrange
            IComparer target = new ComparerAdapter<string, int>( s => s.Length );

            // act
            var actual = target.Compare( "short", "longer" );

            // assert
            Assert.Equal( -1, actual );
        }
        public void CompareShouldReturnOneWhenLeftSideIsGreater()
        {
            // arrange
            var target = new ComparerAdapter<string, int>( s => s.Length );

            // act
            var actual = target.Compare( "longer", "short" );

            // assert
            Assert.Equal( 1, actual );
        }
        public void IComparerCompareShouldReturnZeroWhenItemsAreEqual()
        {
            IComparer t1 = new ComparerAdapter<string, int>( s => s.Length );   // ref type
            Assert.Equal( 0, t1.Compare( "TEST", "test" ) );                    // compared by length

            IComparer t2 = new ComparerAdapter<DateTime, int>( d => d.Day );    // value type
            var actual = t2.Compare( new DateTime( 2012, 1, 1 ), new DateTime( 2013, 1, 1 ) );
            Assert.Equal( 0, actual );                                          // compared by day
        }
        public void IComparerCompareShouldReturnZeroWhenItemsAreNull()
        {
            // arrange
            IComparer target = new ComparerAdapter<string, int>( s => s.Length );

            // act
            var actual = target.Compare( null, null );

            // assert
            Assert.Equal( 0, actual );
        }