@@ -59,7 +59,8 @@ public void CopyFromDoesNotLoseAvatar()
5959
6060 //Demonstrating that the avatar is present
6161 Assert . NotNull ( col [ 0 ] . Avatar ) ;
62- Assert . Equal ( true , BitmapImageExtensions . IsEqual ( col [ 0 ] . Avatar , userImage ) ) ;
62+ Assert . True ( BitmapSourcesAreEqual ( col [ 0 ] . Avatar , userImage ) ) ;
63+ Assert . False ( BitmapSourcesAreEqual ( col [ 0 ] . Avatar , orgImage ) ) ;
6364
6465 //Creating an observable that will return in one second
6566 var updatedBitmapSourceObservable = generateObservable ( 1 , orgImage ) ;
@@ -97,24 +98,21 @@ public void CopyFromDoesNotLoseAvatar()
9798
9899 //CopyFrom() should not cause a race condition here
99100 Assert . NotNull ( col [ 0 ] . Avatar ) ;
100- Assert . Equal ( true , BitmapImageExtensions . IsEqual ( ( col [ 0 ] . Avatar as BitmapImage ) , orgImage ) ) ;
101+ Assert . True ( BitmapSourcesAreEqual ( col [ 0 ] . Avatar , orgImage ) ) ;
102+ Assert . False ( BitmapSourcesAreEqual ( col [ 0 ] . Avatar , userImage ) ) ;
101103 }
102- }
103-
104- public static class BitmapImageExtensions
105- {
106- //http://stackoverflow.com/questions/15558107/quickest-way-to-compare-two-bitmapimages-to-check-if-they-are-different-in-wpf
107104
108- public static bool IsEqual ( BitmapSource image1 , BitmapSource image2 )
105+ public static bool BitmapSourcesAreEqual ( BitmapSource image1 , BitmapSource image2 )
109106 {
110107 if ( image1 == null || image2 == null )
111108 {
112109 return false ;
113110 }
114- return ToBytes ( image1 ) . SequenceEqual ( ToBytes ( image2 ) ) ;
111+
112+ return BitmapSourceToBytes ( image1 ) . SequenceEqual ( BitmapSourceToBytes ( image2 ) ) ;
115113 }
116114
117- public static byte [ ] ToBytes ( BitmapSource image )
115+ public static byte [ ] BitmapSourceToBytes ( BitmapSource image )
118116 {
119117 byte [ ] data = new byte [ ] { } ;
120118 if ( image != null )
@@ -134,6 +132,7 @@ public static byte[] ToBytes(BitmapSource image)
134132 {
135133 }
136134 }
135+
137136 return data ;
138137 }
139138 }
0 commit comments