예제 #1
0
        public void TestModelToMongo()
        {
            var models = new XPathDemo[]
            {
                new XPathDemo
                {
                    Id       = "Random123",
                    Revision = 1,
                    Engine   = XPathEngine.xpath3,
                    Xml      = "<root/>",
                    XPath    = "/*/self::*",
                    Result   = new XPathResult {
                        Data = "<root/>"
                    }
                },
                new XPathDemo()
            };
            var isAllMatch = models.Select(model =>
            {
                var mongoModel = new XPathDemoMongo();
                mongoModel.LoadFromModel(model);

                var isMatch = (
                    mongoModel.Id == model.Id &&
                    mongoModel.Revision == model.Revision &&
                    (XPathEngine)Enum.ToObject(typeof(XPathEngine), mongoModel.Engine) == model.Engine &&
                    mongoModel.Xml == model.Xml &&
                    mongoModel.XPath == model.XPath &&
                    mongoModel.Result == model.Result.Data
                    );
                return(isMatch);
            }).All(o => o);

            Assert.IsTrue(isAllMatch);
        }
예제 #2
0
        public static string GetRedirectUrl(XPathDemoMongo model, RequestContext context)
        {
            UrlHelper urlHelper = new UrlHelper(context);

            if (model.Revision > 0)
            {
                return(urlHelper.Action("Index", "XPath", new { id = model.Id, rev = model.Revision }));
            }
            else
            {
                return(urlHelper.Action("Index", "XPath", new { id = model.Id }));
            }
        }
예제 #3
0
        public JsonResult SaveDemo(XPathDemo demo)
        {
            string         error     = "";
            XPathDemoMongo data      = new XPathDemoMongo();
            var            isSuccess = true;

            try
            {
                var mongoModel = new XPathDemoMongo();
                mongoModel.LoadFromModel(demo);
                data = DataRepository.CreateDemo(mongoModel);
            }
            catch (Exception e)
            {
                isSuccess = false;
                error     = e.Message;
                return(Json(new { isSuccess = isSuccess, error, data = data.Id }));
            }
            return(Json(new { isSuccess = isSuccess, error, data = UrlUtils.GetRedirectUrl(data, Request.RequestContext) }));
        }