Inheritance: vlko.core.Base.BaseController
コード例 #1
0
        public void Delete_post_failed()
        {
            // Arrange
            var controller = new FileBrowserController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);
            builder.Form["Ident"] = "some_name";
            controller.MockUser("delete_ok");

            // Act
            // Act
            ActionResult createResult = controller.Upload(new HttpPostedFileMock("test.jpg", 40));
            // get first
            var createModel = createResult.AssertViewRendered().WithViewData<FileBrowserViewModel>();
            var item = createModel.UserFiles.First();
            item.Ident += "_not_exists";
            // delete first
            ActionResult result = controller.Delete(item);

            // Assert
            result.AssertViewRendered();

            Assert.IsFalse(controller.ModelState.IsValid);
        }
コード例 #2
0
        public void Delete()
        {
            // Arrange
            var controller = new FileBrowserController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);
            builder.Form["Ident"] = "some_name";
            controller.MockUser("delete");

            // Act
            ActionResult createResult = controller.Upload(new HttpPostedFileMock("test.jpg", 40));
            // get first
            var createModel = createResult.AssertViewRendered().WithViewData<FileBrowserViewModel>();
            // delete first
            ActionResult result = controller.Delete(createModel.UserFiles.First().Ident);

            // Assert
            var deleteModel = result.AssertViewRendered().WithViewData<FileViewModel>();

            Assert.IsNotNull(deleteModel);
            Assert.AreEqual("some_name.jpg", deleteModel.Ident);
            Assert.AreEqual(40, deleteModel.Size);
        }
コード例 #3
0
        public void Delete_post_ok()
        {
            // Arrange
            var controller = new FileBrowserController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);
            builder.Form["Ident"] = "some_name";
            controller.MockUser("delete_ok");

            // Act
            ActionResult createResult = controller.Upload(new HttpPostedFileMock("test.jpg", 40));
            // get first
            var createModel = createResult.AssertViewRendered().WithViewData<FileBrowserViewModel>();
            // delete first
            ActionResult result = controller.Delete(createModel.UserFiles.First());

            // Assert
            result.AssertActionRedirect().ToAction("Index");

            // test if user directory is empty
            ActionResult listResult = controller.Index();
            var model = listResult.AssertViewRendered().WithViewData<FileBrowserViewModel>();
            Assert.AreEqual(0, model.UserFiles.Count());
        }
コード例 #4
0
        public void Upload_with_dangerous_inputs()
        {
            // Arrange
            var controller = new FileBrowserController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);
            builder.Form["Ident"] = "..\\some_name";
            controller.MockUser("..\\upload_ok");

            // Act
            ActionResult result = controller.Upload(new HttpPostedFileMock("..\\test.\\jpg", 40));

            // Assert
            var model = result.AssertViewRendered().WithViewData<FileBrowserViewModel>();

            Assert.IsTrue(controller.ModelState.IsValid);

            Assert.IsNotNull(model.UserFiles);
            Assert.AreEqual(1, model.UserFiles.Count());

            FileViewModel savedFile = model.UserFiles.First();
            Assert.AreEqual("..-some_name", savedFile.Ident);
            Assert.AreEqual(40, savedFile.Size);
        }
コード例 #5
0
        public void Upload_ident_exists()
        {
            // Arrange
            var controller = new FileBrowserController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);
            builder.Form["Ident"] = "some_name";
            controller.MockUser("upload");

            // Act
            ActionResult previousResult = controller.Upload(new HttpPostedFileMock("test.jpg", 40));
            // upload second time the same
            ActionResult result = controller.Upload(new HttpPostedFileMock("test.jpg", 40));

            // Assert
            var model = result.AssertViewRendered().WithViewData<FileBrowserViewModel>();

            Assert.IsFalse(controller.ModelState.IsValid);

            Assert.IsNotNull(model.UserFiles);
            Assert.AreEqual(1, model.UserFiles.Count());
        }
コード例 #6
0
        public void Upload_file_too_big()
        {
            // Arrange
            var controller = new FileBrowserController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);
            builder.Form["Ident"] = "some_name";
            controller.MockUser("upload");

            // Act
            ActionResult result = controller.Upload(new HttpPostedFileMock("test.jpg", FileBrowserViewModel.MaxFileSize + 1));

            // Assert
            var model = result.AssertViewRendered().WithViewData<FileBrowserViewModel>();

            Assert.IsFalse(controller.ModelState.IsValid);

            Assert.IsNotNull(model.UserFiles);
            Assert.AreEqual(0, model.UserFiles.Count());
        }
コード例 #7
0
        public void Index_empty()
        {
            // Arrange
            var controller = new FileBrowserController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);
            controller.MockUser("empty");

            // Act
            ActionResult result = controller.Index();

            // Assert
            var model = result.AssertViewRendered().WithViewData<FileBrowserViewModel>();

            Assert.IsNotNull(model.UserFiles);
            Assert.AreEqual(0, model.UserFiles.Count());
        }