Esempio n. 1
0
        public Contact UpdateContact(string id, ContactOptionalArguments optionalArguments)
        {
            ParameterValidator.IsNotNullOrWhiteSpace(id, "id");

            var customDetails = new ContactCustomDetails
            {
                Custom1 = optionalArguments.Custom1,
                Custom2 = optionalArguments.Custom2,
                Custom3 = optionalArguments.Custom3,
                Custom4 = optionalArguments.Custom4,
            };

            var contacts = new Contacts(new Contact
            {
                Id            = id,
                FirstName     = optionalArguments.FirstName,
                LastName      = optionalArguments.LastName,
                CustomDetails = customDetails,
            });

            RestClientOptions.UpdateMode = UpdateMode.Patch;
            restClient.Update(contacts);

            return(contacts.Object as Contact);
        }
Esempio n. 2
0
        public void Update()
        {
            var restClient = MockRestClient
                             .ThatExpects("{\"lastName\":\"SomeName\",\"custom4\":\"Fourth\"}")
                             .AndReturns("{\"id\": \"id\",\"href\": \"https://rest.messagebird.com/contacts/id\",\"msisdn\": 31687654321,\"firstName\": \"Foo\",\"lastName\": \"SomeName\",\"customDetails\": {\"custom1\": \"First\",\"custom2\": \"Second\",\"custom3\": null,\"custom4\": \"Fourth\"},\"groups\": {\"totalCount\": 0,\"href\": \"https://rest.messagebird.com/contacts/id/groups\"},\"messages\": {\"totalCount\": 0,\"href\": \"https://rest.messagebird.com/contacts/id/messages\"},\"createdDatetime\": \"2018-08-10T13:58:00+00:00\",\"updatedDatetime\": \"2018-08-10T13:58:00+00:00\"}")
                             .FromEndpoint("PATCH", "contacts/some-id")
                             .Get();
            var client = Client.Create(restClient.Object);

            var optionalArguments = new ContactOptionalArguments
            {
                LastName = "SomeName",
                Custom4  = "Fourth",
            };
            var contact = client.UpdateContact("some-id", optionalArguments);

            restClient.Verify();

            Assert.AreEqual(31687654321L, contact.Msisdn);
            Assert.AreEqual("SomeName", contact.LastName);
            Assert.AreEqual("Fourth", contact.CustomDetails.Custom4);
        }
        public Contact CreateContact(long msisdn, ContactOptionalArguments optionalArguments = null)
        {
            var contact = new Contact {
                Msisdn = msisdn
            };

            if (optionalArguments != null)
            {
                contact.FirstName     = optionalArguments.FirstName;
                contact.LastName      = optionalArguments.LastName;
                contact.CustomDetails = new ContactCustomDetails
                {
                    Custom1 = optionalArguments.Custom1,
                    Custom2 = optionalArguments.Custom2,
                    Custom3 = optionalArguments.Custom3,
                    Custom4 = optionalArguments.Custom4,
                };
            }

            var result = restClient.Create(new Contacts(contact));

            return(result.Object as Contact);
        }
Esempio n. 4
0
        public void Create()
        {
            var restClient = MockRestClient
                             .ThatExpects("{\"msisdn\":31612345678,\"firstName\":\"Foo\",\"lastName\":\"Bar\",\"custom1\":\"First\",\"custom2\":\"Second\"}")
                             .AndReturns("{\"id\": \"id\",\"href\": \"https://rest.messagebird.com/contacts/id\",\"msisdn\": 31612345678,\"firstName\": \"Foo\",\"lastName\": \"Bar\",\"customDetails\": {\"custom1\": \"First\",\"custom2\": \"Second\",\"custom3\": null,\"custom4\": null},\"groups\": {\"totalCount\": 0,\"href\": \"https://rest.messagebird.com/contacts/id/groups\"},\"messages\": {\"totalCount\": 0,\"href\": \"https://rest.messagebird.com/contacts/id/messages\"},\"createdDatetime\": \"2018-08-10T13:58:00+00:00\",\"updatedDatetime\": \"2018-08-10T13:58:00+00:00\"}")
                             .FromEndpoint("POST", "contacts")
                             .Get();
            var client = Client.Create(restClient.Object);

            var optionalArguments = new ContactOptionalArguments
            {
                FirstName = "Foo",
                LastName  = "Bar",
                Custom1   = "First",
                Custom2   = "Second",
            };
            var contact = client.CreateContact(31612345678L, optionalArguments);

            restClient.Verify();

            Assert.AreEqual(31612345678L, contact.Msisdn);
            Assert.AreEqual("Second", contact.CustomDetails.Custom2);
        }