public async void TestSearchWithAllOptions()
        {
            String        accessToken = this.RandomString();
            String        url         = this.RandomString();
            String        teamId      = this.RandomString();
            int           page        = 20;
            List <String> triggerIds  = new List <String> {
                this.RandomString()
            };
            SearchWebhooksRequest req = new SearchWebhooksRequest();

            req.Url        = url;
            req.TriggerIds = triggerIds;
            req.TeamId     = teamId;
            req.Page       = page;
            MockAPI <Webhooks> mock = this.MockFor <Webhooks>(
                HttpMethod.Post,
                "/api/v1/webhooks.search",
                m => m.WithContent(req.ToString()).Respond("application/json", "{\"webhooks\":[{\"webhookId\":\"" + this.RandomString() + "\"}]}")
                );
            APIResponse <WebhooksResponseBody> res = await mock.Instance.Search(accessToken, url, triggerIds, page, teamId);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(1, res.Body.Webhooks.Count());
        }
Exemple #2
0
        public async void TestManageTagsWithTags()
        {
            String        accessToken = this.RandomString();
            List <String> contactIds  = new List <String> {
                this.RandomString()
            };
            List <String> addTagIds = new List <String> {
                this.RandomString()
            };
            List <String> removeTagIds = new List <String> {
                this.RandomString()
            };
            String            teamId = this.RandomString();
            ManageTagsRequest req    = new ManageTagsRequest();

            req.ContactIds   = contactIds;
            req.AddTagIds    = addTagIds;
            req.RemoveTagIds = removeTagIds;
            req.TeamId       = teamId;
            MockAPI <Contacts> mock = this.MockFor <Contacts>(
                HttpMethod.Post,
                "/api/v1/contacts.manageTags",
                m => m.WithContent(req.ToString())
                .Respond("application/json", req.ToString())
                );

            APIResponse <dynamic> res = await mock.Instance.ManageTags(accessToken, contactIds, addTagIds, removeTagIds, teamId);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(System.Net.HttpStatusCode.OK, res.Status);
        }
Exemple #3
0
        public async void TestUpdateWithTeam()
        {
            String accessToken = this.RandomString();
            String teamId      = this.RandomString();

            Models.Contact contact = new Models.Contact();
            contact.ContactData                 = new Models.ContactData();
            contact.ContactId                   = this.RandomString();
            contact.ContactData.Name            = new Models.Fields.Name();
            contact.ContactData.Name.FamilyName = this.RandomString();
            UpdateContactRequest req = new UpdateContactRequest();

            req.Contact = contact;
            req.TeamId  = teamId;
            MockAPI <Contacts> mock = this.MockFor <Contacts>(
                HttpMethod.Post,
                "/api/v1/contacts.update",
                m => m.WithContent(req.ToString())
                .Respond("application/json", req.ToString())
                );

            APIResponse <ContactResponseBody> res = await mock.Instance.Update(accessToken, contact, teamId);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(contact.ContactId, res.Body.Contact.ContactId);
        }
        public async void TestUpdateWithTeam()
        {
            String accessToken = this.RandomString();
            String teamId      = this.RandomString();

            Models.Tag tag = new Models.Tag();
            tag.TagId        = this.RandomString();
            tag.TagData      = new Models.TagData();
            tag.TagData.Name = this.RandomString();
            UpdateTagRequest req = new UpdateTagRequest();

            req.Tag    = tag;
            req.TeamId = teamId;
            MockAPI <Tags> mock = this.MockFor <Tags>(
                HttpMethod.Post,
                "/api/v1/tags.update",
                m => m.WithContent(req.ToString())
                .Respond("application/json", req.ToString())
                );

            APIResponse <TagResponseBody> res = await mock.Instance.Update(accessToken, tag, teamId);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(tag.TagId, res.Body.Tag.TagId);
        }
Exemple #5
0
        public async void TestGet()
        {
            String          accessToken = this.RandomString();
            String          teamId      = this.RandomString();
            MockAPI <Teams> mock        = this.MockFor <Teams>(
                HttpMethod.Post,
                "/api/v1/teams.get",
                m => m.WithContent("{}").Respond("application/json", "{ \"teams\": [{\"teamId\":\"" + teamId + "\"}]}")
                );
            APIResponse <TeamsResponseBody> res = await mock.Instance.Get(accessToken);

            Assert.Equal(res.Body.Teams.First().TeamId, teamId);
            mock.Handler.VerifyNoOutstandingExpectation();
        }
        public async void TestGet()
        {
            String            accessToken = this.RandomString();
            String            accountId   = this.RandomString();
            MockAPI <Account> mock        = this.MockFor <Account>(
                HttpMethod.Post,
                "/api/v1/account.get",
                m => m.WithContent("{}").Respond("application/json", "{ \"account\": { \"accountId\": \"" + accountId + "\"}}")
                );
            APIResponse <AccountResponseBody> res = await mock.Instance.Get(accessToken);

            Assert.Equal(res.Body.Account.AccountId, accountId);
            mock.Handler.VerifyNoOutstandingExpectation();
        }
        public async void TestGetTriggers()
        {
            String             accessToken = this.RandomString();
            String             trigger     = this.RandomString();
            MockAPI <Webhooks> mock        = this.MockFor <Webhooks>(
                HttpMethod.Post,
                "/api/v1/webhooks.getTriggers",
                m => m.WithContent("{}").Respond("application/json", "{ \"triggers\": [\"" + trigger + "\"]}")
                );
            APIResponse <TriggersResponseBody> res = await mock.Instance.GetTriggers(accessToken);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(trigger, res.Body.Triggers.First());
        }
        public async void TestScroll()
        {
            String            accessToken = this.RandomString();
            ScrollTagsRequest req         = new ScrollTagsRequest();
            MockAPI <Tags>    mock        = this.MockFor <Tags>(
                HttpMethod.Post,
                "/api/v1/tags.scroll",
                m => m.WithContent(req.ToString())
                .Respond("application/json", "{ \"tags\": [{\"tagId\":\"" + this.RandomString() + "\"}]}")
                );

            APIResponse <TagsResponseBody> res = await mock.Instance.Scroll(accessToken, null);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(res.Body.Tags.Count, 1);
        }
        public async void TestDelete()
        {
            String accessToken       = this.RandomString();
            String webhookId         = this.RandomString();
            DeleteWebhookRequest req = new DeleteWebhookRequest();

            req.WebhookId = webhookId;
            MockAPI <Webhooks> mock = this.MockFor <Webhooks>(
                HttpMethod.Post,
                "/api/v1/webhooks.delete",
                m => m.WithContent(req.ToString()).Respond("application/json", "{}")
                );
            APIResponse <dynamic> res = await mock.Instance.Delete(accessToken, webhookId, null);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(System.Net.HttpStatusCode.OK, res.Status);
        }
Exemple #10
0
        public async void TestSearch()
        {
            String accessToken        = this.RandomString();
            String query              = this.RandomString();
            SearchContactsRequest req = new SearchContactsRequest();

            req.SearchQuery = query;
            MockAPI <Contacts> mock = this.MockFor <Contacts>(
                HttpMethod.Post,
                "/api/v1/contacts.search",
                m => m.WithContent(req.ToString())
                .Respond("application/json", "{ \"contacts\": [{\"contactId\":\"" + this.RandomString() + "\"}]}")
                );

            APIResponse <ContactsResponseBody> res = await mock.Instance.Search(accessToken, query, null);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(res.Body.Contacts.Count, 1);
        }
        public async void TestGet()
        {
            String        accessToken = this.RandomString();
            String        webhookId   = this.RandomString();
            List <String> webhookIds  = new List <String> {
                webhookId
            };
            GetWebhooksRequest req = new GetWebhooksRequest();

            req.WebhookIds = webhookIds;
            MockAPI <Webhooks> mock = this.MockFor <Webhooks>(
                HttpMethod.Post,
                "/api/v1/webhooks.get",
                m => m.WithContent(req.ToString()).Respond("application/json", "{\"webhooks\":[{\"webhookId\":\"" + webhookId + "\"}]}")
                );
            APIResponse <WebhooksResponseBody> res = await mock.Instance.Get(accessToken, webhookIds, null, null);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(res.Body.Webhooks.First().WebhookId, webhookId);
        }
Exemple #12
0
        public async void TestDelete()
        {
            String accessToken       = this.RandomString();
            String etag              = this.RandomString();
            String contactId         = this.RandomString();
            DeleteContactRequest req = new DeleteContactRequest();

            req.ContactId = contactId;
            req.Etag      = etag;
            MockAPI <Contacts> mock = this.MockFor <Contacts>(
                HttpMethod.Post,
                "/api/v1/contacts.delete",
                m => m.WithContent(req.ToString())
                .Respond("application/json", req.ToString())
                );

            APIResponse <dynamic> res = await mock.Instance.Delete(accessToken, contactId, etag, null);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(System.Net.HttpStatusCode.OK, res.Status);
        }
        public async void TestGetBatchesWithTeam()
        {
            String accessToken           = this.RandomString();
            String webhookId             = this.RandomString();
            String batchId               = this.RandomString();
            String teamId                = this.RandomString();
            GetWebhookBatchesRequest req = new GetWebhookBatchesRequest();

            req.WebhookId = webhookId;
            req.BatchId   = batchId;
            req.TeamId    = teamId;
            MockAPI <Webhooks> mock = this.MockFor <Webhooks>(
                HttpMethod.Post,
                "/api/v1/webhooks.getBatches",
                m => m.WithContent(req.ToString()).Respond("application/json", "{}")
                );
            APIResponse <dynamic> res = await mock.Instance.GetBatches(accessToken, webhookId, batchId, teamId);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(System.Net.HttpStatusCode.OK, res.Status);
        }
        public async void TestCreate()
        {
            String        accessToken = this.RandomString();
            String        url         = this.RandomString();
            List <String> triggerIds  = new List <String> {
                this.RandomString()
            };
            CreateWebhookRequest req = new CreateWebhookRequest();

            req.TriggerIds = triggerIds;
            req.Url        = url;
            MockAPI <Webhooks> mock = this.MockFor <Webhooks>(
                HttpMethod.Post,
                "/api/v1/webhooks.create",
                m => m.WithContent(req.ToString()).Respond("application/json", "{\"webhook\":{\"webhookId\":\"" + this.RandomString() + "\"}}")
                );
            APIResponse <WebhookResponseBody> res = await mock.Instance.Create(accessToken, url, triggerIds, null);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.NotNull(res.Body.Webhook);
        }
Exemple #15
0
        public async void TestScrollWithCursor()
        {
            String accessToken        = this.RandomString();
            String teamId             = this.RandomString();
            String cursor             = this.RandomString();
            ScrollContactsRequest req = new ScrollContactsRequest();

            req.TeamId       = teamId;
            req.ScrollCursor = cursor;
            MockAPI <Contacts> mock = this.MockFor <Contacts>(
                HttpMethod.Post,
                "/api/v1/contacts.scroll",
                m => m.WithContent(req.ToString())
                .Respond("application/json", "{ \"contacts\": [{\"contactId\":\"" + this.RandomString() + "\"}]}")
                );

            APIResponse <ContactsResponseBody> res = await mock.Instance.Scroll(accessToken, cursor, teamId);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(res.Body.Contacts.Count, 1);
        }
        public async void TestGet()
        {
            String        accessToken = this.RandomString();
            String        tagId       = this.RandomString();
            List <String> tagIds      = new List <String> {
                tagId
            };
            GetTagsRequest req = new GetTagsRequest();

            req.TagIds = tagIds;
            MockAPI <Tags> mock = this.MockFor <Tags>(
                HttpMethod.Post,
                "/api/v1/tags.get",
                m => m.WithContent(req.ToString())
                .Respond("application/json", "{ \"tags\": [{\"tagId\":\"" + tagId + "\"}]}")
                );
            APIResponse <TagsResponseBody> res = await mock.Instance.Get(accessToken, tagIds, null);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(res.Body.Tags.Count, 1);
        }
Exemple #17
0
        public async void TestCreate()
        {
            String accessToken = this.RandomString();

            Models.Contact contact = new Models.Contact();
            contact.ContactData       = new Models.ContactData();
            contact.ContactData.Notes = this.RandomString();
            CreateContactRequest req = new CreateContactRequest();

            req.Contact = contact;
            MockAPI <Contacts> mock = this.MockFor <Contacts>(
                HttpMethod.Post,
                "/api/v1/contacts.create",
                m => m.WithContent(req.ToString())
                .Respond("application/json", req.ToString())
                );

            APIResponse <ContactResponseBody> res = await mock.Instance.Create(accessToken, contact, null);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(contact.ContactData.Notes, res.Body.Contact.ContactData.Notes);
        }
        protected MockAPI <T> MockFor <T>(HttpMethod method, String uri, Func <MockedRequest, MockedRequest> action) where T : API
        {
            MockHttpMessageHandler      mockHandler = new MockHttpMessageHandler();
            Dictionary <String, Object> config      = new Dictionary <String, Object>();

            config.Add("apiUrl", this.baseUrl);
            config.Add("clientId", this.clientId);
            config.Add("clientSecret", this.clientSecret);
            this.output.WriteLine(String.Format("{0}{1}", this.baseUrl, uri));
            MockedRequest req = mockHandler.Expect(method, String.Format("{0}{1}", this.baseUrl, uri));

            if (action != null)
            {
                req = action.Invoke(req);
            }

            MockAPI <T> mock = new MockAPI <T>();

            mock.Request  = req;
            mock.Instance = (T)Activator.CreateInstance(typeof(T), new object[] { config, mockHandler.ToHttpClient() });
            mock.Handler  = mockHandler;
            return(mock);
        }
Exemple #19
0
        public async void TestGetWithTeam()
        {
            String        accessToken = this.RandomString();
            String        contactId   = this.RandomString();
            String        teamId      = this.RandomString();
            List <String> contactIds  = new List <String> {
                contactId
            };
            GetContactsRequest req = new GetContactsRequest();

            req.ContactIds = contactIds;
            req.TeamId     = teamId;
            MockAPI <Contacts> mock = this.MockFor <Contacts>(
                HttpMethod.Post,
                "/api/v1/contacts.get",
                m => m.WithContent(req.ToString())
                .Respond("application/json", "{ \"contacts\": [{\"contactId\":\"" + contactId + "\"}]}")
                );
            APIResponse <ContactsResponseBody> res = await mock.Instance.Get(accessToken, contactIds, teamId);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(res.Body.Contacts.Count, 1);
        }
        public async void TestScrollWithAllOptions()
        {
            String            accessToken = this.RandomString();
            String            teamId      = this.RandomString();
            String            cursor      = this.RandomString();
            int               size        = 20;
            ScrollTagsRequest req         = new ScrollTagsRequest();

            req.TeamId             = teamId;
            req.ScrollCursor       = cursor;
            req.Size               = size;
            req.IncludeDeletedTags = true;
            MockAPI <Tags> mock = this.MockFor <Tags>(
                HttpMethod.Post,
                "/api/v1/tags.scroll",
                m => m.WithContent(req.ToString())
                .Respond("application/json", "{ \"tags\": [{\"tagId\":\"" + this.RandomString() + "\"}]}")
                );

            APIResponse <TagsResponseBody> res = await mock.Instance.Scroll(accessToken, cursor, true, teamId, size);

            mock.Handler.VerifyNoOutstandingExpectation();
            Assert.Equal(res.Body.Tags.Count, 1);
        }