public void TestRepositryExecute_InternalOrder() { /* * <add key="EntityName" value="new_internalorder"/> * <add key="CrmPrimaryKey" value ="new_internalorderId"/> * <add key="CrmSecondPrimaryKey" value ="new_InternalOrderNumber"/> */ //insert internal order Random ran = new Random(); int accountcode = ran.Next(2000000); string inputJsonData = "{\"Action\":\"0\",\"new_internalorderId\":\"" + Guid.Empty.ToString() + "\",\"new_InternalOrderNumber\":\"" + accountcode.ToString() + "\",\"new_name\":\"kanchen\"}"; var obj = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(inputJsonData); var task = OnlineTest(obj); CRMResponse res = task; Assert.IsNotNull(res.RecordGuid); Assert.IsTrue(Convert.ToBoolean(res.LogStatusCode)); Guid guid = res.RecordGuid; //update without given guid inputJsonData = "{\"Action\":\"1\",\"new_internalorderId\":null,\"new_InternalOrderNumber\":\"" + accountcode.ToString() + "\",\"new_name\":\"kanchen1\"}"; obj = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(inputJsonData); task = OnlineTest(obj); res = task; Assert.IsTrue(Convert.ToBoolean(res.LogStatusCode)); Assert.IsNotNull(res.RecordGuid); Assert.AreEqual(res.RecordGuid, guid); //update with guid inputJsonData = "{\"Action\":\"1\",\"new_internalorderId\":\"" + guid.ToString() + "\",\"new_InternalOrderNumber\":\"" + accountcode.ToString() + "\",\"new_name\":\"kanchen2\"}"; obj = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(inputJsonData); task = OnlineTest(obj); res = task; Assert.IsTrue(Convert.ToBoolean(res.LogStatusCode)); }
public static CRMResponse SuccessResponse(JObject input) { CRMResponse response = new CRMResponse() { InputData = input.ToString(), RecordGuid = Guid.Parse(input.Value <string>(crmPrimaryKey)), LogStatusCode = Constants.CRMSucceed, MessageText = (int.Parse(input.Value <string>(Constants.PropertyName_Action)) == Constants.CRMCreate) ? "Created Successfully" : "Updated Successfully" }; return(response); }
public static CRMResponse FailedResponse(JObject input, Exception ex) { CRMResponse response = new CRMResponse() { InputData = input.ToString(), RecordGuid = Guid.Parse(input.Value <string>(crmPrimaryKey)), LogStatusCode = Constants.CRMFailed, MessageText = ex.Message + (ex.InnerException == null ? string.Empty : "InnerException: " + ex.InnerException.Message) }; return(response); }
public static CRMResponse InvalidResponse(JObject input) { CRMResponse response = new CRMResponse() { InputData = input.ToString(), RecordGuid = input.Property(crmPrimaryKey) != null?Guid.Parse(input.Value <string>(crmPrimaryKey)) : Guid.Empty, LogStatusCode = Constants.CRMFailed, MessageText = "input object error: " + input.ToString() }; return(response); }
public void TestAddAccount() { Random ran = new Random(); int employeeid = ran.Next(2000000); string inputJsonData = "{\"Action\":\"0\",\"ContactId\":\"" + Guid.Empty.ToString() + "\",\"EmployeeId\":\"" + employeeid.ToString() + "\",\"FirstName\":\"KanKan\",\"LastName\":\"Lewis\"}"; var obj = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(inputJsonData); var task = OnlineTest(obj); CRMResponse res = task; Assert.IsNotNull(res.RecordGuid); Assert.IsTrue(Convert.ToBoolean(res.LogStatusCode)); }
public static CRMResponse Query(string query) { CRMResponse response = new CRMResponse(); query = String.Format(@"Message-ID: 1 Message-Type: Request Time: '2016-10-04 13:42:12' Terminal-Type: 25 Content-Length: {0} {1} ", query.Length, query); TcpClient client = new TcpClient(); client.SendTimeout = 120000; client.ReceiveTimeout = 120000; client.ReceiveBufferSize = 5242880; client.Connect(ip, 9191); NetworkStream tcpStream = client.GetStream(); byte[] sendBytes = Encoding.GetEncoding(1251).GetBytes(query); tcpStream.Write(sendBytes, 0, sendBytes.Length); byte[] bytes = new byte[client.ReceiveBufferSize]; int bytesRead = tcpStream.Read(bytes, 0, client.ReceiveBufferSize); client.Close(); string returnData = Encoding.GetEncoding(1251).GetString(bytes).Replace("\0", ""); Match m = Regex.Match(returnData, "^Message-Type:(?<val>.*?)$", RegexOptions.Multiline | RegexOptions.IgnoreCase); if (m.Success) { response.MessageType = m.Groups["val"].ToString().Trim(); } m = Regex.Match(returnData, "Content-Length:.*?\r\n(?<val>.*)", RegexOptions.Singleline | RegexOptions.IgnoreCase); if (m.Success) { response.Message = m.Groups["val"].ToString().Trim(); } return response; }
public void TestOnpremRepositryExecute_Contact() { /* * <add key="EntityName" value="Contact"/> * <add key="CrmPrimaryKey" value ="ContactId"/> * <add key="CrmSecondPrimaryKey" value ="EmployeeId"/> */ //insert contact Random ran = new Random(); int employeeid = ran.Next(2000000); string inputJsonData = "{\"Action\":\"0\",\"ContactId\":\"" + Guid.Empty.ToString() + "\",\"EmployeeId\":\"" + employeeid.ToString() + "\",\"FirstName\":\"Kevin\",\"LastName\":\"Lewis\",\"MiddleName\":\"\",\"MobilePhone\":\"\",\"JobTitle\":\"\",\"EMailAddress1\":\"[email protected]\",\"Address1_City\":\"Santa Clara\",\"Address1_Country\":\"United States\",\"Address1_StateOrProvince\":\"CA\",\"Telephone1\":\"\",\"Address1_Line1\":\"2045 Lafayette Street\",\"Address1_Line3\":\"\",\"Address1_PostalCode\":\"95050\"}"; //string inputJsonData = "{\"ContactId\": \"\",\"EMailAddress1\": \"[email protected]\",\"EMailAddress2\": \"[email protected]\",\"EmployeeId\": \"1352109318\",\"FirstName\": \"kanchen\",\"LastName\": \"Leon-Dufour\",\"MiddleName\": \"\",\"new_CostCenter\": \"IE-WWL International Dublin\",\"new_CostCenterCode\": \"24069\",\"new_CostCenterNumber\": \"24069\",\"new_Domain\": \"EUROPE\",\"new_DomainAlias\": \"EUROPE\\\\v-tileon\",\"new_MSAlias\": \"v-tileon\",\"new_PositionNumber\": \"91250771\",\"new_ReportsToPositionNumber\": \"8143\",\"StateCode\": {\"Value\": 0},\"StatusCode\": {\"Value\": 1}}"; //string inputJsonData = "{\"FirstName\":\"KevinKK\"}"; var obj = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(inputJsonData); var task = OnpremTest(obj); CRMResponse res = task; Assert.IsNotNull(res.RecordGuid); Assert.IsTrue(Convert.ToBoolean(res.LogStatusCode)); Guid guid = res.RecordGuid; // update contact without given guid inputJsonData = "{\"Action\":\"1\",\"ContactId\":null,\"EmployeeId\":\"" + employeeid.ToString() + "\",\"FirstName\":\"KanChen0\",\"LastName\":\"Lewis\",\"MiddleName\":\"\",\"MobilePhone\":\"\",\"JobTitle\":\"\",\"EMailAddress1\":\"[email protected]\",\"Address1_City\":\"Santa Clara\",\"Address1_Country\":\"United States\",\"Address1_StateOrProvince\":\"CA\",\"Telephone1\":\"\",\"Address1_Line1\":\"2045 Lafayette Street\",\"Address1_Line3\":\"\",\"Address1_PostalCode\":\"95050\",\"StateCode\":{\"Value\":\"1\"},\"StatusCode\":{\"Value\":\"2\"}}"; obj = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(inputJsonData); task = OnpremTest(obj); res = task; Assert.IsNotNull(res.RecordGuid); Assert.IsTrue(Convert.ToBoolean(res.LogStatusCode)); Assert.AreEqual(res.RecordGuid, guid); // update contact inputJsonData = "{\"Action\":\"1\",\"ContactId\":\"" + res.RecordGuid.ToString() + "\",\"EmployeeId\":\"" + employeeid.ToString() + "\",\"FirstName\":\"KanChen1\",\"LastName\":\"Lewis\",\"MiddleName\":\"\",\"MobilePhone\":\"\",\"JobTitle\":\"\",\"EMailAddress1\":\"[email protected]\",\"Address1_City\":\"Santa Clara\",\"Address1_Country\":\"United States\",\"Address1_StateOrProvince\":\"CA\",\"Telephone1\":\"\",\"Address1_Line1\":\"2045 Lafayette Street\",\"Address1_Line3\":\"\",\"Address1_PostalCode\":\"95050\"}"; obj = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(inputJsonData); task = OnpremTest(obj); res = task; Assert.IsTrue(Convert.ToBoolean(res.LogStatusCode)); }