コード例 #1
0
 public void RaiseReleaseRequestReceived(ReleaseRequest relReq, Association asc)
 {
     if (ReleaseRequestReceived != null)
     {
         ReleaseRequestReceived(relReq, asc);
     }
 }
コード例 #2
0
ファイル: ReleaseExamples.cs プロジェクト: AltaPay/sdk-csharp
        /// <summary>
        /// Example for performing  release payment request.
        /// </summary>
        public void Release()
        {
            //Reserving amount in order to release method example could be successful
            PaymentResult paymentResult = ReserveAmount(Amount.Get(2190.00, Currency.EUR), AuthType.payment);
            //Transaction ID is returned from the gateway when payment request was successful
            string transactionId = paymentResult.Payment.TransactionId;

            //initialize release request class
            ReleaseRequest releaseRequest = new ReleaseRequest
            {
                PaymentId = transactionId
            };

            //call release method
            ReleaseResult releaseResult = _api.Release(releaseRequest);

            //Result property contains information if the request was successful or not
            if (releaseResult.Result == Result.Success)
            {
                //release was successful
                Transaction transaction = releaseResult.Payment;
            }
            else
            {
                //release unsuccessful
                //error messages contain information about what went wrong
                string errorMerchantMessage = releaseResult.ResultMerchantMessage;
                string errorMessage         = releaseResult.ResultMessage;
            }
        }
コード例 #3
0
        public async void Post_SuccessStatus201_Test()
        {
            // 1: Add Existing establishment to validate name param on request body
            await establishmentService.CreateItem(new Establishment()
            {
                Name = "Test 1",
                Type = "Alimentação"
            });

            // 2: Request body
            ReleaseRequest requestBody = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            // 3: Call POST Action passing body request with a new release
            var query = await releasesController.Post(requestBody);

            var resultStatusCode = query.Result.GetType().GetProperty("StatusCode").GetValue(query.Result);
            var resultValue      = (Release)query.Result.GetType().GetProperty("Value").GetValue(query.Result);

            // 4: Remove all establishments and releases from database
            await establishmentService.RemoveAll();

            await releasesService.RemoveAll();

            Assert.Equal(201, (int)resultStatusCode);
            Assert.Equal("Test 1", resultValue.EstablishmentName);
            Assert.NotNull(resultValue.Id);
        }
コード例 #4
0
        public async void Put_Returns404_EstablishmentNotFound_Test()
        {
            // 1: Request body
            string id          = "5dcaad2526235a471cfcccad";
            var    requestBody = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            // 2: Mocking GetById to return a fake release object
            var releasesServiceMock = new Mock <ReleasesService>(dbSettings);

            releasesServiceMock.Setup(es => es.GetById(It.IsAny <string>())).ReturnsAsync(new Release()
            {
                Date              = requestBody.Date,
                PaymentMethod     = requestBody.PaymentMethod,
                EstablishmentName = requestBody.EstablishmentName,
                Amount            = requestBody.Amount,
                CreatedAt         = DateTime.Now
            });

            var releasesControllerLocal = new ReleasesController(loggerWrapper, releasesServiceMock.Object, establishmentService, controllerMessages);

            var query = await releasesControllerLocal.Put(id, requestBody);

            var  result     = query.Result.GetType().GetProperty("Value").GetValue(query.Result);
            Type resultType = result.GetType();

            Assert.Equal(404, (int)resultType.GetProperty("StatusCode").GetValue(result));
            Assert.Equal(controllerMessages.CantFoundGivenName.Replace("$", "estabelecimento"), (string)resultType.GetProperty("Message").GetValue(result));
        }
コード例 #5
0
        public async Task <ActionResult <Release> > Post([FromBody] ReleaseRequest body)
        {
            Release resultRelease;

            try {
                logger.LogInformation("Trying to get associated establishment");
                var establishment = await establishmentService.GetByName(body.EstablishmentName);

                if (establishment == null)
                {
                    string errorMessage = responseMessages.CantFoundGivenName.Replace("$", "estabelecimento");
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 404));
                }

                logger.LogInformation("Inserting release into database");
                var newRelease = new Release()
                {
                    Date              = body.Date,
                    PaymentMethod     = body.PaymentMethod,
                    Amount            = body.Amount,
                    EstablishmentName = establishment.Name,
                    CreatedAt         = DateTime.Now
                };

                resultRelease = await releasesService.CreateItem(newRelease);
            } catch (Exception ex) {
                logger.LogInformation("Exception: " + ex.Message);
                throw ex;
            }

            logger.LogInformation("Action POST for /api/releases returns 201");
            return(Created("", resultRelease));
        }
コード例 #6
0
        public async void Post_NoEstablishment_StatusCode_404_Test()
        {
            // 0: Remove all establishments from database
            await establishmentService.RemoveAll();

            // 1: Creating testing objects
            ReleaseRequest testRelease = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            // 2: Trying to POST a new release
            var query = await releasesController.Post(testRelease);

            var result = query.Result.GetType().GetProperty("Value").GetValue(query.Result);

            // 3: Check if result is an error
            Type resultType = result.GetType();

            Assert.Equal(404, (int)resultType.GetProperty("StatusCode").GetValue(result));
            Assert.Equal(controllerMessages.CantFoundGivenName.Replace("$", "estabelecimento"), (string)resultType.GetProperty("Message").GetValue(result));
        }
コード例 #7
0
        public static void SendReleaseRequest(Association asc)
        {
            var req = new ReleaseRequest();

            asc.State = NetworkState.AWAITING_RELEASE_RESPONSE;
            asc.Logger.Log("-->" + req);
            byte[] message = req.Write();
            if (asc.Stream.CanWrite)
            {
                asc.Stream.Write(message, 0, message.Length);
            }
        }
コード例 #8
0
ファイル: PDUReader.cs プロジェクト: yjsyyyjszf/DicomFinder-1
        public static Message <ReleaseRequest> ReadReleaseRequest(NetworkBinaryReader dr)
        {
            var relReq = new ReleaseRequest();

            if (relReq.Write().Skip(1).SequenceEqual(dr.Take(9)))
            {
                return(new Message <ReleaseRequest> {
                    Payload = relReq, Type = MessageType.PDU
                });
            }
            //Invalid release request
            throw new Exception("Release request was invalid. Did not match signature.");
        }
コード例 #9
0
        public void ReleasePaymentReturnsSuccess()
        {
            var reserveResult = ReserveAmount(1.23, AuthType.payment);

            this.WaitForDataToFlowIntoReporting();

            var request = new ReleaseRequest {
                PaymentId = reserveResult.Payment.TransactionId,
            };
            PaymentResult result = _api.Release(request);

            Assert.AreEqual(Result.Success, result.Result);
        }
コード例 #10
0
        public async void Put_Returns406_NotAcknowledged_Test()
        {
            // 1: Request body
            string id          = "5dcaad2526235a471cfcccad";
            var    requestBody = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            // 2: Mocking GetById Method to return fake data
            var releasesServiceMock = new Mock <ReleasesService>(dbSettings);

            releasesServiceMock.Setup(es => es.GetById(It.IsAny <string>())).ReturnsAsync(new Release()
            {
                Date              = requestBody.Date,
                PaymentMethod     = requestBody.PaymentMethod,
                EstablishmentName = requestBody.EstablishmentName,
                Amount            = requestBody.Amount,
                CreatedAt         = DateTime.Now
            });

            var establishmentServiceMock = new Mock <EstablishmentService>(dbSettings);

            establishmentServiceMock.Setup(es => es.GetByName(It.IsAny <string>())).ReturnsAsync(new Establishment()
            {
                Name = "Test 1",
                Type = "Alimentação"
            });

            var replaceOneResultWrapper = new ReplaceOneResultWrapper();

            releasesServiceMock.Setup(es => es.UpdateById(It.IsAny <string>(), It.IsAny <Release>())).ReturnsAsync(replaceOneResultWrapper);

            var releasesControllerLocal = new ReleasesController(loggerWrapper, releasesServiceMock.Object, establishmentServiceMock.Object, controllerMessages);

            var query = await releasesControllerLocal.Put(id, requestBody);

            var  result     = query.Result.GetType().GetProperty("Value").GetValue(query.Result);
            Type resultType = result.GetType();

            Assert.Equal(406, (int)resultType.GetProperty("StatusCode").GetValue(result));
            Assert.Equal(controllerMessages.CantUpdate, (string)resultType.GetProperty("Message").GetValue(result));
        }
コード例 #11
0
        public async void Put_SuccessStatus200_Test()
        {
            // 1: POST Request body
            var postRequestBody = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            var establishmentServiceMock = new Mock <EstablishmentService>(dbSettings);

            establishmentServiceMock.Setup(es => es.GetByName(It.IsAny <string>())).ReturnsAsync(
                new Establishment()
            {
                Name = "Test 1",
                Type = "Alimentação"
            });

            // 2: Call POST Action passing body request with a new release
            var releasesControllerLocal = new ReleasesController(loggerWrapper, releasesService, establishmentServiceMock.Object, controllerMessages);

            var postQuery = await releasesControllerLocal.Post(postRequestBody);

            var postResultValue = (Release)postQuery.Result.GetType().GetProperty("Value").GetValue(postQuery.Result);

            // 3: PUT Request body
            string id          = postResultValue.Id;
            var    requestBody = new ReleaseRequest {
                Date              = "06/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            var query = await releasesControllerLocal.Put(id, requestBody);

            var statusCode = (int)query.Result.GetType().GetProperty("StatusCode").GetValue(query.Result);
            var result     = (Release)query.Result.GetType().GetProperty("Value").GetValue(query.Result);

            Assert.Equal(200, statusCode);
            Assert.Equal("06/05/2019", result.Date);
        }
コード例 #12
0
        [Authorize]                   // Require some form of authentication
        public async Task <HttpResponseMessage> Post([FromBody] JObject payload)
        {
            var request = ReleaseRequest.Parse(payload);

            if (!request.IsValid)
            {
                this.Log(request.Error);
                return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = request.Error
                });
            }

            var runtime = this.GetRuntimeContext(request);

            await new ReleaseRequestHandler().HandleRelease(request, runtime.Settings.PersonalToken, runtime.RequestContext.GetProjectCollectionUri());

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }
コード例 #13
0
        public async void Put_InvalidId400_Test(string id)
        {
            // 1: Request body
            var requestBody = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            // 2: Call PUT Action passing body request with an updated release
            var query = await releasesController.Put(id, requestBody);

            var  result     = query.Result.GetType().GetProperty("Value").GetValue(query.Result);
            Type resultType = result.GetType();

            Assert.Equal(400, (int)resultType.GetProperty("StatusCode").GetValue(result));
            Assert.Equal(controllerMessages.IncorretIdFormat, (string)resultType.GetProperty("Message").GetValue(result));
        }
コード例 #14
0
        public async void Put_Returns404_IdNotFound_Test()
        {
            // 1: Request body, given id is not found on database
            string id          = "5dcaad2526235a471cfcccad";
            var    requestBody = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            // 2: Call PUT Action passing body request with an updated release
            var query = await releasesController.Put(id, requestBody);

            var  result     = query.Result.GetType().GetProperty("Value").GetValue(query.Result);
            Type resultType = result.GetType();

            Assert.Equal(404, (int)resultType.GetProperty("StatusCode").GetValue(result));
            Assert.Equal(controllerMessages.NotFoundGivenId.Replace("$", "lançamento"), (string)resultType.GetProperty("Message").GetValue(result));
        }
コード例 #15
0
        public async void Post_ThrowsException_Test()
        {
            // 0: Creating testing objects
            ReleaseRequest testRelease = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            // 1: Mocking GetByName Method to throws
            var establishmentServiceMock = new Mock <EstablishmentService>(dbSettings);

            establishmentServiceMock.Setup(es => es.GetByName(It.IsAny <string>())).ThrowsAsync(new InvalidOperationException());

            var releasesControllerLocal = new ReleasesController(loggerWrapper, releasesService, establishmentServiceMock.Object, controllerMessages);

            // 2: Call POST Action and Expects to throws
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await releasesControllerLocal.Post(testRelease));
        }
コード例 #16
0
        public async void Put_ThrowsException_Test()
        {
            // 1: Request body
            string id          = "5dcaad2526235a471cfcccad";
            var    requestBody = new ReleaseRequest()
            {
                Date              = "05/05/2019",
                PaymentMethod     = PaymentMethod.Credito,
                EstablishmentName = "Test 1",
                Amount            = 55.55m
            };

            // 2: Mocking GetByName Method to throws
            var releasesServiceMock = new Mock <ReleasesService>(dbSettings);

            releasesServiceMock.Setup(es => es.GetById(It.IsAny <string>())).ThrowsAsync(new InvalidOperationException());

            var releasesControllerLocal = new ReleasesController(loggerWrapper, releasesServiceMock.Object, establishmentService, controllerMessages);

            // 3: Call POST Action and Expects to throws
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await releasesControllerLocal.Put(id, requestBody));
        }
コード例 #17
0
        public JsonResult CurrentRelease(ReleaseRequest rreq)
        {
            ReleaseResponse release = null;

            try
            {
                if (rreq != null)
                {
                    if (Request.Cookies["AUTH_PTEmail"] != null && Request.Cookies["AUTHADMIN"] != null && Request.Cookies["AUTHADMIN"].Value == "Admin")
                    {
                        rreq.emailid = "";
                    }

                    release = CABusinessProjectTrackingAPIClient.GetHttpResponse <ReleaseResponse>(rreq, CABPTMethodConstants.CURRENTRELEASE);
                }
                return(Json(JsonConvert.SerializeObject(release)));
            }

            catch (Exception ex)
            {
                JsonExceptionResult jsonexc = new JsonExceptionResult();
                return(Json(JsonConvert.SerializeObject(new CABPTException(ex, out jsonexc))));
            }
        }
コード例 #18
0
 /// <summary>
 ///  发布edge核心系统和安装包
 /// </summary>
 /// <param name="request">请求参数信息</param>
 /// <returns>请求结果信息</returns>
 public async Task <ReleaseResponse> Release(ReleaseRequest request)
 {
     return(await new ReleaseExecutor().Client(this).Execute <ReleaseResponse, ReleaseResult, ReleaseRequest>(request).ConfigureAwait(false));
 }
コード例 #19
0
        public async Task HandleRelease(ReleaseRequest releaseRequest, string pat, Uri projectCollectionUri)
        {
            var creds      = new VssBasicCredential(string.Empty, pat);
            var connection = new VssConnection(new Uri(projectCollectionUri, "DefaultCollection"), creds);

            var gitClient     = connection.GetClient <GitHttpClient>();
            var buildClient   = connection.GetClient <BuildHttpClient>();
            var releaseClient = connection.GetClient <ReleaseHttpClient>();


            var release = await releaseClient.GetReleaseAsync(releaseRequest.TeamProject, releaseRequest.ReleaseId);

            var buildArtifact = release.Artifacts.First(a => a.Type == "Build").DefinitionReference;
            var branch        = buildArtifact["branch"].Name;

            var build = await buildClient.GetBuildAsync(buildArtifact["project"].Id, int.Parse(buildArtifact["version"].Id));

            var envStatus = release.Environments.ToDictionary(e => e.Name, e => e.Status);

            var repos = await gitClient.GetRepositoriesAsync(releaseRequest.TeamProject);

            var prs = await gitClient.GetPullRequestsAsync(
                releaseRequest.TeamProject,
                repos.First(r => r.Name == releaseRequest.TeamProject).Id,
                new GitPullRequestSearchCriteria { Status = PullRequestStatus.Active, SourceRefName = branch });

            foreach (var pr in prs)
            {
                var iterations = await gitClient.GetPullRequestIterationsAsync(pr.Repository.Id, pr.PullRequestId);

                var id = iterations.Last(i => i.SourceRefCommit.CommitId == build.SourceVersion).Id;

                foreach (var env in envStatus)
                {
                    var prStatus = new GitPullRequestStatus
                    {
                        State       = GetEnvState(env.Value),
                        Description = $"Deploy {env.Key} {env.Value}",
                        TargetUrl   = (release.Links.Links["web"] as ReferenceLink)?.Href,
                        Context     = new GitStatusContext {
                            Genre = "release", Name = env.Key
                        }
                    };

                    if (id != null)
                    {
                        prStatus.Description = $"Update {id.Value}: {prStatus.Description}";
                        await gitClient.CreatePullRequestIterationStatusAsync(prStatus, pr.Repository.Id, pr.PullRequestId, id.Value);
                    }
                }

                if (envStatus.All(e => GetEnvState(e.Value) == GitStatusState.Succeeded))
                {
                    var prStatus = new GitPullRequestStatus
                    {
                        State       = GitStatusState.Succeeded,
                        Description = $"Last Complete Deploy: Update {id}",
                        TargetUrl   = (release.Links.Links["web"] as ReferenceLink)?.Href,
                        Context     = new GitStatusContext {
                            Genre = "release", Name = "lastComplete"
                        }
                    };

                    await gitClient.CreatePullRequestStatusAsync(prStatus, releaseRequest.TeamProject, pr.Repository.Id, pr.PullRequestId).ConfigureAwait(false);
                }
            }
        }
コード例 #20
0
 /// <summary>
 ///  发布edge核心系统和安装包
 /// </summary>
 /// <param name="request">请求参数信息</param>
 /// <returns>请求结果信息</returns>
 public ReleaseResponse Release(ReleaseRequest request)
 {
     return(new ReleaseExecutor().Client(this).Execute <ReleaseResponse, ReleaseResult, ReleaseRequest>(request));
 }
コード例 #21
0
        public async Task <ActionResult <Release> > Put(string id, [FromBody] ReleaseRequest body)
        {
            // Validating id
            if (id == null || !Regex.IsMatch(id, "^[0-9a-fA-F]{24}$"))
            {
                string errorMessage = responseMessages.IncorretIdFormat;
                logger.LogInformation("Error: " + errorMessage);
                return(httpResponseHelper.ErrorResponse(errorMessage, 400));
            }

            Release updatedRelease;

            try {
                logger.LogInformation("Trying to get a release with given id");
                var actualRelease = await releasesService.GetById(id);

                if (actualRelease == null)
                {
                    string errorMessage = responseMessages.NotFoundGivenId.Replace("$", "lançamento");
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 404));;
                }

                logger.LogInformation("Trying to get associated establishment");
                var establishment = await establishmentService.GetByName(body.EstablishmentName);

                if (establishment == null)
                {
                    string errorMessage = responseMessages.CantFoundGivenName.Replace("$", "estabelecimento");
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 404));
                }

                updatedRelease = new Release()
                {
                    Id                = id,
                    Date              = body.Date,
                    PaymentMethod     = body.PaymentMethod,
                    Amount            = body.Amount,
                    EstablishmentName = establishment.Name,
                    CreatedAt         = actualRelease.CreatedAt,
                    UpdatedAt         = DateTime.Now
                };

                logger.LogInformation("Trying to update release with id: " + id);
                var replaceResult = await releasesService.UpdateById(id, updatedRelease);

                if (!replaceResult.IsAcknowledged)
                {
                    string errorMessage = responseMessages.CantUpdate;
                    logger.LogInformation("Error: " + errorMessage);
                    return(httpResponseHelper.ErrorResponse(errorMessage, 406));
                }
            } catch (Exception ex) {
                logger.LogInformation("Exception: " + ex.Message);
                throw ex;
            }

            logger.LogInformation("Action PUT for /api/releases returns 200");
            return(Ok(updatedRelease));
        }