public void PostTest()
        {
            var testFile      = @"D:\iCanFileData\upload\4JMQBV.gif";
            var fileStream    = new FileStream(testFile, FileMode.Open, FileAccess.Read);
            var streamContent = new StreamContent(fileStream);
            var fileTools     = new FileTools();

            streamContent.Headers.ContentType = new MediaTypeHeaderValue(fileTools.ConvertContentType(".gif"));

            var multiPartContent = new MultipartFormDataContent("boundary=---011000010111000001101001");

            multiPartContent.Add(streamContent, "TheFormDataKeyForYourFile", testFile);
            //測試資料
            var formData = new NameValueCollection
            {
                { "icantoken", "a0c4399e-c724-42d8-9d05-a0b2b0548783" },
                { "classid", "9999testcourse" },
                { "title", string.Format("[單元測試]-{0}", DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss")) },
                { "content", string.Format("[單元測試假單內容]-{0}", DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss")) },
                { "leavedate", DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss") },
                { "leavecategoryid", "1" }
            };

            foreach (string key in formData)
            {
                multiPartContent.Add(new StringContent(formData[key]), key);
            }
            target = new SetNewAbsenceFormController()
            {
                Request = new HttpRequestMessage()
                {
                    Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                    {
                        multiPartContent
                    },
                    Method = HttpMethod.Get
                },
                ControllerContext = new HttpControllerContext()
                {
                    Request = new HttpRequestMessage()
                    {
                        Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                        {
                            multiPartContent
                        },
                        Method = HttpMethod.Get
                    }
                }
            };
            var targetResponse = target.Post().Result;

            Assert.IsInstanceOfType(targetResponse, typeof(OkNegotiatedContentResult <BaseResponse <string> >));
            var targetResponseData = targetResponse as OkNegotiatedContentResult <BaseResponse <string> >;

            Assert.IsNotNull(targetResponseData.Content);
        }
        public void PutTest()
        {
            var testFile      = @"D:\iCanFileData\upload\4JMQBV.gif";
            var fileStream    = new FileStream(testFile, FileMode.Open, FileAccess.Read);
            var streamContent = new StreamContent(fileStream);
            var fileTools     = new FileTools();

            streamContent.Headers.ContentType = new MediaTypeHeaderValue(fileTools.ConvertContentType(".gif"));

            var multiPartContent = new MultipartFormDataContent("boundary=---011000010111000001101001");

            multiPartContent.Add(streamContent, "TheFormDataKeyForYourFile", testFile);
            //測試資料
            var formData = new NameValueCollection
            {
                { "icantoken", "4a01b7ed-27d7-4312-9a63-71c53a70dc81" },
                { "classid", "9999testcourse" },
                { "title", string.Format("[修改單元測試] {0} ", DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss")) },
                { "content", "修改單元測試內容" },
                { "activityOuterKey", "135EF2B9-7D44-4C43-8EA4-F59C28C74F39" }
            };

            foreach (string key in formData)
            {
                multiPartContent.Add(new StringContent(formData[key]), key);
            }
            var controller = new DiscussionController()
            {
                Request = new HttpRequestMessage()
                {
                    Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                    {
                        multiPartContent
                    },
                    Method = HttpMethod.Put
                },
                ControllerContext = new HttpControllerContext()
                {
                    Request = new HttpRequestMessage()
                    {
                        Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                        {
                            multiPartContent
                        },
                        Method = HttpMethod.Put
                    }
                }
            };

            var targetResponse = controller.Put().Result; //List<Infrastructure.Entity.FileStorage>

            Assert.IsInstanceOfType(targetResponse, typeof(OkNegotiatedContentResult <BaseResponse <string> >));
            var targetResponseData = targetResponse as OkNegotiatedContentResult <BaseResponse <string> >;

            Assert.IsNotNull(targetResponseData.Content);
        }
Example #3
0
        public void PostTest()
        {
            var testFile      = @"D:\iCanFileData\upload\4JMQBV.gif";
            var fileStream    = new FileStream(testFile, FileMode.Open, FileAccess.Read);
            var streamContent = new StreamContent(fileStream);
            var fileTools     = new FileTools();

            streamContent.Headers.ContentType = new MediaTypeHeaderValue(fileTools.ConvertContentType(".gif"));

            var multiPartContent = new MultipartFormDataContent("boundary=---011000010111000001101001");

            multiPartContent.Add(streamContent, "TheFormDataKeyForYourFile", testFile);
            //測試資料
            var formData = new NameValueCollection
            {
                { "icantoken", "4a01b7ed-27d7-4312-9a63-71c53a70dc81" },
                { "classid", "9999testcourse" },
                { "activityOuterKey", "A6D3B148-5CF7-427B-99DE-4674048EB0E9" },
                { "msg", string.Format("[{0}] 單元測試留言", DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss")) }
            };

            foreach (string key in formData)
            {
                multiPartContent.Add(new StringContent(formData[key]), key);
            }
            target = new AddDiscussionMessageController()
            {
                Request = new HttpRequestMessage()
                {
                    Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                    {
                        multiPartContent
                    },
                    Method = HttpMethod.Post
                },
                ControllerContext = new HttpControllerContext()
                {
                    Request = new HttpRequestMessage()
                    {
                        Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                        {
                            multiPartContent
                        },
                        Method = HttpMethod.Post
                    }
                }
            };
            var targetResponse = target.Post().Result;

            Assert.IsInstanceOfType(targetResponse, postResponse);
            var targetResData = targetResponse as OkNegotiatedContentResult <ResultBaseModel <DiscussionSendMsg> >;

            Assert.IsNotNull(targetResData.Content);
            Assert.IsTrue(targetResData.Content.Success);
        }
Example #4
0
        public void POSTTest()
        {
            var testFile      = @"D:\iCanFileData\upload\4JMQBV.gif";
            var fileStream    = new FileStream(testFile, FileMode.Open, FileAccess.Read);
            var streamContent = new StreamContent(fileStream);
            var fileTools     = new FileTools();

            streamContent.Headers.ContentType = new MediaTypeHeaderValue(fileTools.ConvertContentType(".gif"));

            var multiPartContent = new MultipartFormDataContent("boundary=---011000010111000001101001");

            multiPartContent.Add(streamContent, "TheFormDataKeyForYourFile", testFile);
            //測試資料
            var formData = new NameValueCollection
            {
                { "icantoken", "4a01b7ed-27d7-4312-9a63-71c53a70dc81" },
                { "classid", "9999testcourse" },
                { "clientkey", "testclientKey" }
            };

            foreach (string key in formData)
            {
                multiPartContent.Add(new StringContent(formData[key]), key);
            }
            target = new MaterialUploadFIleController()
            {
                Request = new HttpRequestMessage()
                {
                    Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                    {
                        multiPartContent
                    },
                    Method = HttpMethod.Post
                },
                ControllerContext = new HttpControllerContext()
                {
                    Request = new HttpRequestMessage()
                    {
                        Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                        {
                            multiPartContent
                        },
                        Method = HttpMethod.Post
                    }
                }
            };
            var targetResponse = target.POST().Result;

            Assert.IsInstanceOfType(targetResponse, typeof(OkNegotiatedContentResult <BaseResponse <string> >));
            var targetResponseData = targetResponse as OkNegotiatedContentResult <BaseResponse <string> >;

            Assert.IsNotNull(targetResponseData.Content);
        }
Example #5
0
        public void PostTest()
        {
            var testFile      = @"D:\iCanFileData\upload\1.txt";
            var fileStream    = new FileStream(testFile, FileMode.Open, FileAccess.Read);
            var streamContent = new StreamContent(fileStream);
            var fileTools     = new FileTools();

            streamContent.Headers.ContentType = new MediaTypeHeaderValue(fileTools.ConvertContentType(".txt"));
            var multiPartContent = new MultipartFormDataContent("boundary=---011000010111000001101001");

            multiPartContent.Add(streamContent, "TheFormDataKeyForYourFile", testFile);
            var controller = new FileController()
            {
                Request = new HttpRequestMessage()
                {
                    Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                    {
                        multiPartContent
                    },
                    Method = HttpMethod.Post
                },
                ControllerContext = new HttpControllerContext()
                {
                    Request = new HttpRequestMessage()
                    {
                        Content = new MultipartFormDataContent("boundary=---011000010111000001101001")
                        {
                            multiPartContent
                        },
                        Method = HttpMethod.Post
                    }
                }
            };
            var targetResponse = controller.Post(token).Result; //List<Infrastructure.Entity.FileStorage>

            Assert.IsInstanceOfType(targetResponse, typeof(OkNegotiatedContentResult <bool>));
            var targetResponseData = targetResponse as OkNegotiatedContentResult <bool>;

            Assert.IsNotNull(targetResponseData.Content);
        }