public static void Run() { const string Username = ""; const string Password = ""; const bool Sandbox = true; NextCallerClient client = new NextCallerClient(Username, Password, Sandbox); const string Phone = "1234567890"; try { FraudLevel fraudLevel = client.GetFraudLevel(Phone); //fraudLevel.FraudRisk = "low"; //fraudLevel.Spoofed = "no"; } catch (FormatException formatException) { HttpWebRequest request = formatException.Request; HttpWebResponse response = formatException.Response; HttpStatusCode code = response.StatusCode; Console.WriteLine("Status code: {0}", code); string reasonPhrase = response.StatusDescription; Console.WriteLine("Reason Phrase: {0}", reasonPhrase); string responseContent = formatException.Content; Console.WriteLine("Content : {0}", responseContent); } catch (BadRequestException badRequestException) { HttpWebRequest request = badRequestException.Request; HttpWebResponse response = badRequestException.Response; Error parsedError = badRequestException.Error; string errorCode = parsedError.Code; string message = parsedError.Message; string type = parsedError.Type; Dictionary<string, string[]> description = parsedError.Description; Console.WriteLine(parsedError.ToString()); } }
public void CreatingClientInstance_NullUsername_ArgumentExceptionThrown() { //Arrange const string Username = null; const string Password = "******"; try { //Action NextCallerClient client = new NextCallerClient(Username, Password); Assert.Fail("An exception should have been thrown"); } catch (ArgumentException argumentException) { //Assert Assert.AreEqual("username", argumentException.ParamName); } }
public void AnalyzeCall_ValidData_FraudLevelReturned() { //Arrange string jsonFraudLevel = Properties.Resources.JsonFraudLevel; AnalyzeCallData data = new AnalyzeCallData { Ani = "12125551212", Dnis = "18005551212", Headers = new Dictionary<string, object> { { "from", "\"John Smith\" <sip:[email protected]>" }, { "via", new List<string> { "SIP/2.0//UDP 1.1.1.1:5060;branch=z9hG4bK3fe1.9a945462b4c1880c5f6fdc0214a205ca.1"} } }, Meta = new Dictionary<string, string> { { "caller_id", "12125551212" }, { "charge_number", "12125551212" }, { "ani2", "0" }, { "private", "true" } } }; Mock<IHttpTransport> httpTransportMock = new Mock<IHttpTransport>(MockBehavior.Strict); httpTransportMock.Setup(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), It.IsAny<string>(), It.IsAny<IEnumerable<Header>>())) .Returns(jsonFraudLevel); //Action NextCallerClient client = new NextCallerClient(httpTransportMock.Object); string jsonData = JsonSerializer.Serialize(data); string fraudLevel = client.AnalyzeCallJson(jsonData); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), It.IsAny<string>(), It.IsAny<IEnumerable<Header>>()), Times.Once); Assert.IsNotNull(fraudLevel); Assert.AreEqual(jsonFraudLevel, fraudLevel); }
public static void Run() { const string Username = ""; const string Password = ""; const bool Sandbox = true; NextCallerClient client = new NextCallerClient(Username, Password, Sandbox); const string Email = "*****@*****.**"; try { IList<Profile> profiles = client.GetByEmail(Email); Profile profile = profiles.First(); //profile.Id = "97d949a413f4ea8b85e9586e1f2d9a"; //profile.FirstName = "Jerry"; //profile.LastName = "Seinfeld"; //profile.Name = "Jerry K Seingeld"; //profile.Language = "English"; //Phone phone = profile.Phones.First(); //phone.Number = "2125558383"; //phone.ResourceUri = "/v2/records/2125558383/"; //profile.Carrier = "Verizon Wireless"; //profile.LineType = "LAN"; //Address address = profile.Addresses.First(); //address.City = "New York"; //address.State = "NY"; //address.Country = "USA"; //address.Line1 = "129 West 81st Street"; //address.Line2 = "Apt 5a"; //address.ZipCode = "10024"; //address.ExtendedZip = ""; //profile.Email = "*****@*****.**"; //profile.LinkedEmails = new[] //{ // "*****@*****.**", "*****@*****.**", "*****@*****.**" //}; //profile.SocialLinks = new[] //{ // new Dictionary<string, object>() // { // { "type", "twitter" }, // { "url", "http://www.twitter.com/example" }, // { "followers", 323 } // } //}; //profile.Relatives = new [] //{ // new Relative // { // Id = "a4bf8cff1bfd61d8611d396997bb29", // Name = "Clark Kent", // ResourceUri = "/v2/users/90c6a00c6391421d3a764716927cd8/" // } //}; //profile.DateOfBirth = "05/15/1970"; //profile.Gender = "Male"; //profile.Age = "45-54"; //profile.HouseholdIncome = "50k-75k"; //profile.HomeOwnerStatus = "Rent"; //profile.LengthOfResidence = "12 Years"; //profile.Occupation = "Entertainer"; //profile.Education = "Completed College"; //profile.ResourceUri = "/v2/users/97d949a413f4ea8b85e9586e1f2d9a/"; } catch (FormatException formatException) { HttpWebRequest request = formatException.Request; HttpWebResponse response = formatException.Response; HttpStatusCode code = response.StatusCode; Console.WriteLine("Status code: {0}", code); string reasonPhrase = response.StatusDescription; Console.WriteLine("Reason Phrase: {0}", reasonPhrase); string responseContent = formatException.Content; Console.WriteLine("Content : {0}", responseContent); } catch (BadRequestException badRequestException) { HttpWebRequest request = badRequestException.Request; HttpWebResponse response = badRequestException.Response; Error parsedError = badRequestException.Error; string errorCode = parsedError.Code; string message = parsedError.Message; string type = parsedError.Type; Dictionary<string, string[]> description = parsedError.Description; // Console.WriteLine(parsedError.ToString()); } }
public static void Run() { const string Username = ""; const string Password = ""; const bool Sandbox = true; NextCallerClient client = new NextCallerClient(Username, Password, Sandbox); try { AnalyzeCallData callData = new AnalyzeCallData { Ani = "12125551212", Dnis = "18005551212", Headers = new Dictionary<string, object> { { "from", "\"John Smith\" <sip:[email protected]>" }, { "via", new List<string> { "SIP/2.0//UDP 1.1.1.1:5060;branch=z9hG4bK3fe1.9a945462b4c1880c5f6fdc0214a205ca.1"} } }, Meta = new Dictionary<string, string> { { "caller_id", "12125551212" }, { "charge_number", "12125551212" }, { "ani2", "0" }, { "private", "true" } } }; FraudLevel fraudLevel = client.AnalyzeCall(callData); } catch (FormatException formatException) { HttpWebRequest request = formatException.Request; HttpWebResponse response = formatException.Response; HttpStatusCode code = response.StatusCode; Console.WriteLine("Status code: {0}", code); string reasonPhrase = response.StatusDescription; Console.WriteLine("Reason Phrase: {0}", reasonPhrase); string responseContent = formatException.Content; Console.WriteLine("Content : {0}", responseContent); } catch (BadRequestException badRequestException) { HttpWebRequest request = badRequestException.Request; HttpWebResponse response = badRequestException.Response; Error parsedError = badRequestException.Error; string errorCode = parsedError.Code; string message = parsedError.Message; string type = parsedError.Type; Dictionary<string, string[]> description = parsedError.Description; Console.WriteLine(parsedError.ToString()); } }
public void GetFraudLevel_ValidPhone_FraudLevelReturned() { //Arrange const string PhoneNumber = "2020327000"; string jsonFraudLevel = Properties.Resources.JsonFraudLevel; Mock<IHttpTransport> httpTransportMock = new Mock<IHttpTransport>(MockBehavior.Strict); httpTransportMock.Setup(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, It.IsAny<IEnumerable<Header>>())) .Returns(jsonFraudLevel); //Action NextCallerClient client = new NextCallerClient(httpTransportMock.Object); string fraudLevel = client.GetFraudLevelJson(PhoneNumber); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, It.IsAny<IEnumerable<Header>>()), Times.Once); Assert.IsNotNull(fraudLevel); Assert.AreEqual(jsonFraudLevel, fraudLevel); }
public void PostProfile_ValidIdAndValidProfile_NoExceptionsThrown() { //Arrange const string ProfileId = "adaSfaqwfasfasdasdfasfasfasd"; ProfileToPost profile = new ProfileToPost { FirstName = "NewFirstName", LastName = "NewLastName" }; Mock<IHttpTransport> httpTransportMock = new Mock<IHttpTransport>(MockBehavior.Strict); httpTransportMock.Setup(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), "POST", It.IsAny<string>(), null)) .Returns(string.Empty); //Action NextCallerClient client = new NextCallerClient(httpTransportMock.Object); client.UpdateByProfileId(ProfileId, profile); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), "POST", It.IsAny<string>(), null), Times.Once); }
public void GetProfilesByphone_ValidPhone_ProfilesReturned() { //Arrange const string PhoneNumber = "2020327000"; string jsonProfiles = Properties.Resources.JsonProfiles; Mock<IHttpTransport> httpTransportMock = new Mock<IHttpTransport>(MockBehavior.Strict); httpTransportMock.Setup(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, null)) .Returns(jsonProfiles); //Action NextCallerClient client = new NextCallerClient(httpTransportMock.Object); string profiles = client.GetByPhoneJson(PhoneNumber); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, null), Times.Once); Assert.IsNotNull(profiles); Assert.AreEqual(jsonProfiles, profiles); }
public void GetProfilesByNameAddress_ValidNA_ProfilesReturned() { //Arrange NameAddress nameAddress = new NameAddress { AddressLine = "129 West 81st Street", FirstName = "Jerry", LastName = "Seinfeld", City = "New York", State = "NY" }; string jsonProfiles = Properties.Resources.JsonProfiles; Mock<IHttpTransport> httpTransportMock = new Mock<IHttpTransport>(MockBehavior.Strict); httpTransportMock.Setup(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, null)) .Returns(jsonProfiles); //Action NextCallerClient client = new NextCallerClient(httpTransportMock.Object); string profiles = client.GetByNameAddressJson(nameAddress); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, null), Times.Once); Assert.IsNotNull(profiles); Assert.AreEqual(jsonProfiles, profiles); }
public void GetProfileEmail_ValidEmail_ProfileReturned() { //Arrange const string ValidEmail = "*****@*****.**"; var jsonProfiles = Properties.Resources.JsonProfiles; Mock<IHttpTransport> httpTransportMock = new Mock<IHttpTransport>(MockBehavior.Strict); httpTransportMock.Setup(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, It.IsAny<IEnumerable<Header>>())) .Returns(jsonProfiles); //Action NextCallerClient client = new NextCallerClient(httpTransportMock.Object); string profiles = client.GetByEmailJson(ValidEmail); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, It.IsAny<IEnumerable<Header>>()), Times.Once); Assert.IsNotNull(profiles); Assert.AreEqual(profiles, jsonProfiles); }
public void GetProfileById_ValidId_ProfileReturned() { //Arrange const string ProfileId = "adaSfaqwfasfasdasdfasfasfasd"; string jsonProfile = Properties.Resources.JsonProfile; Mock<IHttpTransport> httpTransportMock = new Mock<IHttpTransport>(MockBehavior.Strict); httpTransportMock.Setup(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, null)) .Returns(jsonProfile); //Action NextCallerClient client = new NextCallerClient(httpTransportMock.Object); string profile = client.GetByProfileIdJson(ProfileId); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny<string>(), It.IsAny<ContentType>(), It.IsIn("GET", "POST"), null, null), Times.Once); Assert.IsNotNull(profile); Assert.AreEqual(jsonProfile, profile); }
public void GetProfileById_NullId_ArgumentExceptionThrown() { //Arrange const string Id = null; Mock<IHttpTransport> httpTransportMock = new Mock<IHttpTransport>(MockBehavior.Strict); NextCallerClient client = new NextCallerClient(httpTransportMock.Object); try { //Action Profile profile = client.GetByProfileId(Id); Assert.Fail("An exception should have been thrown"); } catch (ArgumentException argumentException) { //Assert Assert.AreEqual("profileId", argumentException.ParamName); } }
public static void Run() { const string Username = ""; const string Password = ""; const bool Sandbox = true; NextCallerClient client = new NextCallerClient(Username, Password, Sandbox); const string ProfileId = "profileId"; try { ProfileToPost profile = new ProfileToPost { Email = "*****@*****.**", FirstName = "Clark", LastName = "Kent", PrimaryAddress = new Address { Line1 = "223 Kryptonite Ave.", Line2 = "", City = "Smallville", State = "KS", ZipCode = "66002" }, SecondaryAddress = new Address { Line1 = "223 Kryptonite Ave.", Line2 = "", City = "Smallville", State = "KS", ZipCode = "66002" }, }; client.UpdateByProfileId(ProfileId, profile); } catch (FormatException formatException) { HttpWebRequest request = formatException.Request; HttpWebResponse response = formatException.Response; HttpStatusCode code = response.StatusCode; Console.WriteLine("Status code: {0}", code); string reasonPhrase = response.StatusDescription; Console.WriteLine("Reason Phrase: {0}", reasonPhrase); string responseContent = formatException.Content; Console.WriteLine("Content : {0}", responseContent); } catch (BadRequestException badRequestException) { HttpWebRequest request = badRequestException.Request; HttpWebResponse response = badRequestException.Response; Error parsedError = badRequestException.Error; string errorCode = parsedError.Code; string message = parsedError.Message; string type = parsedError.Type; Dictionary<string, string[]> description = parsedError.Description; Console.WriteLine(parsedError.ToString()); } }