コード例 #1
0
        public async Task Get_and_Post_Ok()
        {
            //Get current data
            var getResponse = await _clientWithToken.GetAsync(ApiEndpoints.userprofiles_me_partnerinvitation);

            Assert.Equal(HttpStatusCode.NotFound, getResponse.StatusCode);
            var getResponsebody = await getResponse.Content.ReadAsStringAsync();

            Assert.Equal("{\"error\":{\"code\":\"NotFound\",\"message\":\"No data found for UserId EA5CEE24-90F9-4804-A45A-4D2E7FCA5D1A\",\"debugMessage\":null}}", getResponsebody);

            //POST data (create invitation)
            var postRequest = new PartnerInvitationRequestInfo
            {
                DateOfBirth  = DateTime.Now.AddYears(-21).ExGetDateOfBirth(),
                FirstName    = "fName",
                LastName     = "lastName",
                MobilePhone  = "7605006125",
                TypeOfGender = GenderType.Male,
            };
            var postResponse = await _clientWithToken.PostAsync(ApiEndpoints.userprofiles_me_partnerinvitation, GetJsonContent(postRequest));

            Assert.Equal(HttpStatusCode.NoContent, postResponse.StatusCode);
            var postResponseBody = await postResponse.Content.ReadAsStringAsync();

            Assert.Equal("", postResponseBody);

            //Get current data again (after Post)
            getResponse = await _clientWithToken.GetAsync(ApiEndpoints.userprofiles_me_partnerinvitation);

            getResponse.EnsureSuccessStatusCode();
            Assert.Equal(HttpStatusCode.OK, getResponse.StatusCode);
            getResponsebody = await getResponse.Content.ReadAsStringAsync();

            var payload = Deserialize <PartnerInvitationResponseInfo>(getResponsebody);

            Assert.Equal(postRequest.DateOfBirth, payload.DateOfBirth);
            Assert.Equal(postRequest.FirstName, payload.FirstName);
            Assert.Equal(PartnerInvitationStatusType.Submitted, payload.InvitationStatus);
            Assert.Equal(postRequest.LastName, payload.LastName);
            Assert.Equal(postRequest.MobilePhone, payload.MobilePhone);
            Assert.Equal(postRequest.TypeOfGender, payload.TypeOfGender);
            Assert.Equal(payload.InvitationId, new Guid(payload.InvitationId).ToString().ToUpper());

            //Resend Invitation
            postResponse = await _clientWithToken.PostAsync("api/userprofiles/me/partnerinvitation/resendinvite", null);

            Assert.Equal(HttpStatusCode.NoContent, postResponse.StatusCode);
            postResponseBody = await postResponse.Content.ReadAsStringAsync();

            Assert.Equal("", postResponseBody);
        }
コード例 #2
0
        public async Task <PartnerInvitationRequestInfo> CreatePartnerInvitation(HttpClient client, [CallerMemberName] string callerMemberName = null, [CallerFilePath] string assemblyFilePath = null)
        {
            var postRequest = new PartnerInvitationRequestInfo
            {
                DateOfBirth  = DateTime.Now.AddYears(-21).ExGetDateOfBirth(),
                FirstName    = $"{callerMemberName}",
                LastName     = $"{assemblyFilePath.ExGetFileNameFromAssemblyPath()}",
                MobilePhone  = "7605006125",
                TypeOfGender = GenderType.Male,
            };
            var postResponse = await client.PostAsync(ApiEndpoints.userprofiles_me_partnerinvitation, BaseWebApiTest.GetJsonContent(postRequest));

            postResponse.EnsureSuccessStatusCode();
            return(postRequest);
        }
コード例 #3
0
        public async Task <IActionResult> Post([FromBody] PartnerInvitationRequestInfo request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(this.ApiErrorMessage400BadRequest(ModelState));
                }

                var jwtPayloadInfo = this.GetJwtPayloadInfo();
                var userProfileId  = await _bl.GetCachedUserId_byExternalReferenceIdAsync(jwtPayloadInfo.ExtReferenceId);

                if (userProfileId == null)
                {
                    return(this.ApiErrorMessage400BadRequestUserIdInTokenNotFound(jwtPayloadInfo.ExtReferenceId));
                }

                var bl_partnerInvitation = new BL_PartnerInvitation
                {
                    DateOfBirth     = request.DateOfBirth,
                    FirstName       = request.FirstName,
                    InvitedByUserId = userProfileId,
                    LastName        = request.LastName,
                    MobilePhone     = request.MobilePhone,
                    TypeOfGender    = EnumMapper.From(request.TypeOfGender),
                };

                await _bl.SetPartnerInvitationsAsync(bl_partnerInvitation);

                return(this.ApiPostMessage204NotContent());
            }
            catch (BusinessLogicException ex)
            {
                HttpContext.Items.Add("ex", ex); //For instrumentation
                return(this.ApiErrorMessage400BadRequest(ex));
            }
            catch (Exception ex)
            {
                HttpContext.Items.Add("ex", ex); //For instrumentation
                return(this.ApiErrorMessage400BadRequest(ex));
            }
        }