Exemplo n.º 1
0
        public override async Task <DepartementResponse> GetDepartementById(GetByIdRequest request, ServerCallContext context)
        {
            var result = await _mediator.Send(new GetDepartementByIdQuery
            {
                Id = request.Id
            });

            var departementResponse = new DepartementResponse
            {
                Id       = result.Id,
                Name     = result.Name,
                Location = result.Location,
            };

            departementResponse.Employees.AddRange(
                result.Employees.Select(
                    x => new DepartementEmployeeResponse
            {
                Id        = x.Id,
                FirstName = x.FirstName,
                LastName  = x.LastName,
                JoinDate  = Timestamp.FromDateTime(x.JoinDate.ToUniversalTime())
            }));

            return(departementResponse);
        }
Exemplo n.º 2
0
        public async void GetByIdHandler_Should_Work(string id, bool expected)
        {
            // Given
            IMediator mediator = ServiceProvider.GetService <IMediator>();

            MockEventPublisher   publisher  = new MockEventPublisher(mediator);
            MockSampleRepository repository = new MockSampleRepository(
                new Dictionary <string, Domain.Sample.Sample>
            {
                { "1", new Domain.Sample.Sample("1", "1") }
            });
            Mock <ILogger <GetByIdRequest> > logger = new Mock <ILogger <GetByIdRequest> >();

            GetByIdHandler handler = new GetByIdHandler(repository, publisher, logger.Object);

            GetByIdRequest command = new GetByIdRequest(id);

            // When
            Result result = await handler.Handle(command, new CancellationToken());

            // Then
            List <ValidationResult> notValidNotifications =
                result.Notifications.Where(notification => !notification.IsValid).ToList();

            if (expected)
            {
                Assert.Empty(notValidNotifications);
            }
            else
            {
                Assert.NotEmpty(notValidNotifications);
            }
        }
Exemplo n.º 3
0
 public ResponseMessageWraper <User> GetById([FromBody] GetByIdRequest reqMsg)
 {
     return(new ResponseMessageWraper <User>
     {
         Body = _userRepository.GetById(reqMsg.Id)
     });
 }
Exemplo n.º 4
0
        public async Task <IActionResult> GetApplicationById(int id)
        {
            var request  = new GetByIdRequest(id);
            var response = await _mediator.Send(request);

            return(Ok(response));
        }
Exemplo n.º 5
0
 public override async Task <GetByIdResponse> GetById(GetByIdRequest request, ServerCallContext context)
 {
     return(new GetByIdResponse
     {
         Episode = await _episodeProvider.GetEpisodeById(request.Id)
     });
 }
Exemplo n.º 6
0
        public async Task <ActionResult <ApplicationStudentDTO> > GetApplicationStudent(int id, CancellationToken ct)
        {
            var request  = new GetByIdRequest(id);
            var response = await _mediator.Send(request);

            return(response);
        }
        /// <summary>
        /// Find all entries in a given contact list. Property <b>request.id</b> required
        /// </summary>
        /// Property <b>request.id</b> required
        /// <param name="request">request object with properties to filter</param>
        /// <returns>paged list with contact objects from contact list</returns>
        /// <exception cref="BadRequestException">          in case HTTP response code is 400 - Bad request, the request was formatted improperly.</exception>
        /// <exception cref="UnauthorizedException">        in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.</exception>
        /// <exception cref="AccessForbiddenException">     in case HTTP response code is 403 - Forbidden, insufficient permissions.</exception>
        /// <exception cref="ResourceNotFoundException">    in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.</exception>
        /// <exception cref="InternalServerErrorException"> in case HTTP response code is 500 - Internal Server Error.</exception>
        /// <exception cref="CallfireApiException">         in case HTTP response code is something different from codes listed above.</exception>
        /// <exception cref="CallfireClientException">      in case error has occurred in client.</exception>
        public Page <Contact> GetListItems(GetByIdRequest request)
        {
            Validate.NotBlank(request.Id.ToString(), "request.id cannot be null");
            string path = LISTS_ITEMS_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.Id.ToString());

            return(Client.Get <Page <Contact> >(path, request));
        }
 public GetResponse Get(GetByIdRequest request)
 {
     return(new GetResponse
     {
         User = Map(_userGateway.Load(request.UserId))
     });
 }
Exemplo n.º 9
0
        public void GetBroadcastTexts()
        {
            var broadcast = new TextBroadcast
            {
                Name       = "text_broadcast_1",
                Message    = "test_msg",
                Recipients = new List <TextRecipient>
                {
                    new TextRecipient {
                        PhoneNumber = "14246525473"
                    }
                }
            };
            var broadcastId = Client.TextBroadcastsApi.Create(broadcast, false);

            var request = new GetByIdRequest {
                Id = broadcastId.Id
            };
            var texts = Client.TextBroadcastsApi.GetTexts(request);

            Console.WriteLine(texts);
            Assert.That(texts.Items, Is.Not.Empty);

            long testBatchId = (long)texts.Items[0].BatchId;

            request = new GetBroadcastCallsTextsRequest {
                Id = broadcastId.Id, BatchId = testBatchId
            };
            texts = Client.TextBroadcastsApi.GetTexts(request);
            Assert.AreEqual(texts.Items[0].BatchId, testBatchId);
        }
Exemplo n.º 10
0
        public async Task <UserSelectDto> Handle(GetByIdRequest id, CancellationToken cancellationToken)
        {
            var user = await _userRepository.TableNoTracking.ProjectTo <UserSelectDto>(_mapper.ConfigurationProvider)
                       .SingleOrDefaultAsync(p => p.Id.Equals(id.Id), cancellationToken);

            return(user);
        }
Exemplo n.º 11
0
        public override Task <GetJsonSerializedResponse> GetPartById(GetByIdRequest request, ServerCallContext context)
        {
            string json  = "";
            string error = "";

            try
            {
                List <Type> tl = new List <Type> {
                    typeof(NWiredWirelesspart), typeof(NWiredPart), typeof(NWirelesspart)
                };
                List <NPart> res = DB.DBExecuter.SQLRequestSPAutoFillParams(
                    "sp_GetPartById",
                    new DB.ParamList {
                    ["Id"] = request.Id
                }
                    ).MapHierarchy <NPart>(tl, "ClassName");
                json = utils.SerializeJsonWithTypes(res);
            }
            catch (Exception e)
            {
                error = e.GetBaseException().Message;
            }
            return(Task.FromResult(new GetJsonSerializedResponse
            {
                Response = json,
                ErrorMessage = error
            }));
        }
Exemplo n.º 12
0
    public void RequestQRhash(int eventId)
    {
        //TODO
        GetByIdRequest request = new GetByIdRequest(eventId, GetByIdRequest.GetById.QR);

        Links.TcpClient.SendData(request.Serialize());
    }
Exemplo n.º 13
0
        public override async Task <SuccessReply> DeleteDepartement(GetByIdRequest request, ServerCallContext context)
        {
            var result = await _mediator.Send(new DeleteDepartementCommand { Id = request.Id });

            return(new SuccessReply {
                Success = result.Success, Reason = result.Reason
            });
        }
Exemplo n.º 14
0
    public void RequestPlayerEvents()
    {
        //Все на что зареган пользователь
        GetByIdRequest request = new GetByIdRequest(Links.DeviceInformation.PlayerData.Id,
                                                    GetByIdRequest.GetById.RegisteredEvents);

        Links.TcpClient.SendData(request.Serialize());
    }
        public void GetContactHistory()
        {
            var request = new GetByIdRequest { Id = 1, Limit = 5 };
            var contactHistory = Client.ContactsApi.GetHistory(request);
            Assert.AreEqual(2, contactHistory.Calls.Count);

            Console.WriteLine("ContactHistory:" + contactHistory);
        }
        public override Task <GetByIdResponse> GetById(GetByIdRequest request, ServerCallContext context)
        {
            var superhero = _superheroesRepository.GetById(request.Id);

            return(Task.FromResult(new GetByIdResponse
            {
                Superhero = _mapper.Map <Superhero>(superhero)
            }));
        }
Exemplo n.º 17
0
        public override async Task <GetByIdResponse> GetById(GetByIdRequest request, ServerCallContext context)
        {
            var series = await _seriesProvider.GetSeriesById(request.Id);

            return(new GetByIdResponse
            {
                Series = series,
            });
        }
        public void AddRecipientsAndAddRemoveBatches()
        {
            var findRequest = new FindBroadcastsRequest
            {
                Name  = "updated_name",
                Limit = 1
            };
            var broadcasts = Client.CallBroadcastsApi.Find(findRequest);

            Console.WriteLine(broadcasts);
            Assert.That(broadcasts.Items, Is.Not.Empty);
            var id = broadcasts.Items[0].Id;

            var calls = Client.CallBroadcastsApi.AddRecipients((long)id, new List <Recipient>
            {
                new Recipient {
                    PhoneNumber = "12132212384"
                },
                new Recipient {
                    PhoneNumber = "12132212385"
                }
            });

            Console.WriteLine(calls);
            Assert.AreEqual(2, calls.Count);

            // get batches
            var getBatchesRequest = new GetByIdRequest {
                Id = id
            };
            var batches = Client.CallBroadcastsApi.GetBatches(getBatchesRequest);

            Console.WriteLine(batches);

            // add batch
            var addBatchRequest = new AddBatchRequest
            {
                CampaignId = (long)id,
                Name       = "new_batch",
                Recipients = new List <Recipient>
                {
                    new Recipient {
                        PhoneNumber = "12132212384"
                    },
                    new Recipient {
                        PhoneNumber = "12132212384"
                    }
                }
            };

            Client.CallBroadcastsApi.AddBatch(addBatchRequest);

            var updatedBatches = Client.CallBroadcastsApi.GetBatches(getBatchesRequest);

            Console.WriteLine(batches);
            Assert.AreEqual(batches.Items.Count + 1, updatedBatches.Items.Count);
        }
Exemplo n.º 19
0
        public void ToggleRecipientsStatus()
        {
            var broadcast = new TextBroadcast
            {
                Name = "text_broadcast",
                BigMessageStrategy = BigMessageStrategy.SEND_MULTIPLE,
                Message            = "test_msg",
                Recipients         = new List <TextRecipient>
                {
                    new TextRecipient {
                        PhoneNumber = "12132212384"
                    },
                    new TextRecipient {
                        PhoneNumber = "12132212385"
                    }
                }
            };
            var id = Client.TextBroadcastsApi.Create(broadcast, false, false);

            var getTextsRequest = new GetByIdRequest {
                Id = id.Id
            };
            var texts = Client.TextBroadcastsApi.GetTexts(getTextsRequest);

            Assert.That(texts.Items, Is.Not.Empty);
            foreach (Text c in texts.Items)
            {
                Assert.AreEqual(StateType.READY, c.State);
            }

            var recipients = new List <Recipient>
            {
                new Recipient {
                    PhoneNumber = "12132212384"
                },
                new Recipient {
                    PhoneNumber = "12132212385"
                }
            };

            Client.TextBroadcastsApi.ToggleRecipientsStatus(id.Id, recipients, false);

            texts = Client.TextBroadcastsApi.GetTexts(getTextsRequest);
            foreach (Text c in texts.Items)
            {
                Assert.AreEqual(StateType.DISABLED, c.State);
            }

            Client.TextBroadcastsApi.ToggleRecipientsStatus(id.Id, recipients, true);

            texts = Client.TextBroadcastsApi.GetTexts(getTextsRequest);
            foreach (Text c in texts.Items)
            {
                Assert.AreEqual(StateType.READY, c.State);
            }
        }
        public void AddRecipientsAndAddRemoveBatches()
        {
            var findRequest = new FindBroadcastsRequest
            {
                Name  = "updated_name",
                Limit = 1
            };
            var broadcasts = Client.CallBroadcastsApi.Find(findRequest);

            System.Console.WriteLine(broadcasts);
            Assert.That(broadcasts.Items, Is.Not.Empty);
            var id = broadcasts.Items[0].Id;

            var calls = Client.CallBroadcastsApi.AddRecipients((long)id, new List <Recipient>
            {
                new Recipient {
                    PhoneNumber = "12132212384"
                },
                new Recipient {
                    PhoneNumber = "12132212385"
                }
            }, null, true);

            System.Console.WriteLine(calls);
            Assert.AreEqual(2, calls.Count);

            // get batches
            var getBatchesRequest = new GetByIdRequest {
                Id = id
            };
            var batches = Client.CallBroadcastsApi.GetBatches(getBatchesRequest);

            System.Console.WriteLine(batches);

            // add batch
            var addBatchRequest = new AddBatchRequest
            {
                CampaignId = (long)id,
                Name       = "new_batch",
                Recipients = new List <Recipient>
                {
                    new Recipient {
                        PhoneNumber = "12132212386"
                    },
                    new Recipient {
                        PhoneNumber = "12132212387"
                    }
                },
                StrictValidation = true
            };
            ResourceId addedBatchId = Client.CallBroadcastsApi.AddBatch(addBatchRequest);

            var addedBatch = Client.BatchesApi.Get(addedBatchId.Id);

            Assert.AreEqual(addedBatch.BroadcastId, id);
        }
        public async Task Handle_GenericGetByIdRequest_GetsUser()
        {
            var request  = new GetByIdRequest <User, UserGetDto>(_user.Id);
            var response = await Mediator.HandleAsync(request);

            Assert.IsFalse(response.HasErrors);
            Assert.IsNotNull(response.Data);
            Assert.AreEqual(_user.Id, response.Data.Id);
            Assert.AreEqual(_user.Name, response.Data.Name);
        }
        public void GetContactHistory()
        {
            var request = new GetByIdRequest {
                Id = 1, Limit = 5
            };
            var contactHistory = Client.ContactsApi.GetHistory(request);

            Assert.AreEqual(2, contactHistory.Calls.Count);

            Console.WriteLine("ContactHistory:" + contactHistory);
        }
Exemplo n.º 23
0
 public static void Main(string[] args)
 {
     var client  = new CallfireClient("api_login", "api_password");
     var request = new GetByIdRequest
     {
         Id     = 379506003,
         Offset = 0,
         Limit  = 10,
         Fields = "items(firstName,lastName,workPhone)"
     };
     Page <Contact> contacts = client.ContactListsApi.GetListItems(request);
 }
Exemplo n.º 24
0
 public static void Main(string[] args)
 {
     var client  = new CallfireClient("api_login", "api_password");
     var request = new GetByIdRequest
     {
         Id     = 5500030002,
         Offset = 0,
         Limit  = 10,
         Fields = "items(fromNumber,toNumber,state,message)"
     };
     var texts = client.TextBroadcastsApi.GetTexts(request);
 }
Exemplo n.º 25
0
        public override Task <Employee> GetById(GetByIdRequest request, ServerCallContext context)
        {
            var employee = InMemoryData.Employees
                           .FirstOrDefault(e => e.Id == request.Id);

            if (employee != null)
            {
                return(Task.FromResult(employee));
            }

            throw new Exception($"Employee not found: {request.Id}");
        }
 public static void Main(string[] args)
 {
     var client  = new CallfireClient("api_login", "api_password");
     var request = new GetByIdRequest
     {
         Id     = 11646003,
         Offset = 0,
         Limit  = 10,
         Fields = "items(name,status,size,remaining)"
     };
     var batches = client.CallBroadcastsApi.GetBatches(request);
 }
        public void TestContactListItemsCRUD()
        {
            Contact c1 = new Contact {
                FirstName = "name1", HomePhone = "12345678901"
            };
            Contact c2 = new Contact {
                FirstName = "name2", HomePhone = "12345678902"
            };
            CreateContactListRequest <Contact> request = new CreateContactListRequest <Contact>
            {
                Contacts = new List <Contact> {
                    c1, c2
                },
                Name            = "listFromContacts",
                UseCustomFields = true
            };
            ResourceId id = Client.ContactListsApi.Create(request);

            AddContactListContactsRequest <string> addItemsRequest = new AddContactListContactsRequest <string>
            {
                ContactListId = id.Id,
                Contacts      = new List <string> {
                    "12345543211"
                },
                UseCustomFields = true
            };

            Client.ContactListsApi.AddListItems(addItemsRequest);

            GetByIdRequest getItemsRequest = new GetByIdRequest {
                Id = id.Id
            };
            Page <Contact>  contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            IList <Contact> items            = contactListItems.Items;

            Assert.AreEqual(3, items.Count);

            Client.ContactListsApi.RemoveListItem(id.Id, (long)items[0].Id);
            System.Threading.Thread.Sleep(5000);
            contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            items            = contactListItems.Items;
            Assert.AreEqual(2, items.Count);

            Client.ContactListsApi.RemoveListItems(id.Id, new List <long> {
                (long)items[0].Id, (long)items[1].Id
            });
            System.Threading.Thread.Sleep(5000);
            contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            Assert.True(contactListItems.Items.Count == 0);
            Assert.AreEqual(0, contactListItems.TotalCount);

            Client.ContactListsApi.Delete(id.Id);
        }
Exemplo n.º 28
0
 public static void Main(string[] args)
 {
     var client  = new CallfireClient("api_login", "api_password");
     var request = new GetByIdRequest
     {
         Id     = 379506003,
         Offset = 0,
         Limit  = 10,
         Fields = "calls/fromNumber,calls/toNumber,texts/message"
     };
     ContactHistory contactHistory = client.ContactsApi.GetHistory(request);
 }
        public void AddRecipientsAndAddRemoveBatches()
        {
            var findRequest = new FindBroadcastsRequest
            {
                Name = "updated_name",
                Limit = 1
            };
            var broadcasts = Client.TextBroadcastsApi.Find(findRequest);
            Console.WriteLine(broadcasts);
            Assert.That(broadcasts.Items, Is.Not.Empty);
            var id = broadcasts.Items[0].Id;

            // add recipients
            var recipients = new List<TextRecipient>
            {
                new TextRecipient { PhoneNumber = "14246525473" },
                new TextRecipient { PhoneNumber = "12132041238" }
            };
            var texts = Client.TextBroadcastsApi.AddRecipients((long)id, recipients);
            Console.WriteLine(texts);
            Assert.AreEqual(2, texts.Count);
            Assert.That(texts[0].Message, Is.StringStarting("test_msg"));

            // get batches
            var getBatchesRequest = new GetByIdRequest { Id = id };
            var batches = Client.TextBroadcastsApi.GetBatches(getBatchesRequest);
            Console.WriteLine(batches);

            // add batch
            var addBatchRequest = new AddBatchRequest
            {
                CampaignId = (long)id,
                Name = "new_batch",
                Recipients = new List<Recipient>
                {
                    new TextRecipient { PhoneNumber = "14246525473" },
                    new TextRecipient { PhoneNumber = "12132041238" }
                }
            };
            ResourceId addedBatchId = Client.TextBroadcastsApi.AddBatch(addBatchRequest);

            var addedBatch = Client.BatchesApi.Get(addedBatchId.Id);
            Console.WriteLine(batches);
            Assert.AreEqual(addedBatch.BroadcastId, id);
            Assert.True((bool)addedBatch.Enabled);
            Assert.AreEqual(addBatchRequest.Name, addedBatch.Name);

            addedBatch.Enabled = false;
            Client.BatchesApi.Update(addedBatch);
            Batch updatedBatch = Client.BatchesApi.Get(addedBatchId.Id);
            Assert.False((bool)updatedBatch.Enabled);
        }
Exemplo n.º 30
0
        public ResponseMessageWraper <GetUserInfoResponse> GetUserInfo([FromBody] GetByIdRequest reqMsg)
        {
            var data = _userRepository.GetUserInfo <Item>(reqMsg.Id);

            return(new ResponseMessageWraper <GetUserInfoResponse>
            {
                Body = new GetUserInfoResponse
                {
                    User = data.Item1,
                    ExtendData = data.Item2
                }
            });
        }
        public void TestContactListCRUD()
        {
            // create from numbers
            CreateContactListRequest<string> request = new CreateContactListRequest<string>
            {
                Contacts = new List<string> { "12135543211", "12135678882" },
                Name = "listFromNumbers"
            };
            ResourceId numbersListId = Client.ContactListsApi.Create(request);

            ContactList contactList = Client.ContactListsApi.Get(numbersListId.Id);
            Assert.AreEqual(2, contactList.Size);
            Assert.AreEqual(contactList.Name, "listFromNumbers");

            // get items
            GetByIdRequest getItemsRequest = new GetByIdRequest	{ Id = contactList.Id };
            Page<Contact> contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            IList<Contact> items = contactListItems.Items;
            Assert.AreEqual(2, items.Count);

            // create from ids
            var request2 = new CreateContactListRequest<long>
            {
                Contacts = new List<long> { (long)items[0].Id, (long)items[1].Id },
                Name = "listFromExistingContacts"
            };
            ResourceId idsListId = Client.ContactListsApi.Create(request2);

            contactList = Client.ContactListsApi.Get(idsListId.Id);
            Assert.AreEqual(2, contactList.Size);
            Assert.AreEqual(contactList.Name, "listFromExistingContacts");

            // find by name
            FindContactListsRequest findRequest = new FindContactListsRequest { Name = "listFrom" };
            Page<ContactList> contactLists = Client.ContactListsApi.Find(findRequest);
            Assert.Greater(contactLists.TotalCount, 1);

            // update
            UpdateContactListRequest updateListRequest = new UpdateContactListRequest
            {
                Id = idsListId.Id,
                Name = "new_name"
            };
            Client.ContactListsApi.Update(updateListRequest);
            ContactList updatedList = Client.ContactListsApi.Get((long)updateListRequest.Id);
            Assert.AreEqual("new_name", updatedList.Name);

            // delete
            Client.ContactListsApi.Delete((long)numbersListId.Id);
            Client.ContactListsApi.Delete((long)idsListId.Id);
        }
        public void GetBroadcastCalls()
        {
            var getCallsRequest = new GetByIdRequest { Id = 1 };
            var calls = Client.CallBroadcastsApi.GetCalls(getCallsRequest);
            Console.WriteLine(calls);
            Assert.That(calls.Items, Is.Not.Empty);

            long testBatchId = (long) calls.Items[0].BatchId;

            getCallsRequest = new GetBroadcastCallsTextsRequest { Id = 1, batchId = testBatchId };
            calls = Client.CallBroadcastsApi.GetCalls(getCallsRequest);
            Console.WriteLine(calls);
            Assert.AreEqual(calls.Items[0].BatchId, testBatchId);
        }
        public async Task Handle_FailingRequest_UsesTestErrorHandler()
        {
            Exception exception = null;

            try
            {
                var request = new GetByIdRequest <NonEntity, NonEntity>(1);
                await Mediator.HandleAsync(request);
            }
            catch (Exception e)
            {
                exception = e;
            }

            Assert.IsNotNull(exception);
            Assert.AreEqual("Failed to find entity.", exception.Message);
        }
Exemplo n.º 34
0
        private Negotiator GetById(GetByIdRequest request)
        {
            if (request.Id.IsNullOrWhitespace())
            {
                return(Negotiate.WithStatusCode(HttpStatusCode.BadRequest));
            }

            var todo = _dataStore.FindById(request.Id);

            if (todo == null)
            {
                return(Negotiate.WithStatusCode(HttpStatusCode.NotFound));
            }

            return(Negotiate.WithModel(ToDoResponse.From(todo))
                   .WithStatusCode(HttpStatusCode.OK));
        }
        public void AddRecipientsAndAddRemoveBatches()
        {
            var findRequest = new FindBroadcastsRequest
            {
                Name = "updated_name",
                Limit = 1
            };
            var broadcasts = Client.CallBroadcastsApi.Find(findRequest);
            Console.WriteLine(broadcasts);
            Assert.That(broadcasts.Items, Is.Not.Empty);
            var id = broadcasts.Items[0].Id;

            var calls = Client.CallBroadcastsApi.AddRecipients((long)id, new List<Recipient>
                {
                    new Recipient { PhoneNumber = "12132212384" },
                    new Recipient { PhoneNumber = "12132212385" }
                });
            Console.WriteLine(calls);
            Assert.AreEqual(2, calls.Count);

            // get batches
            var getBatchesRequest = new GetByIdRequest { Id = id };
            var batches = Client.CallBroadcastsApi.GetBatches(getBatchesRequest);
            Console.WriteLine(batches);

            // add batch
            var addBatchRequest = new AddBatchRequest
            {
                CampaignId = (long)id,
                Name = "new_batch",
                Recipients = new List<Recipient>
                {
                    new Recipient { PhoneNumber = "12132212386" },
                    new Recipient { PhoneNumber = "12132212387" }
                }
            };
            ResourceId addedBatchId = Client.CallBroadcastsApi.AddBatch(addBatchRequest);

            var addedBatch = Client.BatchesApi.Get(addedBatchId.Id);
            Assert.AreEqual(addedBatch.BroadcastId, id);
        }
        public void GetCallsWithGetByIdRequest()
        {
            var expectedJson = GetJsonPayload("/campaigns/callBroadcastsApi/response/getCalls.json");
            var restRequest = MockRestResponse(expectedJson);

            var request = new GetByIdRequest
            {
                Offset = 5,
                Fields = FIELDS,
                Id = 11
            };
            var calls = Client.CallBroadcastsApi.GetCalls(request);
            Assert.That(Serializer.Serialize(calls), Is.EqualTo(expectedJson));

            Assert.AreEqual(Method.GET, restRequest.Value.Method);
            var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody);
            Assert.IsNull(requestBodyParam);
            Assert.That(restRequest.Value.Resource, Is.StringEnding("/11/calls"));
            Assert.That(restRequest.Value.Parameters, Has.No.Some.Matches<Parameter>(p => p.Name.Equals("id")));
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("offset") && p.Value.Equals("5")));
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS)));
        }
 public Page<Call> GetCalls(GetByIdRequest request)
 {
     String path = CB_ITEM_CALLS_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.Id.ToString());
     return Client.Get<Page<Call>>(path, request);
 }
 /// <summary>
 /// Get text broadcast batches. Retrieve batches associated with text campaign
 /// </summary>
 /// <param name="request">get request</param>
 /// <returns>broadcast batches</returns>
 /// <exception cref="BadRequestException">          in case HTTP response code is 400 - Bad request, the request was formatted improperly.</exception>
 /// <exception cref="UnauthorizedException">        in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.</exception>
 /// <exception cref="AccessForbiddenException">     in case HTTP response code is 403 - Forbidden, insufficient permissions.</exception>
 /// <exception cref="ResourceNotFoundException">    in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.</exception>
 /// <exception cref="InternalServerErrorException"> in case HTTP response code is 500 - Internal Server Error.</exception>
 /// <exception cref="CallfireApiException">         in case HTTP response code is something different from codes listed above.</exception>
 /// <exception cref="CallfireClientException">      in case error has occurred in client.</exception>
 public Page<Batch> GetBatches(GetByIdRequest request)
 {
     String path = TB_ITEM_BATCHES_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.Id.ToString());
     return Client.Get<Page<Batch>>(path, request);
 }
 public Page<Text> GetTexts(GetByIdRequest request)
 {
     String path = TB_ITEM_TEXTS_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.Id.ToString());
     return Client.Get<Page<Text>>(path, request);
 }
        public void TestGetContactsForContactList()
        {
            string expectedJson = GetJsonPayload("/contacts/contactsApi/response/findContacts.json");
            var restRequest = MockRestResponse(expectedJson);

            GetByIdRequest request = new GetByIdRequest
            {
                Id = TEST_LONG,
                Limit = 1,
                Offset = 5,
                Fields = FIELDS
            };

            Page<Contact> contactsList = Client.ContactListsApi.GetListItems(request);

            Assert.NotNull(contactsList);
            Assert.That(Serializer.Serialize(contactsList), Is.EqualTo(expectedJson));

            Assert.AreEqual(Method.GET, restRequest.Value.Method);
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("limit") && p.Value.Equals("1")));
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("offset") && p.Value.Equals("5")));
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS)));
        }
        public void TestContactListItemsCRUD()
        {
            Contact c1 = new Contact { FirstName = "name1", HomePhone = "12345678901" };
            Contact c2 = new Contact { FirstName = "name2", HomePhone = "12345678902" };
            CreateContactListRequest<Contact> request = new CreateContactListRequest<Contact>
            {
                Contacts = new List<Contact> { c1, c2 },
                Name = "listFromContacts"
            };
            ResourceId id = Client.ContactListsApi.Create(request);

            AddContactListContactsRequest<string> addItemsRequest = new AddContactListContactsRequest<string>
            {
                ContactListId = id.Id,
                Contacts = new List<string> { "12345543211" }
            };
            Client.ContactListsApi.AddListItems(addItemsRequest);

            GetByIdRequest getItemsRequest = new GetByIdRequest { Id = id.Id };
            Page<Contact> contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            IList<Contact> items = contactListItems.Items;
            Assert.AreEqual(3, items.Count);

            Client.ContactListsApi.RemoveListItem(id.Id, (long)items[0].Id);
            contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            items = contactListItems.Items;
            Assert.AreEqual(2, items.Count);

            Client.ContactListsApi.RemoveListItems(id.Id, new List<long> { (long)items[0].Id, (long)items[1].Id });
            contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            Assert.True(contactListItems.Items.Count == 0);
            Assert.AreEqual(0, contactListItems.TotalCount);

            Client.ContactListsApi.Delete(id.Id);
        }
        public void GetContactHistory()
        {
            var expectedJson = GetJsonPayload("/contacts/contactsApi/response/getContactHistory.json");
            var restRequest = MockRestResponse(expectedJson);
            var request = new GetByIdRequest
            {
                Id = 1,
                Limit = 1,
                Offset = 5
            };
            var contactHistory = Client.ContactsApi.GetHistory(request);
            Assert.That(Serializer.Serialize(contactHistory), Is.EqualTo(expectedJson));

            Assert.AreEqual(Method.GET, restRequest.Value.Method);
            var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody);
            Assert.IsNull(requestBodyParam);
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("limit") && p.Value.Equals("1")));
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("offset") && p.Value.Equals("5")));
        }
        public void GetBroadcastTexts()
        {
            var broadcast = new TextBroadcast
            {
                Name = "text_broadcast_1",
                Message = "test_msg",
                Recipients = new List<TextRecipient>
                {
                    new TextRecipient { PhoneNumber = "14246525473" }
                }
            };
            var broadcastId = Client.TextBroadcastsApi.Create(broadcast, false);

            var request = new GetByIdRequest { Id = broadcastId.Id };
            var texts = Client.TextBroadcastsApi.GetTexts(request);
            Console.WriteLine(texts);
            Assert.That(texts.Items, Is.Not.Empty);

            long testBatchId = (long)texts.Items[0].BatchId;

            request = new GetBroadcastCallsTextsRequest { Id = broadcastId.Id, batchId = testBatchId };
            texts = Client.TextBroadcastsApi.GetTexts(request);
            Assert.AreEqual(texts.Items[0].BatchId, testBatchId);
        }