public void Test3() { try { RegisterClientAddressTransaction anUnknowClient = new RegisterClientAddressTransaction( "http://unknown/", "unknownId", theClientProxyMocks, theDal); anUnknowClient.Excute(); Assert.Fail("期望失败"); } catch (ApplicationException) { } ClientInformationModel theClientInformationModel = theDal.GetAllClientInfomationModel()[0]; ListenAddressModel theListenAddressModel = theClientInformationModel.TheAddressModelCollcetion[0]; Assert.IsFalse(theListenAddressModel.IsPermitted); //打开信道 new ActiveTheListenAddressProxy(theClientInformationModel.Pkid, theListenAddressModel.Pkid, theClientProxyMocks, theDal).Excute(); Assert.IsTrue(theListenAddressModel.IsPermitted); Assert.AreEqual(1, MockSingleSmsClientContract._TheServiceStatusChanged.Count); Assert.AreEqual("http://unknown/", MockSingleSmsClientContract._TheServiceStatusChanged[0]); //关闭信道 new DisableTheListenAddressProxy(theClientInformationModel.Pkid, theListenAddressModel.Pkid, theClientProxyMocks, theDal).Excute(); Assert.IsFalse(theListenAddressModel.IsPermitted); Assert.AreEqual(2, MockSingleSmsClientContract._TheServiceStatusChanged.Count); Assert.AreEqual("http://unknown/", MockSingleSmsClientContract._TheServiceStatusChanged[1]); }
public void UpdateClientInfomationModel(ClientInformationModel theClientInfomationModel) { InitializeTranscation(); try { SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add(_PKID, SqlDbType.Int).Value = theClientInfomationModel.Pkid; TheNeedParametersForClientInformationModel(cmd, theClientInfomationModel); SqlHelper.TransExecuteNonQuery("ClientInformationUpdate", cmd, _Conn, _Trans); DeleteListenAddressModelByClientInformationId(theClientInfomationModel.Pkid); InsertToAddressTable(theClientInfomationModel.Pkid, theClientInfomationModel); _Trans.Commit(); } catch { _Trans.Rollback(); throw new ApplicationException(_DbError); } finally { _Conn.Close(); } }
public void InsertClientInfomationModel(ClientInformationModel aClientAddressModel) { InitializeTranscation(); try { SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add(_PKID, SqlDbType.Int).Direction = ParameterDirection.Output; TheNeedParametersForClientInformationModel(cmd, aClientAddressModel); int pkid; SqlHelper.TransExecuteNonQueryReturnPKID("ClientInformationInsert", cmd, _Conn, _Trans, out pkid); aClientAddressModel.Pkid = pkid; InsertToAddressTable(pkid, aClientAddressModel); _Trans.Commit(); } catch { _Trans.Rollback(); throw new ApplicationException(_DbError); } finally { _Conn.Close(); } }
private void InsertToAddressTable(int clientInformationId, ClientInformationModel theObj) { foreach (ListenAddressModel lam in theObj.TheAddressModelCollcetion) { InsertListenAddressModel(clientInformationId, lam); } }
public void Excute() { ClientInformationModel theClientAddress = CheckTheClientAddress(_HrmisId); bool theClientAddressIsGood = VerifyTheClientAddress(_Address); //有该Hrmisid相关的对象 if (theClientAddress != null) { //更新对象信息,由于所有信息都全了,在返回给客户端信息之前作保存 theClientAddress.TryAddDiffierentListenAddress(_Address, theClientAddressIsGood); new ClientInformationDbRestrictLayer(_TheAddressDal).UpdateTheObject(theClientAddress); if (theClientAddress.IsMePermitted(_Address)) { if (theClientAddressIsGood) { return; } else { throw new ApplicationException("服务器调用客户端监听端口失败"); } } else { throw new ApplicationException("当前客户端HrmisId未被允许"); } } //无该Hrmisid相关的对象 else { new ClientInformationDbRestrictLayer(_TheAddressDal).AddAnObject(ClientInformationModel.CreateGuestAddress(_Address, _HrmisId, theClientAddressIsGood)); throw new ApplicationException("当前客户端HrmisId未被允许"); } }
public void Test1() { //持久一个新的对象 ClientInformationModel aNewObject = new ClientInformationModel("hrmisId", "companyDescription", true); aNewObject.TheAddressModelCollcetion.Add(new ListenAddressModel("listenAddress", true, true, DateTime.Today)); _TheTarget.InsertClientInfomationModel(aNewObject); _TheNewPkid = aNewObject.Pkid; //重新装载该对象,使用GetAll方式 List <ClientInformationModel> rechieveObjects = _TheTarget.GetAllClientInfomationModel(); Assert.AreEqual(1, rechieveObjects.Count); Assert.IsTrue(aNewObject.Equals(rechieveObjects[0])); //重新装载对象,使用GetById方式 ClientInformationModel rechieveObjectById = _TheTarget.GetClientInformationById(_TheNewPkid); Assert.IsTrue(aNewObject.Equals(rechieveObjectById)); //修改对象 ClientInformationModel theRechieveObject = rechieveObjects[0]; theRechieveObject.HrmisId = "hrmisId1"; theRechieveObject.CompanyDescription = "capcom"; theRechieveObject.IsPermitted = false; theRechieveObject.TheAddressModelCollcetion[0].IsActivited = false; theRechieveObject.TheAddressModelCollcetion[0].IsPermitted = false; theRechieveObject.TheAddressModelCollcetion[0].LastTryActivitedTime = new DateTime(1999, 1, 1); theRechieveObject.TheAddressModelCollcetion[0].ListenAddress = "http://localhost"; theRechieveObject.TheAddressModelCollcetion.Add(new ListenAddressModel("123123", false, true, new DateTime(1998, 1, 1))); _TheTarget.UpdateClientInfomationModel(theRechieveObject); //再次加载对象 List <ClientInformationModel> secondRechieveObjectsSecond = _TheTarget.GetAllClientInfomationModel(); Assert.AreEqual(1, secondRechieveObjectsSecond.Count); Assert.IsTrue(theRechieveObject.Equals(secondRechieveObjectsSecond[0])); }
public void Test1() { //注册一个新的客户端 try { theDataServices.RegisterSmsClient("http://localhost:8000/SmsClientService/", "aNewHrmisId"); Assert.Fail("期望失败"); } catch (FaultException fe) { Assert.AreEqual("当前客户端HrmisId未被允许", fe.Message); } Assert.AreEqual(1, theController.GetAllClientAddressModel().Count); ClientInformationModel theClientInfo = theController.GetAllClientAddressModel()[0]; AssertTheClientInformationDisabled(theClientInfo); Assert.AreEqual(1, MockClientServicesProvider._ClientIsAvailableCalled); //允许该客户端 theController.ActiveTheClientInformation(theClientInfo.Pkid); Thread.Sleep(50);//此处Sleep的原因是,客户端被回调声明为OneWay,服务器没有等待结果 ClientInformationModel theClientInfo1 = theController.GetAllClientAddressModel()[0]; AssertTheClientInformationActived(theClientInfo1); Assert.AreEqual(1, MockClientServicesProvider._TheServiceStatusChanged); //todo by nh 加入更多的测试 12.7 }
public void Test4() { new AddActivedClientInformation("permittedClient", "已知的公司", theDal).Excute(); //客户信息对象 List <ClientInformationModel> allClients = theDal.GetAllClientInfomationModel(); Assert.AreEqual(1, allClients.Count); ClientInformationModel theObj = allClients[0]; Assert.AreEqual("已知的公司", theObj.CompanyDescription); Assert.AreEqual("permittedClient", theObj.HrmisId); Assert.AreEqual(true, theObj.IsPermitted); //地址对象 Assert.AreEqual(0, theObj.TheAddressModelCollcetion.Count); //模拟客户端发起调用 new RegisterClientAddressTransaction("http://knownaddress", "permittedClient", theClientProxyMocks, theDal).Excute(); Assert.AreEqual(1, theObj.TheAddressModelCollcetion.Count); ListenAddressModel lam = theObj.TheAddressModelCollcetion[0]; Assert.IsTrue(lam.IsActivited); Assert.IsTrue(lam.IsPermitted); Assert.IsTrue(lam.IsPermitted); Assert.AreEqual("http://knownaddress", lam.ListenAddress); Console.WriteLine(lam.LastTryActivitedTime); }
public ClientInformationModel GetClientData(int clientId) { ClientInformationModel ClientInfo = new ClientInformationModel(); try { var database = SingletonDb.Instance.GetDBConnection(); object[] parameterValues = new object[] { clientId }; DbCommand cmd = database.GetStoredProcCommand("dbo.Client_sp_SelectByClientId", parameterValues); using (IDataReader reader = database.ExecuteReader(cmd)) { while (reader.Read()) { ClientInfo.ClientId = reader.GetInt32(0); ClientInfo.FirstName = !reader.IsDBNull(reader.GetOrdinal("vc_FirstName")) ? reader.GetString(1) : string.Empty; ClientInfo.MiddleName = !reader.IsDBNull(reader.GetOrdinal("vc_MiddleName")) ? reader.GetString(2) : string.Empty; ClientInfo.LastName = !reader.IsDBNull(reader.GetOrdinal("vc_LastName")) ? reader.GetString(3) : string.Empty; ClientInfo.PhoneNumber = !reader.IsDBNull(reader.GetOrdinal("in_PhoneNo")) ? reader.GetString(4) : string.Empty; ClientInfo.Address = !reader.IsDBNull(reader.GetOrdinal("vc_ClientAddress")) ? reader.GetString(5) : string.Empty; ClientInfo.City = !reader.IsDBNull(reader.GetOrdinal("vc_ClientCity")) ? reader.GetString(6) : string.Empty; ClientInfo.State = !reader.IsDBNull(reader.GetOrdinal("vc_ClientState")) ? reader.GetString(7) : string.Empty; ClientInfo.Country = !reader.IsDBNull(reader.GetOrdinal("vc_ClientCountry")) ? reader.GetString(8) : string.Empty; ClientInfo.PinCode = !reader.IsDBNull(reader.GetOrdinal("in_ClientPINcode")) ? reader.GetString(9) : string.Empty; ClientInfo.LastUpdated = !reader.IsDBNull(reader.GetOrdinal("dt_lastUpdateDate")) ? reader.GetDateTime(10) : DateTime.Now; } } } catch (Exception ex) { } return(ClientInfo); }
public void Test1() { try { new RegisterClientAddressTransaction("http://unknown/", "unknownId", theClientProxyMocks, theDal).Excute(); Assert.Fail("期望失败"); } catch (ApplicationException ae) { Assert.AreEqual("当前客户端HrmisId未被允许", ae.Message); } //客户信息对象 List <ClientInformationModel> allClients = theDal.GetAllClientInfomationModel(); Assert.AreEqual(1, allClients.Count); ClientInformationModel theObj = allClients[0]; Assert.AreEqual("未定义的公司", theObj.CompanyDescription); Assert.AreEqual("unknownId", theObj.HrmisId); Assert.IsFalse(theObj.IsPermitted); //地址对象 Assert.AreEqual(1, theObj.TheAddressModelCollcetion.Count); ListenAddressModel lam = theObj.TheAddressModelCollcetion[0]; Assert.IsTrue(lam.IsActivited); Assert.IsFalse(lam.IsPermitted); Assert.AreEqual("http://unknown/", lam.ListenAddress); Console.WriteLine(lam.LastTryActivitedTime); }
public void UpdateClientInfomationModel(ClientInformationModel theClientAddress) { _ClientInformation[theClientAddress.Pkid] = theClientAddress; foreach (ListenAddressModel lam in theClientAddress.TheAddressModelCollcetion) { lam.Pkid = _AddressPkid++; } }
public void InsertClientInfomationModel(ClientInformationModel aClientAddressModel) { aClientAddressModel.Pkid = _Pkid; foreach (ListenAddressModel lam in aClientAddressModel.TheAddressModelCollcetion) { lam.Pkid = _AddressPkid++; } _ClientInformation.Add(_Pkid++, aClientAddressModel); }
private void AssertTheClientInformationActived(ClientInformationModel theClientInfo1) { Assert.AreEqual("aNewHrmisId", theClientInfo1.HrmisId); Assert.IsTrue(theClientInfo1.IsPermitted); Assert.AreEqual(1, theClientInfo1.TheAddressModelCollcetion.Count); Assert.IsTrue(theClientInfo1.TheAddressModelCollcetion[0].IsActivited); Assert.IsTrue(theClientInfo1.TheAddressModelCollcetion[0].IsPermitted); Assert.AreEqual("http://localhost:8000/SmsClientService/", theClientInfo1.TheAddressModelCollcetion[0].ListenAddress); }
public void EditClientDetails(ClientInformationModel clientData) { var database = SingletonDb.Instance.GetDBConnection(); object[] parameter = new object[] { clientData.ClientId, clientData.FirstName, clientData.MiddleName, clientData.LastName, clientData.PhoneNumber, clientData.Address, clientData.City, clientData.State, clientData.Country, clientData.PinCode }; DbCommand cmd = database.GetStoredProcCommand("dbo.Client_sp_Update", parameter); database.ExecuteNonQuery(cmd); }
private void AssertTheClientInformationDisabled(ClientInformationModel theClientInfo) { Assert.AreEqual("aNewHrmisId", theClientInfo.HrmisId); Assert.IsFalse(theClientInfo.IsPermitted); Assert.AreEqual(1, theClientInfo.TheAddressModelCollcetion.Count); Assert.IsTrue(theClientInfo.TheAddressModelCollcetion[0].IsActivited); Assert.IsFalse(theClientInfo.TheAddressModelCollcetion[0].IsPermitted); Assert.AreEqual("http://localhost:8000/SmsClientService/", theClientInfo.TheAddressModelCollcetion[0].ListenAddress); Console.WriteLine(theClientInfo.TheAddressModelCollcetion[0].LastTryActivitedTime); }
protected override void ChangeTheObject(ClientInformationModel theModelTobeUpdated) { ListenAddressModel theAddressModel = theModelTobeUpdated.GetTheAddressModelById(_TheListenAddressId); if (theAddressModel == null) { throw new ApplicationException("无法找到该Id标记的地址信息"); } theAddressModel.IsPermitted = SetTheListenAddressStatus(); }
public void Excute() { ClientInformationModel _TheModelToBeUpdated = _TheDal.GetClientInformationById(_ClientInfomationId); if (_TheModelToBeUpdated == null) { throw new ApplicationException("无法找到该Id标记的客户信息"); } ChangeTheObject(_TheModelToBeUpdated); new ClientInformationDbRestrictLayer(_TheDal).UpdateTheObject(_TheModelToBeUpdated); }
public ActionResult Calculate() { ClientInformationModel model = new ClientInformationModel(); if (Request.Cookies[_clientInfoCookie] != null) { model = ClientInformationModel.FromCookie(Request.Cookies[_clientInfoCookie]); } return(View(model)); }
private void DataBindClientInformationForDescript(int theClientInformationId) { ClientInformationModel theClientInfo = _TheSmsControllor.GetClientAddressModelById(theClientInformationId); txtClientId.Text = theClientInformationId.ToString(); txtClientId.Enabled = false; txtHrmisIdForUpdate.Text = theClientInfo.HrmisId; txtHrmisIdForUpdate.Enabled = false; txtCompanyDescriptionForUpdate.Text = theClientInfo.CompanyDescription; txtCompanyDescriptionForUpdate.Enabled = true; }
public void AddAnObject(ClientInformationModel aNewObject) { List <ClientInformationModel> hrmisIdRepresentObj = new ClientInformationModelCollection(_TheDal.GetAllClientInfomationModel()).GetClientAddressByHrmisId(aNewObject.HrmisId); if (hrmisIdRepresentObj.Count > 0) { throw new ApplicationException("待新增的对象的HrmisId与系统中已有的重复"); } _TheDal.InsertClientInfomationModel(aNewObject); }
public void Test5() { new AddActivedClientInformation("permittedClient", "已知的公司", theDal).Excute(); List <ClientInformationModel> allClients = theDal.GetAllClientInfomationModel(); ClientInformationModel theObj = allClients[0]; Assert.AreEqual("已知的公司", theObj.CompanyDescription); new DescriptClientInformation(theObj.Pkid, "修改过的公司", theDal).Excute(); Assert.AreEqual("修改过的公司", theObj.CompanyDescription); }
private void AfterChangeTheObject(ClientInformationModel theModelTobeUpdated) { try { foreach (string address in theModelTobeUpdated.GetActivedAddress()) { _TheClientProxy.TheServiceStatusChanged(true, address); } } catch (FaultException) { throw new ApplicationException("业务已经完成,但是通知客户端服务已经改变未能成功,可能是客户端已经关闭"); } }
public void AddClientData(ClientInformationModel clientData) { try { var database = SingletonDb.Instance.GetDBConnection(); object[] parameterValues = new object[] { 2, clientData.FirstName, clientData.MiddleName, clientData.LastName, clientData.PhoneNumber, clientData.PhoneNumber, clientData.Address, clientData.City, clientData.Country, clientData.PinCode }; DbCommand cmd = database.GetStoredProcCommand("dbo.client_sp_details", parameterValues); database.ExecuteNonQuery(cmd); } catch (Exception ex) { } }
public void Test6() { //增加一个允许的客户端,其中包括一个不被允许的地址,一个被允许的地址, new AddActivedClientInformation("permittedClient", "已知的公司", theDal).Excute(); new RegisterClientAddressTransaction("http://permittedAddress", "permittedClient", theClientProxyMocks, theDal).Excute(); new RegisterClientAddressTransaction("http://disableAddress", "permittedClient", theClientProxyMocks, theDal).Excute(); ClientInformationModel theClientInformationModel = theDal.GetAllClientInfomationModel()[0]; Assert.AreEqual(2, theClientInformationModel.TheAddressModelCollcetion.Count); new DisableTheListenAddress(theClientInformationModel.Pkid, theClientInformationModel.TheAddressModelCollcetion[1].Pkid, theDal).Excute(); Assert.IsTrue(theClientInformationModel.TheAddressModelCollcetion[0].IsPermitted); Assert.IsTrue(theClientInformationModel.TheAddressModelCollcetion[0].IsActivited); Assert.IsFalse(theClientInformationModel.TheAddressModelCollcetion[1].IsPermitted); Assert.IsTrue(theClientInformationModel.TheAddressModelCollcetion[1].IsActivited); //增加一个允许的客户端,一个允许的地址,用于发送失败短信回传 new AddActivedClientInformation("permittedClient_SendFailedMessage", "已知的公司2", theDal).Excute(); new RegisterClientAddressTransaction("http://permittedAddress_SendFailedMessage", "permittedClient_SendFailedMessage", theClientProxyMocks, theDal).Excute(); //增加一个不被允许的客户段 try { new RegisterClientAddressTransaction("http://unknown/", "unknownId", theClientProxyMocks, theDal).Excute(); Assert.Fail(); } catch (ApplicationException) { } //模拟短信机需要回送短信的过程 CallbackDataGateWayImplement target = new CallbackDataGateWayImplement(theDal, theClientProxyMocks); target.OnReceivedMessages(new List <ReceiveMessageDataModel>()); target.OnSendFailedMessages(new SendMessageDataModel(-1, null, null, "permittedClient_SendFailedMessage")); target.OnStopServer(); Assert.AreEqual(2, MockSingleSmsClientContract._ReceiveTheMessages.Count); Assert.IsTrue(MockSingleSmsClientContract._ReceiveTheMessages.Contains("http://permittedAddress")); Assert.IsTrue(MockSingleSmsClientContract._ReceiveTheMessages.Contains("http://permittedAddress_SendFailedMessage")); Assert.AreEqual(1, MockSingleSmsClientContract._SendFailedMessages.Count); Assert.IsTrue(MockSingleSmsClientContract._SendFailedMessages.Contains("http://permittedAddress_SendFailedMessage")); Assert.AreEqual(2, MockSingleSmsClientContract._TheServiceStatusChanged.Count); Assert.IsTrue(MockSingleSmsClientContract._TheServiceStatusChanged.Contains("http://permittedAddress")); Assert.IsTrue(MockSingleSmsClientContract._TheServiceStatusChanged.Contains("http://permittedAddress_SendFailedMessage")); }
public void AddClientData() { ClientInformationModel clientData = new ClientInformationModel(); clientData.FirstName = "cc"; clientData.MiddleName = "dd"; clientData.LastName = "ddde"; clientData.Address = "dddfsdaf"; clientData.City = "bng"; clientData.State = "dd"; clientData.PhoneNumber = "111"; clientData.PinCode = "333"; ClientDetails cl = new ClientDetails(); cl.AddClientData(clientData); }
private void AfterChangeTheObject(ClientInformationModel theModelTobeUpdated) { ListenAddressModel listenAddressModel = theModelTobeUpdated.GetTheAddressModelById(_TheListenAddressId); if (!listenAddressModel.IsActivited) { return; } try { _TheClientProxy.TheServiceStatusChanged(true, listenAddressModel.ListenAddress); } catch (FaultException) { throw new ApplicationException("业务已经完成,但是通知客户端服务已经改变未能成功,可能是客户端已经关闭"); } }
private void LoadListenAddressFor(ClientInformationModel theObject) { SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add(_ClientInformationId, SqlDbType.Int).Value = theObject.Pkid; using (SqlDataReader sdr = SqlHelper.ExecuteReader("GetListenAddressByClientInformationId", cmd)) { while (sdr.Read()) { bool isPermitted = int.Parse(sdr[_DBIsPermitted].ToString()) > 0 ? true : false; bool isActived = int.Parse(sdr[_DBIsActived].ToString()) > 0 ? true : false; ListenAddressModel theModel = new ListenAddressModel(sdr[_DBListenAddress].ToString(), isPermitted, isActived, DateTime.Parse(sdr[_DBLastTryActivitedTime].ToString())); theModel.Pkid = int.Parse(sdr[_DBPKID].ToString()); theObject.TheAddressModelCollcetion.Add(theModel); } } }
public ClientInformationModel GetClientInformationById(int pkid) { ClientInformationModel retVal = null; SqlCommand cmd = new SqlCommand(); cmd.Parameters.Add(_PKID, SqlDbType.Int).Value = pkid; using (SqlDataReader sdr = SqlHelper.ExecuteReader("GetClientInformationByPkid", cmd)) { while (sdr.Read()) { bool isPermitted = int.Parse(sdr[_DBIsPermitted].ToString()) > 0 ? true : false; retVal = new ClientInformationModel(sdr[_DBHrmisId].ToString(), sdr[_DBCompanyDescription].ToString(), isPermitted); retVal.Pkid = pkid; LoadListenAddressFor(retVal); } } return(retVal); }
public void GetClientInfoDetails() { ClientDetailsClient client = new ClientDetailsClient(); var clientInfo = client.GetSingeClientData(AuditModel.ClientId); ClientDetail = new ObservableCollection <ClientInformationModel>(); ClientInformationModel clientInfoModel = new ClientInformationModel(); clientInfoModel.ClientId = clientInfo.ClientId; clientInfoModel.FirstName = clientInfo.FirstName; clientInfoModel.MiddleName = clientInfo.MiddleName; clientInfoModel.LastName = clientInfo.LastName; clientInfoModel.Address = clientInfo.Address; clientInfoModel.City = clientInfo.City; clientInfoModel.Country = clientInfo.Country; clientInfoModel.PinCode = clientInfo.PinCode; clientInfoModel.PhoneNumber = clientInfo.PhoneNumber; clientInfoModel.LastUpdated = clientInfo.LastUpdated; ClientDetail.Add(clientInfoModel); }
public List <ClientInformationModel> GetAllClientInfomationModel() { List <ClientInformationModel> retVal = new List <ClientInformationModel>(); SqlCommand cmd = new SqlCommand(); //数据库编码当参数取-1时获取所有的的值 cmd.Parameters.Add(_PKID, SqlDbType.Int).Value = -1; using (SqlDataReader sdr = SqlHelper.ExecuteReader("GetClientInformationByPkid", cmd)) { while (sdr.Read()) { bool isPermitted = int.Parse(sdr[_DBIsPermitted].ToString()) > 0 ? true : false; ClientInformationModel anObject = new ClientInformationModel(sdr[_DBHrmisId].ToString(), sdr[_DBCompanyDescription].ToString(), isPermitted); anObject.Pkid = int.Parse(sdr[_DBPKID].ToString()); LoadListenAddressFor(anObject); retVal.Add(anObject); } } return(retVal); }