示例#1
0
        public void StringAsyncDownloadTest()
        {
            UTF8Encoding encoding = new UTF8Encoding();

            byte[]       contentAsBytes       = encoding.GetBytes(TestResources.CharacterSheet);
            MemoryStream sourceResponseStream = new MemoryStream();

            sourceResponseStream.Write(contentAsBytes, 0, contentAsBytes.Length);
            sourceResponseStream.Position = 0;
            Mock <HttpWebRequest>        mockRequest  = MockManager.Mock <HttpWebRequest>(Constructor.NotMocked);
            MockObject <HttpWebResponse> mockResponse = MockManager.MockObject <HttpWebResponse>(Constructor.Mocked);

            mockResponse.ExpectAndReturn("GetResponseStream", sourceResponseStream);
            mockRequest.ExpectAndReturn("GetResponse", mockResponse.Object);

            _stringAsyncCompletedTrigger = new AutoResetEvent(false);
            HttpWebService service = new HttpWebService();

            service.DownloadStringAsync("http://www.battleclinic.com", StringAysncDownloadTestCompleted, null);
            _stringAsyncCompletedTrigger.WaitOne();
            if (_stringAsyncDownloadResult.Error != null)
            {
                Assert.Fail(_stringAsyncDownloadResult.Error.Message);
            }
            Assert.AreEqual(TestResources.CharacterSheet, _stringAsyncDownloadResult.Result);
            sourceResponseStream.Close();
            _stringAsyncCompletedTrigger = null;
            _stringAsyncDownloadResult   = null;
        }
示例#2
0
        public void ImageAsyncDownloadTest()
        {
            MemoryStream sourceResponseStream = new MemoryStream();

            TestResources.testimage.Save(sourceResponseStream, ImageFormat.Png);
            sourceResponseStream.Position = 0;

            Mock <HttpWebRequest>        mockRequest  = MockManager.Mock <HttpWebRequest>(Constructor.NotMocked);
            MockObject <HttpWebResponse> mockResponse = MockManager.MockObject <HttpWebResponse>(Constructor.Mocked);

            mockResponse.ExpectAndReturn("GetResponseStream", sourceResponseStream);
            mockRequest.ExpectAndReturn("GetResponse", mockResponse.Object);

            _imageAsyncCompletedTrigger = new AutoResetEvent(false);
            HttpWebService service = new HttpWebService();

            service.DownloadImageAsync("http://www.battleclinic.com", ImageAysncDownloadTestCompleted, null);
            _imageAsyncCompletedTrigger.WaitOne();
            if (_imageAsyncDownloadResult.Error != null)
            {
                Assert.Fail(_imageAsyncDownloadResult.Error.Message);
            }
            Assert.IsNotNull(_imageAsyncDownloadResult.Result, "No image retrieved");
            _imageAsyncCompletedTrigger = null;
            _imageAsyncDownloadResult   = null;
        }
示例#3
0
        public void ImageDownloadExceptionTest()
        {
            UTF8Encoding encoding = new UTF8Encoding();

            byte[]       contentAsBytes       = encoding.GetBytes("This is not image data");
            MemoryStream sourceResponseStream = new MemoryStream();

            sourceResponseStream.Write(contentAsBytes, 0, contentAsBytes.Length);
            sourceResponseStream.Position = 0;

            Mock <HttpWebRequest>        mockRequest  = MockManager.Mock <HttpWebRequest>(Constructor.NotMocked);
            MockObject <HttpWebResponse> mockResponse = MockManager.MockObject <HttpWebResponse>(Constructor.Mocked);

            mockResponse.ExpectAndReturn("GetResponseStream", sourceResponseStream);
            mockRequest.ExpectAndReturn("GetResponse", mockResponse.Object);

            HttpWebService service = new HttpWebService();

            try
            {
                service.DownloadImage("http://www.battleclinic.com");
                Assert.Fail("Expected exception was not thrown");
            }
            catch (HttpWebServiceException ex)
            {
                Assert.AreEqual(HttpWebServiceExceptionStatus.ImageException, ex.Status);
            }
            finally
            {
                sourceResponseStream.Close();
            }
        }
示例#4
0
        public void XmlDownloadTest()
        {
            UTF8Encoding encoding = new UTF8Encoding();

            byte[]       contentAsBytes       = encoding.GetBytes(TestResources.CharacterSheet);
            MemoryStream sourceResponseStream = new MemoryStream();

            sourceResponseStream.Write(contentAsBytes, 0, contentAsBytes.Length);
            sourceResponseStream.Position = 0;
            XmlDocument contentAsXml = new XmlDocument();

            contentAsXml.Load(new StringReader(TestResources.CharacterSheet));

            Mock <HttpWebRequest>        mockRequest  = MockManager.Mock <HttpWebRequest>(Constructor.NotMocked);
            MockObject <HttpWebResponse> mockResponse = MockManager.MockObject <HttpWebResponse>(Constructor.Mocked);

            mockResponse.ExpectAndReturn("GetResponseStream", sourceResponseStream);
            mockRequest.ExpectAndReturn("GetResponse", mockResponse.Object);

            HttpWebService service = new HttpWebService();
            XmlDocument    result  = service.DownloadXml("http://www.battleclinic.com");

            StringAssert.AreEqualIgnoringCase(contentAsXml.ToString(), result.ToString());

            sourceResponseStream.Close();
        }
示例#5
0
        public void Transform()
        {
            SPSKeyValueList list = new SPSKeyValueList();

            list.Add("key0", "value0");
            list.Add("key1", "value1");
            list.Add("key2", "value2");

            Mock <Page>    mockPage    = MockManager.MockObject <Page>(Constructor.Mocked);
            Mock <Control> mockControl = MockManager.MockObject <Control>(Constructor.Mocked);

            mockControl.MockedInstance.ID = "TestID";

            Mock <SPSXsltControl> xsltMockControl = MockManager.MockObject <SPSXsltControl>(Constructor.Mocked);

            xsltMockControl.ExpectGet("Page", mockPage.MockedInstance);
            xsltMockControl.ExpectGet("Parent", mockControl.MockedInstance);

            SPSXsltControl xsltControl = xsltMockControl.MockedInstance;

            Assert.IsNotNull(xsltControl);
            xsltControl.XmlData = TestData.GetResource("TestData.xml");
            xsltControl.Xsl     = TestData.GetResource("Test.xslt");
            StringWriter transform = xsltControl.Transform();
            string       output    = transform.ToString();

            Debug.WriteLine(output);

            Assert.IsTrue(output.Contains("TEST"));
            Assert.IsTrue(output.Contains("1"));
            Assert.IsTrue(output.Contains("2"));

            MockManager.Verify();
        }
示例#6
0
 public void MockSample_TestMessageBox()
 {
     // create a mock instance of th System.Diagnostics.Process class
     //    var process = Isolate.Fake.Instance<Process>();
     TypeMock.MockObject mock = MockManager.MockObject(typeof(Process));
     mock.CallStatic.ExpectAndReturn("Start", mock.Object);
 }
        public SPSXsltExtension_Test()
        {
            SPSKeyValueList list = new SPSKeyValueList();

            list.Add("key0", "value0");
            list.Add("key1", "value1");
            list.Add("key2", "value2");

            Mock <Page>    mockPage    = MockManager.MockObject <Page>(Constructor.Mocked);
            Mock <Control> mockControl = MockManager.MockObject <Control>(Constructor.Mocked);

            mockControl.MockedInstance.ID = "TestID";

            _extension = new SPSXsltExtension(mockControl.MockedInstance, mockPage.MockedInstance, list);
            MockManager.Verify();
        }
示例#8
0
        public SPSXsltExtension_Test()
        {
            SPSKeyValueList list = new SPSKeyValueList();

            list.Add("key0", "value0");
            list.Add("key1", "value1");
            list.Add("key2", "value2");

            Mock <Page>           mockPage           = MockManager.MockObject <Page>(Constructor.Mocked);
            SPSXsltCommandControl xsltCommandControl = new SPSXsltCommandControl
            {
                ID = "TestID"
            };

            _extension = new SPSXsltExtension(xsltCommandControl, mockPage.MockedInstance, list);

            MockManager.Verify();
        }
示例#9
0
        public void ImageDownloadTest()
        {
            MemoryStream sourceResponseStream = new MemoryStream();

            TestResources.testimage.Save(sourceResponseStream, ImageFormat.Png);
            sourceResponseStream.Position = 0;

            Mock <HttpWebRequest>        mockRequest  = MockManager.Mock <HttpWebRequest>(Constructor.NotMocked);
            MockObject <HttpWebResponse> mockResponse = MockManager.MockObject <HttpWebResponse>(Constructor.Mocked);

            mockResponse.ExpectAndReturn("GetResponseStream", sourceResponseStream);
            mockRequest.ExpectAndReturn("GetResponse", mockResponse.Object);

            HttpWebService service = new HttpWebService();

            try
            {
                service.DownloadImage("http://www.battleclinic.com");
            }
            finally
            {
                sourceResponseStream.Close();
            }
        }
 public void FakeWebResponseGetResponse()
 {
     webResponseMock = MockManager.MockObject <WebResponse>();
     httpRequestMock.ExpectAndReturn("GetResponse", webResponseMock.Object);
 }