public void Test_AddEQI()
 {
     SyncRequest synReq = new SyncRequest();
     synReq.CustomerId = "010203040";
     synReq.CustomerStatus = "A";
     EquipmentSyncRequest esynReq = new EquipmentSyncRequest();
     esynReq.CustomerId = "010203040";
     esynReq.macAddress = "00:00:40:C4:2A:1E";
     esynReq.offeringId = new List<string>("0001234/0001236/0001237".Split('/'));
     esynReq.smartCardId = "";
     CustomerEquipmentRequest ceReq = new CustomerEquipmentRequest(esynReq, synReq);
     ServiceRunTimeManager srvRunMgr = new ServiceRunTimeManager();
     String expRes = srvRunMgr.transalteResCode2ICOM4m4C(ceReq.AddEQI(), "AddEQI");
     Assert.AreEqual("0000901", expRes, "Should not able to add customer Equipment as Device Id is passes as incorrect format");
 }
        public void Test_processCCIMessage_InvInput()
        {
            ServiceRunTimeManager srtMngr = new ServiceRunTimeManager();
            ServiceListenerMembers listMem = new ServiceListenerMembers();
            listMem.siteid = "siteid1";
            listMem.listenerAddress = "10.203.232.19";

            listMem.CustomerIdFlag = "true";

            listMem.listenerPort = "12000";

            String testData = "I000CUI,TI:000000000000000000,AN:010203040,SI:013,HE:C3,ND:B4567,BD:05,TL:Mrs ,LN:Customer       ,FN:Test      ,MI:E,A1:222 Avenue St.                  ,A2:Apt#123                         ,CT:Greensburg               ,ST:PA,ZP:12345    ,HP:213 123 1234,WP:215 123 1234,AS:A,E1:ENG000102030405.00039V000CUI,0000000,TI:000000000000000000.select LastName from Subscriber where SmsTag='013010203040'CUSTOMERselect FirstName from Subscriber where SmsTag='013010203040'TEST";
            String expData = "0000116";
            String resp = srtMngr.processCCIMessage(testData, listMem);
            Assert.AreEqual(expData, resp, "CCI Message is not processed correctly. Response [" + resp + "]");
        }
        public void Test_DeleteEQI()
        {
            SyncRequest synReq = new SyncRequest();
            synReq.CustomerId = "010203040";
            synReq.CustomerStatus = "A";
            EquipmentSyncRequest esynReq = new EquipmentSyncRequest();
            esynReq.CustomerId = "010203040";
            esynReq.macAddress = "00002986685810000000000000000987123";
            esynReq.offeringId = new List<string>("0001234/0001236/0001237".Split('/'));
            esynReq.smartCardId = "";
            CustomerEquipmentRequest ceReq = new CustomerEquipmentRequest(esynReq, synReq);
            ServiceRunTimeManager srvRunMgr = new ServiceRunTimeManager();
            String expRes = srvRunMgr.transalteResCode2ICOM4m4C(ceReq.DeleteEQI(), "DeleteEQI");

            Assert.AreEqual("0000301", expRes, "Should not be able to delete customer Equipment as device id is passed as incorrect value");
        }
        public void Test_AddEQI_ValidUrl()
        {
            SyncRequest synReq = new SyncRequest();
            synReq.CustomerId = "010203551";
            synReq.CustomerStatus = "A";
            EquipmentSyncRequest esynReq = new EquipmentSyncRequest();
            esynReq.CustomerId = "010203551";
            esynReq.macAddress = "00002986685810000000000000000551";
            esynReq.offeringId = new List<string>("0001234/0001236/0001237".Split('/'));
            esynReq.smartCardId = "";
            CustomerEquipmentRequest ceReq = new CustomerEquipmentRequest(esynReq, synReq);
            ServiceRunTimeManager srvRunMgr = new ServiceRunTimeManager();
            String expRes = srvRunMgr.transalteResCode2ICOM4m4C(ceReq.AddEQI(), "AddEQI");

            Assert.AreEqual("0000000", expRes, "Should be able to add Customer Equipment ");
        }
        public void Test_processCCIMessage()
        {
            ServiceRunTimeManager srtMngr = new ServiceRunTimeManager();
            ServiceListenerMembers listMem = new ServiceListenerMembers();
            listMem.siteid = "siteid1";
            listMem.listenerAddress = "10.203.232.19";

            listMem.CustomerIdFlag = "true";

            listMem.listenerPort = "12000";

            String testData = "I000CCI,TI:000000000000000000,AN:010203040,SI:013,CA:AB,CL:000000995,CP:0000000.00039V000CCI,0000000,TI:000000000000000000.select CreditLimit from Subscriber where SmsTag='013010203040'995";
            String expData_Success = "0000000";
            String expData_Fail = "0000901";
            String resp = srtMngr.processCCIMessage(testData, listMem);
            if (resp.Equals(expData_Success) || resp.Equals(expData_Fail))
            {
                Assert.Pass("CCI Message is processed correctly");
            }
            else
            {
                Assert.Fail("CCI Message is not processed correctly. Response [" + resp+"]");
            }
        }
        public void Test_processEQIMessage()
        {
            ServiceRunTimeManager srtMngr = new ServiceRunTimeManager();
            ServiceListenerMembers listMem = new ServiceListenerMembers();
            listMem.siteid = "siteid1";
            listMem.listenerAddress = "10.203.232.19";

            listMem.CustomerIdFlag = "true";

            listMem.listenerPort = "12000";

            String testData = "I000EQI,TI:000000000000000000,AN:010203040,SI:013,ES:A,EA:00002986685930000000000000000000,S#:ABC45678901234567890123456789012,PA:ABCDEFGH,SV:0001234/0001236/0001237,AC:A,0000257,TI:000000000000000000.select * from Settop where MacAddr='000011cd5231'<empty>";
            String expData_Success = "0000000";
            String expData_Fail = "0000901";
            String resp = srtMngr.processEQIMessage(testData, listMem);
            if (resp.Equals(expData_Success) || resp.Equals(expData_Fail))
            {
                Assert.Pass("EQI Message is processed correctly");
            }
            else
            {
                Assert.Fail("EQI Message is not processed correctly. Response [" + resp + "]");
            }
        }
        public void Test_processCUIMessage_InvInput()
        {
            ServiceRunTimeManager srtMngr = new ServiceRunTimeManager();
            ServiceListenerMembers listMem = new ServiceListenerMembers();
            listMem.siteid = "siteid1";
            listMem.listenerAddress = "10.203.232.19";

            listMem.CustomerIdFlag = "true";

            listMem.listenerPort = "12000";

            String testData = "I000CCI,TI:000000000000000000,AN:010203040,SI:013,CA:AB,CL:000000995,CP:0000000.00039V000CCI,0000000,TI:000000000000000000.select CreditLimit from Subscriber where SmsTag='013010203040'995";
            String expData = "0000114";
            String resp = srtMngr.processCUIMessage(testData, listMem);
            Assert.AreEqual(expData, resp, "CUI Message is not processed correctly. Response [" + resp + "]");
        }
        public void Test_UpdateEQI()
        {
            SyncRequest synReq = new SyncRequest();
            synReq.CustomerId = "010203040";
            synReq.CustomerStatus = "A";
            EquipmentSyncRequest esynReq = new EquipmentSyncRequest();
            esynReq.CustomerId = "010203040";
            esynReq.macAddress = "00002986685810000000000000000001";
            esynReq.offeringId = new List<string>("0005432".Split('/'));
            esynReq.smartCardId = "";
            CustomerEquipmentRequest ceReq = new CustomerEquipmentRequest(esynReq, synReq);
            ServiceRunTimeManager srvRunMgr = new ServiceRunTimeManager();
            String expRes = srvRunMgr.transalteResCode2ICOM4m4C(ceReq.UpdateEQI(), "UpdateEQI");

            Assert.AreEqual("0000901", expRes, "Should not able to update customer Equipment as product id is not in correct format");
        }
        static void ListenForRequests(object tempObj)
        {
            logger.Info("ICOMSProvisioningService::ListenForRequests() called");

            string strIPAddress = string.Empty;
            ServiceListenerMembers templistenerMembers;
            templistenerMembers = (ServiceListenerMembers)tempObj;
            ServiceRunTimeManager objServiceMgr;
            TcpListener tcpICOMServer = new TcpListener(IPAddress.Parse(templistenerMembers.listenerAddress), Convert.ToInt32(templistenerMembers.listenerPort));
            // Start listening for client requests.

            try
            {
            tcpICOMServer.Start();
            strIPAddress = templistenerMembers.listenerAddress + ":" + templistenerMembers.listenerPort;
            int bytesRead;
            logger.Info(string.Format("The server listening at...  {0}", strIPAddress));

            // Client connection loop
            while (true)
            {
                //TcpClient tcpICOMClient;
                Socket tcpICOMSocket;
                bool isClientClosed=false;
                try
                {
                    //tcpICOMClient = tcpICOMServer.AcceptTcpClient();
                    tcpICOMSocket = tcpICOMServer.AcceptSocket();

                    string clientIP = tcpICOMSocket.RemoteEndPoint.ToString();
                    logger.Info(string.Format("Connection established: {0}", clientIP));
                    //NetworkStream clientStream = tcpICOMClient.GetStream();

                    string strRec = string.Empty;
                    string strSend = string.Empty;
                    byte[] message = new byte[4096];

                    //persistent communication loop after client connected
                    while (true)
                    {
                        bytesRead = 0;

                        try
                        {
                            //blocks until a client sends a message
                            //bytesRead = clientStream.Read(message, 0, 4096);
                            bytesRead = tcpICOMSocket.Receive(message, 0, message.Length, 0);
                            if (bytesRead == 0)
                            {
                                logger.Debug("Message length received zero closing..");
                                //the client has disconnected from the server
                                break;
                            }
                            logger.Debug("++++++++++++++++ MESSAGE PROCESS START +++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                            TimeSpan startTS = System.DateTime.Now.TimeOfDay;
                            logger.Info(string.Format("Conversion of byte data to string from {0} at {1} progress", strIPAddress, startTS));

                            ASCIIEncoding encoder = new ASCIIEncoding();
                            strRec = encoder.GetString(message, 0, bytesRead);

                            logger.Info("Converted string data...");
                            logger.Info(string.Format("{0}", strRec));

                            // Calling Service Run Time Manager of ICOMS Provisioning service
                            objServiceMgr = new ServiceRunTimeManager();
                            strSend = objServiceMgr.processICOMSMessages(strRec, templistenerMembers);

                            ASCIIEncoding asen = new ASCIIEncoding();
                            byte[] buffer = encoder.GetBytes(strSend);
                            //clientStream.Write(buffer, 0, buffer.Length);
                            //clientStream.Flush();
                            tcpICOMSocket.Send(buffer);

                            TimeSpan endTS = System.DateTime.Now.TimeOfDay;
                            logger.Info(string.Format("Response Data to ICOMS...{0}, client={1}  Process Time={2}", strSend, clientIP, endTS.Subtract(startTS)));
                            logger.Debug("++++++++++++++++ MESSAGE PROCESS END +++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                        }
                        catch (Exception ex)
                        {
                            logger.Warn(string.Format("Client disconnected abruptly from {0}", clientIP));
                            //clientStream.Close();
                            //tcpICOMClient.Close();
                            tcpICOMSocket.Close();
                            isClientClosed = true;
                            logger.Error(string.Format("ListenForRequests(): Exception: {0}", ex.Message.ToString()));
                            logger.Error("ICOMSProvisioningService::ListenForRequests() failing while reading data from client");
                            break;
                        }
                    }
                    /* clean up */
                    if (!isClientClosed)
                    {
                        //clientStream.Close();
                        //tcpICOMClient.Close();
                        tcpICOMSocket.Close();
                    }
                    logger.Info(string.Format("Connection closed from {0}", clientIP));
                }
                catch (Exception ex)
                {
                    logger.Error(string.Format("ListenForRequests(): Exception: {0}", ex.Message.ToString()));
                    logger.Error("ICOMSProvisioningService::ListenForRequests() failing while reading data from client");
                }

            }

            }
            catch (Exception ex)
            {
            logger.Error(string.Format("ListenForRequests(): Exception: {0}", ex.Message.ToString()));
            logger.Error("ICOMSProvisioningService::ListenForRequests() failing while start listening the server");
            }
        }