Ejemplo n.º 1
0
        public ActionResult UploadImportFile(HttpPostedFileBase uploadFile, UploadImportFileViewModel model)
        {
            WireJson result;

            if (ModelState.IsValid && uploadFile != null)
            {
                model.FileStream = uploadFile.InputStream;

                var response = GetCommand <UploadBlogsImportFileCommand>().ExecuteCommand(model);

                result = new WireJson(response != null, response);
            }
            else
            {
                result = new WireJson(false);
            }

            if (result.Success)
            {
                result.Messages = Messages.Success.ToArray();
            }
            else
            {
                result.Messages = Messages.Error.ToArray();
            }

            return(new WrappedJsonResult
            {
                Data = result
            });
        }
Ejemplo n.º 2
0
        public ActionResult UploadImportFile(HttpPostedFileBase uploadFile, UploadImportFileViewModel model)
        {
            WireJson result;
            if (ModelState.IsValid && uploadFile != null)
            {
                model.FileStream = uploadFile.InputStream;

                var response = GetCommand<UploadBlogsImportFileCommand>().ExecuteCommand(model);

                result = new WireJson(response != null, response);
            }
            else
            {
                result = new WireJson(false);
            }

            if (result.Success)
            {
                result.Messages = Messages.Success.ToArray();
            }
            else
            {
                result.Messages = Messages.Error.ToArray();
            }

            return new WrappedJsonResult
                {
                    Data = result
                };
        }
Ejemplo n.º 3
0
        public void Should_Save_EditSeoViewModel_And_Return_Success_Flag()
        {
            Mock <IRedirectService>   redirectService        = new Mock <IRedirectService>();
            Mock <IPageService>       pageService            = new Mock <IPageService>();
            Mock <ISitemapService>    sitemapService         = new Mock <ISitemapService>();
            Mock <ISecurityService>   securityService        = new Mock <ISecurityService>();
            Mock <IUrlService>        urlService             = new Mock <IUrlService>();
            Mock <SavePageSeoCommand> savePageSeoCommandMock = new Mock <SavePageSeoCommand>(redirectService.Object, pageService.Object, sitemapService.Object, urlService.Object);

            savePageSeoCommandMock.SetupGet(x => x.SecurityService).Returns(securityService.Object);
            savePageSeoCommandMock.Setup(f => f.Execute(It.IsAny <EditSeoViewModel>())).Returns(new EditSeoViewModel()).Verifiable();

            SeoController seoController = new SeoController();

            seoController.CommandResolver = GetMockedCommandResolver(mock =>
            {
                mock.Setup(resolver => resolver.ResolveCommand <SavePageSeoCommand>(It.IsAny <ICommandContext>())).Returns(() => savePageSeoCommandMock.Object);
            });

            ActionResult result = seoController.EditSeo(new EditSeoViewModel());

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <JsonResult>(result);

            JsonResult viewResult = (JsonResult)result;

            Assert.IsNotNull(viewResult.Data);

            Assert.IsInstanceOf <WireJson>(viewResult.Data);
            WireJson wireJson = (WireJson)viewResult.Data;

            Assert.IsTrue(wireJson.Success);

            savePageSeoCommandMock.Verify(f => f.Execute(It.IsAny <EditSeoViewModel>()), Times.Once());
        }
Ejemplo n.º 4
0
        public void Should_Initialize_Success()
        {
            var json = new WireJson(true);

            Assert.IsTrue(json.Success);
            Assert.AreEqual(json.DataType, "html");
            Assert.IsNull(json.Data);
            Assert.IsEmpty(json.Messages);
        }
Ejemplo n.º 5
0
        public void Should_Initialize_Empty_Constructor()
        {
            var json = new WireJson();

            Assert.IsFalse(json.Success);
            Assert.AreEqual(json.DataType, "html");
            Assert.IsNull(json.Data);
            Assert.IsNull(json.Messages);
        }
Ejemplo n.º 6
0
        public virtual JsonResult Json(WireJson data, JsonRequestBehavior behavior = JsonRequestBehavior.DenyGet)
        {
            List <string> messages = data.Messages != null
                                        ? data.Messages.ToList()
                                        : new List <string>();

            messages.AddRange(data.Success ? Messages.Success : Messages.Error);
            data.Messages = messages.ToArray();

            return(base.Json(data, behavior));
        }
Ejemplo n.º 7
0
        public void Should_Initialize_Success_And_Object()
        {
            dynamic data = new { Test = 1 };

            var json = new WireJson(true, data);

            Assert.IsTrue(json.Success);
            Assert.IsNull(json.DataType);
            Assert.AreEqual(json.Data, data);
            Assert.IsNull(json.Messages);
        }
Ejemplo n.º 8
0
        public void Should_Create_Failed_Json_And_Append_Messages()
        {
            using (var container = ContextScopeProvider.CreateChildContainer())
            {
                var controller = PrepareController(container);
                var messages   = new[] { "Message 1" };
                var json       = new WireJson {
                    Success = false, Messages = messages.ToArray()
                };
                var jsonResult = controller.Json(json);

                Assert.AreEqual(jsonResult.Data, json);
                AssertJson(messages, jsonResult);
            }
        }
Ejemplo n.º 9
0
        public void Should_Initialize_Success_And_Messages()
        {
            const string message1 = "Message1";
            const string message2 = "Message2";

            var json = new WireJson(true, new[] { message1, message2 });

            Assert.IsTrue(json.Success);
            Assert.AreEqual(json.DataType, "html");
            Assert.IsNull(json.Data);
            Assert.IsNotNull(json.Messages);
            Assert.AreEqual(json.Messages.Length, 2);
            Assert.IsTrue(json.Messages.Any(m => m == message1));
            Assert.IsTrue(json.Messages.Any(m => m == message2));
        }
Ejemplo n.º 10
0
        public void Should_Try_To_Save_EditSeoViewModel_And_Return_Error_Flag()
        {
            SeoController seoController = new SeoController();

            seoController.ModelState.AddModelError("PageTitle", "Page title required.");

            ActionResult result = seoController.EditSeo(new EditSeoViewModel());

            Assert.IsNotNull(result);
            Assert.IsInstanceOf <JsonResult>(result);

            JsonResult viewResult = (JsonResult)result;

            Assert.IsNotNull(viewResult.Data);

            Assert.IsInstanceOf <WireJson>(viewResult.Data);
            WireJson wireJson = (WireJson)viewResult.Data;

            Assert.IsFalse(wireJson.Success);
        }