コード例 #1
0
        public void CreatePlatformAccount_ValidUsernameAndValidUser_NoExceptionsThrown()
        {
            //Arrange
            PlatformAccountToPost user = new PlatformAccountToPost
            {
                Id          = "TestUser1",
                FirstName   = "FirstName",
                LastName    = "LastName",
                Email       = "*****@*****.**",
                CompanyName = "Malibu"
            };

            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.CreatePlatformAccount(user);

            //Assert
            httpTransportMock.Verify(httpTransport => httpTransport.Request(It.IsAny <string>(), It.IsAny <ContentType>(), "POST", It.IsAny <string>(), It.IsAny <IEnumerable <Header> >()), Times.Once);
        }
        public static void Run()
        {
            const string Username = "";
            const string Password = "";
            const bool   Sandbox  = true;

            NextCallerPlatformClient client = new NextCallerPlatformClient(Username, Password, Sandbox);

            try
            {
                PlatformAccountToPost user = new PlatformAccountToPost
                {
                    Id          = "TestUser1",
                    CompanyName = "platform_company1_name",
                    Email       = "*****@*****.**",
                    FirstName   = "platform_user1_fname",
                    LastName    = "platform_user1_lname"
                };

                client.CreatePlatformAccount(user);
            }
            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());
            }
        }