public BatchModel CreateBatch(int configId, string template, Status status)
        {
            BatchModel batch = new BatchModel()
            {
                Config_Id = configId,
                Status = status,
                Template = template
            };

            return CreateBatch(batch);
        }
        public BatchModel CreateBatch(BatchModel batch)
        {
            if (!_creationAllowedStatuses.Contains(batch.Status))
            {
                throw new ArgumentException(string.Format(StringResource.STATUS_NOT_ALLOWED, batch.Status));
            }

            IDictionary<string, object> propertyValues = batch.ToPostPropertiesDictionary();
            Uri uri = new Uri(_baseUri, _batchRelatedUri);
            ServiceResponse serviceReponse = _serviceCommunicator.PostRequest(uri.ToString(), _authorizationStrategy.GetAuthorizationHeader(), propertyValues);
            if (serviceReponse.StatusCode != HttpStatusCode.OK)
            {
                ThrowCommunicationException(serviceReponse);
            }

            BatchModel resultConfigModel =_modelConvertor.ConvertToModel<BatchModel>(serviceReponse.Response);
            return resultConfigModel;
        }
        public bool ModifyBatch(BatchModel batch)
        {
            IDictionary<string, object> propertyValues = batch.ToUpdatePropertiesDictionary();
            Uri uri = new Uri(_baseUri, JoinRelativeUri(_batchRelatedUri, batch.Batch_Id));
            ServiceResponse serviceReponse = _serviceCommunicator.PostRequest(uri.ToString(), _authorizationStrategy.GetAuthorizationHeader(), propertyValues);
            if (serviceReponse.StatusCode != HttpStatusCode.OK)
            {
                ThrowCommunicationException(serviceReponse);
            }

            bool result;
            bool canParse = bool.TryParse(serviceReponse.Response, out result);
            return canParse && result;
        }
        public bool ModifyBatch(int batchId, Status status)
        {
            BatchModel batch = new BatchModel()
            {
                Status = status,
                Batch_Id = batchId
            };

            return ModifyBatch(batch);
        }
Exemplo n.º 5
0
        public void TestPostBatch()
        {
            IAuthorizationStrategy basicAuthStrategy = MockAuthStrategy();
            IServiceCommunicator serviceCommunicator = MockServiceCommunicator();
            IStamprApiClient stamprApiClient = new StamprApiClient.StamprApiClient(_url, _username, _password, serviceCommunicator, basicAuthStrategy);
            BatchModel postModel = new BatchModel()
            {
                Config_Id = 4769,
                Status = Status.processing,
                Template = "Hello"
            };

            BatchModel model = stamprApiClient.CreateBatch(postModel);
            Assert.AreEqual(model.Config_Id, postModel.Config_Id);
            Assert.AreEqual(model.Status, postModel.Status);
            Assert.AreEqual(model.Template, postModel.Template);
            Assert.Greater(model.Batch_Id, 0);
            Assert.Greater(model.User_Id, 0);
        }