示例#1
0
        public void DownloadFileAsync_should_be_callable_indirectly()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var called    = false;
                var notCalled = true;
                var handler   = default(AsyncCompletedEventHandler);
                handler = (sender, e) => called = true;
                PULWebClient.AddDownloadFileCompletedAsyncCompletedEventHandler().Body    = (@this, value) => handler += value;
                PULWebClient.RemoveDownloadFileCompletedAsyncCompletedEventHandler().Body = (@this, value) => handler -= value;
                PULWebClient.DownloadFileAsyncUri().Body = (@this, address) =>
                {
                    var e = new AsyncCompletedEventArgs(null, false, null);
                    handler(@this, e);
                };


                // Act
                var client = new ULWebClient();
                client.DownloadFileAsync(new Uri("http://google.co.jp/"));
                client.DownloadFileCompleted += (sender, e) => notCalled = false;


                // Assert
                Assert.IsTrue(called);
                Assert.IsTrue(notCalled);
            }
        }
        public void ShowGoogle_should_write_response_from_google_to_standard_output()
        {
            // Prig has no attributes like HostType("Moles"). Use using (new IndirectionsContext()) instead of that.
            using (new IndirectionsContext())
            {
                // Arrange
                var handler = default(DownloadStringCompletedEventHandler);
                handler = (sender, e) => { };

                // AllInstances that is the feature of Moles to mock all instance members doesn't exist, because it is default feature.
                PWebClient.AddDownloadStringCompletedDownloadStringCompletedEventHandler().Body    = (@this, value) => handler += value;
                PWebClient.RemoveDownloadStringCompletedDownloadStringCompletedEventHandler().Body = (@this, value) => handler -= value;
                PWebClient.DownloadStringAsyncUri().Body = (@this, address) =>
                {
                    // Use the stub that starts with PProxy if you want to mock against one instance.
                    var e = new PProxyDownloadStringCompletedEventArgs();
                    e.ResultGet().Body = @this_ => "google!modoki";
                    handler(@this, e);
                };
                var mockWriteLine = new Mock <IndirectionAction <string> >();
                mockWriteLine.Setup(_ => _(It.IsAny <string>()));
                PConsole.WriteLineString().Body = mockWriteLine.Object;


                // Act
                ULWebClient.ShowGoogle();


                // Assert
                mockWriteLine.Verify(_ => _("google!modoki"), Times.Once());
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            //Console.WriteLine(LifeInfo.IsNowLunchBreak() ? "お昼休みなう!" : "お仕事なう・・・");
            var client = new ULWebClient();

            client.DownloadFileCompleted += client_DownloadFileCompleted;
            client.DownloadFileAsync(new Uri("http://google.co.jp/"));
            Console.ReadLine();
        }