Ejemplo n.º 1
0
        public void GetStatus()
        {
            Twizo twizo  = new Twizo(this.apiKey, this.apiHost);
            var   backup = twizo.GetBackupCode(this.identifier);

            LogResponse(backup);
        }
        public void ValidationExceptionTest()
        {
            //Arrange
            Twizo twizo        = new Twizo(TwizoTests.apiKey, TwizoTests.apiHost);
            var   verification = twizo.CreateVerification("601151174973");

            verification.tokenLength = 11;
            verification.tag         = "This tag contains more than 30 characters.";
            verification.validity    = 1;

            //Act
            try
            {
                verification.Send();
            }
            catch (ValidationException e)
            {
                var           errors     = e.errorFields;
                List <string> errorNames = errors.Select(x => x.name).ToList();

                //Assert
                Assert.IsTrue(e.Message.StartsWith("Validation error for field"));
                Assert.AreEqual(errors.Count, 3);
                Assert.IsTrue(errorNames.Contains("tag") && errorNames.Contains("tokenLength") && errorNames.Contains("validity"));
            }
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            CloudRail.AppKey = "[Your CloudRail Key]";

            List <ISMS> services = new List <ISMS>();

            Nexmo nexmo = new Nexmo(null, "[Nexmo API Key]", "[Nexmo API Secret]");

            services.Add(nexmo);

            Twilio twilio = new Twilio(null, "[Twilio Account SID]", "[Twilio Auth Token]");

            services.Add(twilio);

            Twizo twizo = new Twizo(null, "[Twizo Key]");

            services.Add(twizo);

            foreach (ISMS service in services)
            {
                try
                {
                    service.SendSMS("[Sending Number]", "[Receiving Number]", "Hello from " + service);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Ejemplo n.º 4
0
        public void Update()
        {
            Twizo twizo  = new Twizo(this.apiKey, this.apiHost);
            var   backup = twizo.CreateBackupCode(this.identifier);

            backup.Update();
            LogResponse(backup);
        }
Ejemplo n.º 5
0
        public void Verify(string token)
        {
            Twizo twizo  = new Twizo(this.apiKey, this.apiHost);
            var   backup = twizo.CreateBackupCode(this.identifier);

            backup.Verify(token);
            LogResponse(backup);
        }
Ejemplo n.º 6
0
        public Boolean Verify(string token)
        {
            Twizo twizo        = new Twizo(this.apiKey, this.apiHost);
            var   verification = twizo.GetTokenResult(token, this.messageId);

            LogResponse(verification);
            return(verification.statusCode == (int)TwizoAPI.Entity.VerificationStatusCode.SUCCESS);
        }
Ejemplo n.º 7
0
        public void GetVerificationTestNull()
        {
            //Arrange
            string messageId = null;
            Twizo  twizo     = new Twizo(apiKey, apiHost);

            //Act
            twizo.GetVerification(messageId);
        }
Ejemplo n.º 8
0
        public void CreateBalanceTest()
        {
            //Arrange
            Twizo twizo = new Twizo(apiKey, apiHost);

            //Act
            var balance = twizo.CreateBalance();

            //Assert
            Assert.IsNotNull(balance);
        }
Ejemplo n.º 9
0
        public void GetNumberLookupResultsTest()
        {
            //Arrange
            Twizo twizo = new Twizo(apiKey, apiHost);

            //Act
            var results = twizo.GetNumberLookupResults();

            //Assert
            Assert.IsNotNull(results);
        }
Ejemplo n.º 10
0
        public void CreateBackupCodeTest()
        {
            //Arrange
            string identifier = "myIdentifier";
            Twizo  twizo      = new Twizo(apiKey, apiHost);

            //Act
            var backup = twizo.CreateBackupCode(identifier);

            //Assert
            Assert.AreEqual(backup.identifier, identifier);
        }
Ejemplo n.º 11
0
        public void CreateVerificationTestNull()
        {
            //Arrange
            string recipient = null;
            Twizo  twizo     = new Twizo(apiKey, apiHost);

            //Act
            var verification = twizo.CreateVerification(recipient);

            //Assert
            Assert.AreEqual(verification.recipient, recipient);
        }
Ejemplo n.º 12
0
        public void CreateNumberLookupTestNull()
        {
            //Arrange
            string[] numbers = null;
            Twizo    twizo   = new Twizo(apiKey, apiHost);

            //Act
            var lookup = twizo.CreateNumberLookup(numbers);

            //Assert
            Assert.AreEqual(lookup.numbers, numbers);
        }
Ejemplo n.º 13
0
        public void Send()
        {
            //Create entity
            Twizo twizo = new Twizo(this.apiKey, this.apiHost);
            var   sms   = twizo.CreateSms(this.recipients, this.body, this.sender);

            sms.resultType = 2;

            //Set variables
            if (this.senderTon >= 0)
            {
                sms.senderTon = this.senderTon;
            }
            if (this.senderNpi >= 0)
            {
                sms.senderNpi = this.senderNpi;
            }
            if (this.pid >= 0)
            {
                sms.pid = this.pid;
            }
            //sms.scheduledDelivery = this.scheduledDelivery.ToString("yyyy-MM-ddTHH:mm:ssZ");
            if (this.tag != "")
            {
                sms.tag = this.tag;
            }
            sms.validity = this.validity;
            if (this.resultType >= 0)
            {
                sms.resultType = this.resultType;
            }
            if (this.callbackUrl != "")
            {
                sms.callbackUrl = this.callbackUrl;
            }

            if (this.dcs >= 0)
            {
                sms.dcs = this.dcs;
            }
            if (this.udh != "")
            {
                sms.udh = this.udh;
            }

            //Send
            sms.Send();

            //Log
            LogResponse(sms);
            this.messageId = sms.messageId;
        }
Ejemplo n.º 14
0
        public void CreateVerificationCallTest()
        {
            //Arrange
            string recipient = "601151174973";
            Twizo  twizo     = new Twizo(apiKey, apiHost);

            //Act
            var verification = twizo.CreateVerificationCall(recipient);

            //Assert
            Assert.AreEqual(verification.recipient, recipient);
            Assert.AreEqual(verification.type, Verification.TYPE_CALL);
        }
Ejemplo n.º 15
0
        public void CreateWidgetSessionTestNull()
        {
            //Arrange
            string[] allowedTypes = new[] { WidgetSession.TYPE_SMS, WidgetSession.TYPE_BACKUP_CODE };
            string   recipient    = null;
            Twizo    twizo        = new Twizo(apiKey, apiHost);

            //Act
            var session = twizo.CreateWidgetSession(allowedTypes, recipient);

            //Assert
            Assert.AreEqual(session.allowedTypes, allowedTypes);
            Assert.AreEqual(session.recipient, recipient);
        }
Ejemplo n.º 16
0
        private void Balance()
        {
            Twizo twizo   = new Twizo(apiKey, apiHost);
            var   balance = twizo.CreateBalance();

            balance.LoadData();
            Console.WriteLine();
            Console.WriteLine("Wallet name: " + balance.wallet);
            Console.WriteLine("Currency code: " + balance.currencyCode);
            Console.WriteLine("Balance: " + balance.credit.ToString());
            Console.WriteLine("Free verifications: " + balance.freeVerification.ToString());
            Console.WriteLine();
            RunMenu();
        }
Ejemplo n.º 17
0
        public void GetNumberLookupTest()
        {
            //Arrange
            string recipient = "601151174973";
            Twizo  twizo     = new Twizo(apiKey, apiHost);

            //Act
            var lookup = twizo.CreateNumberLookup(recipient);

            lookup.Send();
            string messageId = lookup.messageId;
            var    newLookup = twizo.GetNumberLookup(messageId);

            //Assert
            Assert.AreEqual(lookup.messageId, newLookup.messageId);
        }
Ejemplo n.º 18
0
        public void CreateSmsTestNull()
        {
            //Arrange
            string recipient = null;
            string body      = "This is a unit test";
            string sender    = "Unit tester";
            Twizo  twizo     = new Twizo(apiKey, apiHost);

            //Act
            var sms = twizo.CreateSms(recipient, body, sender);

            //Assert
            Assert.AreEqual(sms.recipient, recipient);
            Assert.AreEqual(sms.body, body);
            Assert.AreEqual(sms.sender, sender);
        }
Ejemplo n.º 19
0
        public void LoadDataTest()
        {
            //Arrange
            Twizo twizo = new Twizo(TwizoTests.apiKey, TwizoTests.apiHost);

            //Act
            var balance = twizo.CreateBalance();

            balance.LoadData();

            //Assert
            Assert.IsNotNull(balance.credit);
            Assert.IsNotNull(balance.freeVerification);
            Assert.IsNotNull(balance.currencyCode);
            Assert.IsNotNull(balance.wallet);
        }
Ejemplo n.º 20
0
        public void Send()
        {
            //Create entity
            Twizo twizo = new Twizo(this.apiKey, this.apiHost);

            TwizoAPI.Entity.Verification verification;
            if (call)
            {
                verification = twizo.CreateVerificationCall(this.recipient);
            }
            else
            {
                verification = twizo.CreateVerification(this.recipient);
            }

            //Set variables
            verification.type        = this.type;
            verification.tokenLength = this.tokenLength;
            verification.tokenType   = this.tokenType;
            if (this.tag != "")
            {
                verification.tag = this.tag;
            }
            if (this.sessionId != "")
            {
                verification.sessionId = this.sessionId;
            }
            verification.validity     = this.validity;
            verification.bodyTemplate = this.bodyTemplate;
            verification.sender       = this.sender;
            if (this.senderTon >= 0)
            {
                verification.senderTon = this.senderTon;
            }
            if (this.senderTon >= 0)
            {
                verification.senderNpi = this.senderNpi;
            }
            verification.dcs = this.dcs;

            //Send
            verification.Send();

            //Log
            LogResponse(verification);
            this.messageId = verification.messageId;
        }
Ejemplo n.º 21
0
        public void GetVerificationTest()
        {
            //Arrange
            string recipient = "601151174973";
            Twizo  twizo     = new Twizo(apiKey, apiHost);

            //Act
            var verification = twizo.CreateVerification(recipient);

            verification.Send();
            string messageId       = verification.messageId;
            var    newVerficiation = twizo.GetVerification(messageId);

            //Assert
            Assert.AreEqual(verification.messageId, newVerficiation.messageId);
            Assert.AreEqual(verification.recipient, newVerficiation.recipient);
        }
Ejemplo n.º 22
0
        private void Results()
        {
            string file = Menu.MyResultsFolder + @"\TwizoTestLogResults.txt";

            File.Delete(file);

            Twizo twizo         = new Twizo(apiKey, apiHost);
            var   SmsReports    = twizo.GetSmsResults();
            var   LookupResults = twizo.GetNumberLookupResults();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("---------------SMS REPORTS---------------");
            foreach (var sms in SmsReports)
            {
                Type           type       = sms.GetType();
                PropertyInfo[] properties = type.GetProperties();
                foreach (PropertyInfo property in properties)
                {
                    sb.AppendLine(String.Format("{0, -25} : {1}", property.Name, property.GetValue(sms, null)));
                }
                sb.AppendLine(Environment.NewLine);
                sb.AppendLine("----------------------");
            }

            sb.AppendLine("----------NUMBER LOOKUP RESULTS----------");
            foreach (var lookup in LookupResults)
            {
                Type           type       = lookup.GetType();
                PropertyInfo[] properties = type.GetProperties();
                foreach (PropertyInfo property in properties)
                {
                    sb.AppendLine(String.Format("{0, -25} : {1}", property.Name, property.GetValue(lookup, null)));
                }
                sb.AppendLine(Environment.NewLine);
                sb.AppendLine("----------------------");
            }

            File.AppendAllText(file, sb.ToString());

            Process.Start(file);
            Console.WriteLine("Results were succesfully requested and written to TwizoTestLogResults.txt");
            Console.WriteLine("Press any key to return to main menu.");
            Console.ReadKey(true);
            RunMenu();
        }
Ejemplo n.º 23
0
        public void GetWidgetSessionTest()
        {
            //Arrange
            string recipient = "601151174973";

            string[] allowedTypes = new[] { WidgetSession.TYPE_SMS };
            Twizo    twizo        = new Twizo(apiKey, apiHost);

            //Act
            var session = twizo.CreateWidgetSession(allowedTypes, recipient);

            session.Create();
            string token      = session.sessionToken;
            var    newSession = twizo.GetWidgetSession(token, recipient);

            //Assert
            Assert.AreEqual(session.sessionToken, newSession.sessionToken);
            Assert.AreEqual(session.recipient, newSession.recipient);
        }
Ejemplo n.º 24
0
        public void GetSmsTest()
        {
            //Arrange
            string recipient = "601151174973";
            string body      = "This is a unit test";
            string sender    = "Unit tester";
            Twizo  twizo     = new Twizo(apiKey, apiHost);

            //Act
            var sms = twizo.CreateSms(recipient, body, sender);

            sms.Send();
            string messageId = sms.messageId;
            var    newSms    = twizo.GetSms(messageId);

            //Assert
            Assert.AreEqual(sms.messageId, newSms.messageId);
            Assert.AreEqual(sms.recipient, newSms.recipient);
        }
Ejemplo n.º 25
0
        public void Send()
        {
            Twizo twizo  = new Twizo(this.apiKey, this.apiHost);
            var   lookup = twizo.CreateNumberLookup(numbers);

            if (this.tag != "")
            {
                lookup.tag = this.tag;
            }
            lookup.validity   = this.validity;
            lookup.resultType = this.resultType;
            if (this.callbackUrl != "")
            {
                lookup.callbackUrl = this.callbackUrl;
            }

            lookup.Send();
            LogResponse(lookup);
            this.messageId = lookup.messageId;
        }
Ejemplo n.º 26
0
        public TwizoAPI.Entity.Verification Refresh()
        {
            Twizo twizo = new Twizo(this.apiKey, this.apiHost);

            return(twizo.GetVerification(this.messageId));
        }
Ejemplo n.º 27
0
        public TwizoAPI.Entity.Sms Refresh()
        {
            Twizo twizo = new Twizo(this.apiKey, this.apiHost);

            return(twizo.GetSms(this.messageId));
        }
Ejemplo n.º 28
0
        public TwizoAPI.Entity.NumberLookup Refresh()
        {
            Twizo twizo = new Twizo(this.apiKey, this.apiHost);

            return(twizo.GetNumberLookup(this.messageId));
        }