OSDN Git Service

イベントのテストにAssert.Raisesを使用する
[opentween/open-tween.git] / OpenTween.Tests / TweetThumbnailTest.cs
index 1529e74..3fd0dcc 100644 (file)
@@ -31,6 +31,7 @@ using System.Threading;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using Moq;
+using OpenTween.Models;
 using OpenTween.Thumbnail;
 using OpenTween.Thumbnail.Services;
 using Xunit;
@@ -64,8 +65,8 @@ namespace OpenTween
 
                 return new MockThumbnailInfo
                 {
-                    ImageUrl = url,
-                    ThumbnailUrl = match.Result(this.replaceUrl),
+                    MediaPageUrl = url,
+                    ThumbnailImageUrl = match.Result(this.replaceUrl),
                     TooltipText = this.replaceTooltip != null ? match.Result(this.replaceTooltip) : null,
                 };
             }
@@ -142,7 +143,7 @@ namespace OpenTween
 
                 tokenSource.Cancel();
 
-                await TestUtils.ThrowsAnyAsync<OperationCanceledException>(async () => await task);
+                await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await task);
                 Assert.True(task.IsCanceled);
             }
         }
@@ -204,8 +205,8 @@ namespace OpenTween
                 Assert.IsAssignableFrom<ThumbnailInfo>(thumbbox.pictureBox[0].Tag);
                 var thumbinfo = (ThumbnailInfo)thumbbox.pictureBox[0].Tag;
 
-                Assert.Equal("http://foo.example.com/abcd", thumbinfo.ImageUrl);
-                Assert.Equal("http://img.example.com/abcd.png", thumbinfo.ThumbnailUrl);
+                Assert.Equal("http://foo.example.com/abcd", thumbinfo.MediaPageUrl);
+                Assert.Equal("http://img.example.com/abcd.png", thumbinfo.ThumbnailImageUrl);
 
                 Assert.Equal("", thumbbox.toolTip.GetToolTip(thumbbox.pictureBox[0]));
             }
@@ -239,14 +240,14 @@ namespace OpenTween
                 Assert.IsAssignableFrom<ThumbnailInfo>(thumbbox.pictureBox[0].Tag);
                 var thumbinfo = (ThumbnailInfo)thumbbox.pictureBox[0].Tag;
 
-                Assert.Equal("http://foo.example.com/abcd", thumbinfo.ImageUrl);
-                Assert.Equal("http://img.example.com/abcd.png", thumbinfo.ThumbnailUrl);
+                Assert.Equal("http://foo.example.com/abcd", thumbinfo.MediaPageUrl);
+                Assert.Equal("http://img.example.com/abcd.png", thumbinfo.ThumbnailImageUrl);
 
                 Assert.IsAssignableFrom<ThumbnailInfo>(thumbbox.pictureBox[1].Tag);
                 thumbinfo = (ThumbnailInfo)thumbbox.pictureBox[1].Tag;
 
-                Assert.Equal("http://bar.example.com/efgh", thumbinfo.ImageUrl);
-                Assert.Equal("http://img.example.com/efgh.png", thumbinfo.ThumbnailUrl);
+                Assert.Equal("http://bar.example.com/efgh", thumbinfo.MediaPageUrl);
+                Assert.Equal("http://img.example.com/efgh.png", thumbinfo.ThumbnailImageUrl);
 
                 Assert.Equal("", thumbbox.toolTip.GetToolTip(thumbbox.pictureBox[0]));
                 Assert.Equal("efgh", thumbbox.toolTip.GetToolTip(thumbbox.pictureBox[1]));
@@ -260,10 +261,6 @@ namespace OpenTween
             {
                 SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
 
-                bool eventCalled;
-                thumbbox.ThumbnailLoading +=
-                    (s, e) => { eventCalled = true; };
-
                 var post = new PostClass
                 {
                     TextFromApi = "てすと",
@@ -271,10 +268,11 @@ namespace OpenTween
                     {
                     },
                 };
-                eventCalled = false;
-                await thumbbox.ShowThumbnailAsync(post);
-
-                Assert.False(eventCalled);
+                await TestUtils.NotRaisesAsync<EventArgs>(
+                    x => thumbbox.ThumbnailLoading += x,
+                    x => thumbbox.ThumbnailLoading -= x,
+                    () => thumbbox.ShowThumbnailAsync(post)
+                );
 
                 SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
 
@@ -286,10 +284,12 @@ namespace OpenTween
                         new MediaInfo("http://foo.example.com/abcd"),
                     },
                 };
-                eventCalled = false;
-                await thumbbox.ShowThumbnailAsync(post2);
 
-                Assert.True(eventCalled);
+                await Assert.RaisesAsync<EventArgs>(
+                    x => thumbbox.ThumbnailLoading += x,
+                    x => thumbbox.ThumbnailLoading -= x,
+                    () => thumbbox.ShowThumbnailAsync(post2)
+                );
             }
         }