public void GivenAFile_WhenItHasAnExtension_ThenTheExtensionIsRetrieved()
        {
            var model = new NewMediaViewModel();
            string extension = model.GetExtension("some.file.name.txt");

            Assert.That(extension, Is.EqualTo("txt"));
        }
示例#2
0
        public virtual JsonResult Create(NewMediaViewModel model)
        {
            var result = new MediaCreateJsonResponse { success = false };
            try
            {
                var user = (UserViewModel)HttpContext.User;
                int contentLength;
                Stream inputStream;
                string fileName;
                if (model.File != null)
                {
                    contentLength = model.File.ContentLength;
                    inputStream = model.File.InputStream;
                    fileName = model.File.FileName;
                }
                else
                {
                    contentLength = HttpContext.Request.ContentLength;
                    inputStream = HttpContext.Request.InputStream;
                    fileName = model.QqFile;
                }

                if (contentLength != 0)
                {
                    var media = new Media();
                    var success = true;
                    var message = "Media uploaded successfully";
                    try
                    {
                        media = _mediaService.WriteMedia(fileName, user.Id, model.ContentType, inputStream, contentLength);
                    }
                    catch (MBlogInsertItemException e)
                    {
                        success = false;
                        message = e.Message;
                    }
                    string anchor = string.Format("<a href='{0}'><img src='{0}'/></a>",
                        Url.Action("show", "media", new { year = media.Year, month = media.Month, day = media.Day, linkKey = media.LinkKey }));
                    result = new MediaCreateJsonResponse { success = success, url = media.Url, message = message, title = media.Title, action = Url.Action("update", "media", new { id = media.Id }), imageAnchor = anchor };
                }
            }
            catch (Exception e)
            {
                result.exception = e;
                result.message = e.Message;
            }
            return Json(result);
        }
示例#3
0
 public virtual ActionResult New(NewMediaViewModel model)
 {
     return View(new NewMediaViewModel { Nickname = model.Nickname, File = model.File });
 }
示例#4
0
 public virtual ActionResult New(string nickname)
 {
     NewMediaViewModel model = new NewMediaViewModel { Nickname = nickname };
     return View(new EditPostViewModel { IsCreate = true, Nickname = nickname, NewMediaViewModel = model });
 }
 public void GivenAValidQqFileExtension_ThenTheModelIsValid()
 {
     var model = new NewMediaViewModel {QqFile = "name.jpg"};
     Assert.That(model.Validate(null).Count(), Is.EqualTo(0));
 }
 public void GivenAValidFileExtension_ThenTheModelIsValid()
 {
     var model = new NewMediaViewModel {File = new TestHttpPostedFileBase("foo.jpg")};
     Assert.That(model.Validate(null).Count(), Is.EqualTo(0));
 }
 public void GivenAValidFIleExtension_ThenIsAllowedIsTrue()
 {
     var model = new NewMediaViewModel();
     Assert.IsTrue(model.IsAllowed("jpg"));
 }
 public void GivenAQQFile_ThenTheCorrectMimeTypeIsReturned()
 {
     var model = new NewMediaViewModel {QqFile = "name.jpg"};
     Assert.That(model.ContentType, Is.EqualTo("image/jpeg"));
 }
 public void GivenAInvalidFIleExtension_ThenIsAllowedIsFalse()
 {
     var model = new NewMediaViewModel();
     Assert.IsFalse(model.IsAllowed("txt"));
 }