public void PostProfile_ValidIdAndValidProfile_NoExceptionsThrown() { //Arrange const string ProfileId = "adaSfaqwfasfasdasdfasfasfasd"; const string AccountId = "TestUser1"; 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>(), It.IsAny <IEnumerable <Header> >())) .Returns(string.Empty); //Action NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); client.UpdateByProfileId(ProfileId, profile, AccountId); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny <string>(), It.IsAny <ContentType>(), "POST", It.IsAny <string>(), It.IsAny <IEnumerable <Header> >()), Times.Once); }
public void UpdatePlatformAccount_ValidUsernameAndValidUser_NoExceptionsThrown() { //Arrange const string AccountId = "TestUser1"; PlatformAccountToPost user = new PlatformAccountToPost { Id = "NewTestUser1", FirstName = "NewFirstName", LastName = "NewLastName", Email = "*****@*****.**", CompanyName = "Malibu" }; Mock <IHttpTransport> httpTransportMock = new Mock <IHttpTransport>(MockBehavior.Strict); httpTransportMock.Setup(httpTransport => httpTransport.Request(It.IsAny <string>(), It.IsAny <ContentType>(), "PUT", It.IsAny <string>(), It.IsAny <IEnumerable <Header> >())) .Returns(string.Empty); //Action NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); client.UpdatePlatformAccount(user, AccountId); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny <string>(), It.IsAny <ContentType>(), "PUT", It.IsAny <string>(), It.IsAny <IEnumerable <Header> >()), Times.Once); }
public void GetProfilesByNameAddress_ValidNA_ProfilesReturned() { //Arrange NameAddress nameAddress = new NameAddress { AddressLine = "129 West 81st Street", FirstName = "Jerry", LastName = "Seinfeld", City = "New York", State = "NY" }; const string AccountId = "TestUser1"; 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, It.IsAny <IEnumerable <Header> >())) .Returns(jsonProfiles); //Action NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); string profiles = client.GetByNameAddressJson(nameAddress, AccountId); //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(jsonProfiles, profiles); }
public void GetPlatformStatistics_InvalidPageNumber_ArgumentExceptionThrown() { //Arrange string jsonStats = Properties.Resources.JsonPlatformUser; const int page = -10; 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(jsonStats); NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); try { //Action client.GetPlatformStatistics(page); Assert.Fail("An exception should have been thrown"); } catch (ArgumentException argumentException) { //Assert Assert.AreEqual("page", argumentException.ParamName); } }
public static void Run() { const string Username = ""; const string Password = ""; const bool Sandbox = true; NextCallerPlatformClient client = new NextCallerPlatformClient(Username, Password, Sandbox); const string AccountId = "TestUser1"; try { PlatformAccountToPost user = new PlatformAccountToPost { Id = "NewTestUser1", CompanyName = "new_platform_company1_name", Email = "*****@*****.**", FirstName = "new_platform_user1_fname", LastName = "new_platform_user1_lname" }; client.UpdatePlatformAccount(user, AccountId); } 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; NextCallerPlatformClient client = new NextCallerPlatformClient(Username, Password, Sandbox); const string Phone = "1234567890"; const string AccountId = "TestUser1"; try { FraudLevel fraudLevel = client.GetFraudLevel(Phone, AccountId); //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 NextCallerPlatformClient client = new NextCallerPlatformClient(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 const string AccountId = "TestUser1"; 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 NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); string jsonData = JsonSerializer.Serialize(data); string fraudLevel = client.AnalyzeCallJson(jsonData, AccountId); //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 void GetPlatformStatistics_AllRight_PlatformStatisticsReturned() { //Arrange string jsonStats = Properties.Resources.JsonPlatformUser; 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(jsonStats); //Action NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); string stats = client.GetPlatformStatisticsJson(); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny <string>(), It.IsAny <ContentType>(), It.IsIn("GET", "POST"), null, null), Times.Once); Assert.IsNotNull(stats); Assert.AreEqual(jsonStats, stats); }
public void GetPlatformAccount_ValidUsername_AccountIdReturned() { //Arrange const string AccountId = "TestUser1"; string jsonUser = Properties.Resources.JsonPlatformUser; 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(jsonUser); //Action NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); string user = client.GetPlatformAccountJson(AccountId); //Assert httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny <string>(), It.IsAny <ContentType>(), It.IsIn("GET", "POST"), null, null), Times.Once); Assert.IsNotNull(user); Assert.AreEqual(jsonUser, user); }
public void GetProfileById_ValidId_ProfileReturned() { //Arrange const string AccountId = "TestUser1"; 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, It.IsAny <IEnumerable <Header> >())) .Returns(jsonProfile); //Action NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); string profile = client.GetByProfileIdJson(ProfileId, AccountId); //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(profile); Assert.AreEqual(jsonProfile, profile); }
public void GetFraudLevel_ValidPhone_FraudLevelReturned() { //Arrange const string PhoneNumber = "2020327000"; const string AccountId = "TestUser1"; 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 NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); string fraudLevel = client.GetFraudLevelJson(PhoneNumber, AccountId); //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 GetProfileEmail_ValidEmail_ProfileReturned() { //Arrange const string ValidEmail = "*****@*****.**"; const string AccountId = "TestUser1"; 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 NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); string profiles = client.GetByEmailJson(ValidEmail, AccountId); //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 GetProfileByPhone_EmptyAccountID_ProfilesReturned() { //Arrange const string PhoneNumber = "2020327123"; const string AccountId = ""; 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, It.IsAny <IEnumerable <Header> >())) .Returns(jsonProfiles); //Action NextCallerPlatformClient client = new NextCallerPlatformClient(httpTransportMock.Object); string profiles = client.GetByPhoneJson(PhoneNumber, AccountId); //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(jsonProfiles, profiles); }
public static void Run() { const string Username = ""; const string Password = ""; const bool Sandbox = true; NextCallerPlatformClient client = new NextCallerPlatformClient(Username, Password, Sandbox); const string ProfileId = "profileId"; const string AccountId = "TestUser1"; 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, AccountId); } 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; NextCallerPlatformClient client = new NextCallerPlatformClient(Username, Password, Sandbox); NameAddress nameAddress = new NameAddress { AddressLine = "129 West 81st Street", FirstName = "Jerry", LastName = "Seinfeld", City = "New York", State = "NY" }; const string AccountId = "TestUser1"; try { IList <Profile> profiles = client.GetByNameAddress(nameAddress, AccountId); 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; NextCallerPlatformClient client = new NextCallerPlatformClient(Username, Password, Sandbox); const string AccountId = "TestUser1"; try { PlatformAccount user = client.GetPlatformAccount(AccountId); //user = new PlatformUser //{ // CreatedTime = "20140416T13:42:00", // NumberOfOperations = 24, // ResourceUri = "/api/v2/platform_users/pl2_un1/", // Username = "******", // TotalCalls = new Dictionary<string, int> // { // { "201403", 7 }, // { "201404", 7 }, // { "201405", 7 } // }, // SuccessfulCalls = new Dictionary<string, int> // { // { "201403", 7 }, // { "201404", 7 }, // { "201405", 7 } // }, // BillableCalls = new Dictionary<string, int> // { // { "201403", 7 }, // { "201404", 7 }, // { "201405", 7 } // } //}; } 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; NextCallerPlatformClient client = new NextCallerPlatformClient(Username, Password, Sandbox); const string AccountId = "TestUser1"; 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, AccountId); } 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()); } }