示例#1
0
        public void exec_ServiceFunctionWithOneComplexParameter()
        {
            // Arrange
            TestCaseTesterController controller = new TestCaseTesterController();

            TestCaseTesterComplexP p = new TestCaseTesterComplexP();

            //p.MFieldbytearray50
            p.MFielddatetime = new DateTime(2013, 1, 1);
            p.MFielddecimal  = 1000000;
            p.MFielddouble   = Double.MaxValue;
            p.MFieldfloat    = float.MaxValue;
            p.MFieldint16    = Int16.MaxValue;
            p.MFieldint32    = Int32.MaxValue;
            p.MFieldint64    = Int64.MaxValue;
            p.MFieldntext    = "Some Text";
            p.MFieldstring   = "Some String";

            string jSonData = FWUtils.EntityUtils.JsonSerializeObject(p);

            FWPostBody body = new FWPostBody(jSonData);
            // Act
            ServiceActionResult res = controller.Exec("ServiceFunctionWithOneComplexParameter", body);

            // Assert
            Assert.AreEqual("OK!", res.data);
        }
示例#2
0
        public ServiceActionResult Exec(string methodName, [FromBody] FWPostBody p)
        {
            try
            {
                IServiceBase service = GetService();

                var method = service.GetType().GetMethod(methodName);
                if (method == null)
                {
                    throw new ServiceSecurityException();
                }
                else
                {
                    object result      = null;
                    var    mParameters = method.GetParameters();
                    Check.Assert(mParameters.Length <= 1, "Only services with one or less parameter is allowed");

                    if (mParameters.Length == 0)
                    {
                        result = method.Invoke(service, null);
                    }
                    else if (mParameters.Length == 1)
                    {
                        ParameterInfo param1 = null;
                        foreach (var item in mParameters)
                        {
                            param1 = item;
                        }
                        object parameterValue = FWUtils.EntityUtils.ConvertStringToObject(p.data, param1.ParameterType);

                        object[] methodParams = { parameterValue };
                        result = method.Invoke(service, methodParams);
                    }

                    if (result != null)
                    {
                        return(new ServiceActionResult(result));
                    }
                    else
                    {
                        return(ServiceActionResult.CreateSuccess(GetSuccessString(methodName)));
                    }
                }
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                return(UIUtils.GetExceptionActionResult(ex.InnerException));
            }
            catch (Exception ex)
            {
                return(UIUtils.GetExceptionActionResult(ex));
            }
        }
        public void exec()
        {
            // Arrange
            UserController controller = new UserController();

            FWPostBody body = new FWPostBody("testpatient");
            // Act
            ServiceActionResult res = controller.Exec("ValidateUserNameForInsert", body);

            // Assert
            Assert.IsNotNull(res.errorMessage);
        }
示例#4
0
        public void exec_ServiceFunctionWithOneParameterRetValue()
        {
            // Arrange
            TestCaseTesterController controller = new TestCaseTesterController();

            FWPostBody body = new FWPostBody("paramValue");
            // Act
            ServiceActionResult res = controller.Exec("ServiceFunctionWithOneParameterRetValue", body);

            // Assert
            Assert.AreEqual("OK! paramValue", res.data);
        }
示例#5
0
        // PUT api/entity_adk
        public virtual ServiceActionResult Insert([FromBody] FWPostBody p)
        {
            try
            {
                if (this.HasDefaultInsert == false)
                {
                    throw new ServiceSecurityException();
                }

                IServiceBase service = GetService();
                var          obj     = EntityFactory.GetEntityObject(service.EntityName, GetSourceTypeEnum.Table);
                FWUtils.EntityUtils.JsonDeserializeOnObject(p.data, obj, null, true);
                service.Insert(obj, new InsertParameters());
                return(ServiceActionResult.CreateSuccess(UIText.Base.EntityService.SuccessMsgs.General.Insert));
            }
            catch (Exception ex)
            {
                return(UIUtils.GetExceptionActionResult(ex));
            }
        }
示例#6
0
        // PUT api/entity_adk/5
        public virtual ServiceActionResult Update(string id, [FromBody] FWPostBody p)
        {
            try
            {
                if (this.HasDefaultUpdate == false)
                {
                    throw new ServiceSecurityException();
                }

                IServiceBase service = GetService();
                //object id = FWUtils.EntityUtils.GetObjectFieldValue(p.data)
                var obj = service.GetByID(id, new GetByIDParameters(GetSourceTypeEnum.Table));
                // TODO: Fix this function in a way that it reads default Update fields from the entity and updates only those fields
                FWUtils.EntityUtils.JsonDeserializeOnObject(p.data, obj, null, true);
                service.Update(obj, new UpdateParameters());
                return(ServiceActionResult.CreateSuccess(UIText.Base.EntityService.SuccessMsgs.General.Update));
            }
            catch (Exception ex)
            {
                return(UIUtils.GetExceptionActionResult(ex));
            }
        }