public void PutAsync_RequestHasNoId_ThrowsException()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah"
                }
            };

            _client.Setup(b => b.PutAsync <RequestResponse>(
                              It.IsAny <Uri>(),
                              request,
                              "application/json",
                              It.IsAny <string>(),
                              It.IsAny <string>()))
            .Returns(TaskHelper.CreateTaskFromResult(response));

            var requestResource = new RequestResource(_client.Object);

            // When, Then
            Assert.Throws <ArgumentException>(async() => await requestResource.PutAsync(request));
        }
Beispiel #2
0
        public async Task Create()
        {
            var response = new RequestResponse();

            using (var api = new EbanxRequestOperationApi())
            {
                var request = new RequestRequest
                {
                    Address             = "Test Address",
                    Amount              = 50,
                    City                = "City",
                    Country             = "BR",
                    Name                = "Name",
                    Email               = "*****@*****.**",
                    CurrencyCode        = "BRL",
                    PaymentTypeCode     = "mastercard",
                    Instalments         = "1-6",
                    DueDate             = "12/12/2020",
                    MerchantPaymentCode = "1",
                };

                response = await api.Create(request);
            }

            Assert.IsFalse(response.Success);
        }
Beispiel #3
0
        public async Task <IActionResult> PostRequest([FromBody] RequestRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Bad request",
                    Result = ModelState
                }));
            }

            RequestEntity requestEntity = new RequestEntity
            {
                Type        = await _context.RequestTypes.FindAsync(request.TypeId),
                InitialDate = request.InitialDate,
                FinishDate  = request.FinishDate,
                Description = request.Description,
                State       = "Pending",
                User        = await _context.Users.FindAsync(request.UserId.ToString())
            };

            _context.Requests.Add(requestEntity);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Beispiel #4
0
 public Request(RequestRequest requestRequest)
 {
     SenderId    = requestRequest.SenderId;
     ReceiverId  = requestRequest.ReceiverId;
     CreatedAt   = DateTime.UtcNow;
     RequestType = (RequestType)requestRequest.RequestTypeId;
 }
        public void Put_RequestHasNoId_ThrowsException()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah"
                }
            };

            _client.Setup(b => b.Put <RequestResponse>(
                              It.IsAny <Uri>(),
                              request,
                              "application/json",
                              It.IsAny <string>(),
                              It.IsAny <string>()))
            .Returns(response);

            var requestResource = new RequestResource(_client.Object);

            // When, Then
            Assert.Throws <ArgumentException>(() => requestResource.Put(request));
        }
        public void Put_CalledWithRequest_ReturnsRequestReponse()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah", Id = 123
                }
            };

            _client.Setup(b => b.Put <RequestResponse>(
                              It.IsAny <Uri>(),
                              request,
                              "application/json",
                              It.IsAny <string>(),
                              It.IsAny <string>()))
            .Returns(response);

            var resource = new RequestResource(_client.Object);

            // When
            var result = resource.Put(request);

            // Then
            Assert.That(result, Is.EqualTo(response));
        }
        public async void PostAsync_CalledWithRequest_ReturnsRequestReponse()
        {
            // Given
            var response = new RequestResponse {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah"
                }
            };

            _client.Setup(b => b.PostAsync <RequestResponse>(
                              It.IsAny <Uri>(),
                              request,
                              "application/json",
                              It.IsAny <string>(),
                              It.IsAny <string>()))
            .Returns(TaskHelper.CreateTaskFromResult(response));

            var requestResource = new RequestResource(_client.Object);

            // When
            var result = await requestResource.PostAsync(request);

            // Then
            Assert.That(result, Is.EqualTo(response));
        }
 public CreateRequestPageViewModel(INavigationService navigationService, IApiService apiService) : base(navigationService)
 {
     Title = Languages.NewRequest;
     _navigationService = navigationService;
     _apiService        = apiService;
     IsEnabled          = true;
     Today   = DateTime.Today.ToLocalTime();
     Request = new RequestRequest();
     LoadTypesAsync();
 }
        public void Apply()
        {
            Model.PatronID = Patron.ID;
            var request = new RequestRequest {
                UserID = GlobalVar.UserID, DTO = Mapper.Map(Model, new RequestDTO())
            };
            var response = Helper.Call(s => s.RequestSet(request));

            ServiceResponseHelper.CheckServiceResponse(response, "RequestSet", request);
            Helper.NotifySuccess("درخواست با موفقیت ثبت شد");
        }
        public void Put_Called_BuildsUri()
        {
            // Given
            var request = new RequestRequest { Item = new Request { Subject = "blah blah", Id = 123 } };
            var resource = new RequestResource(_client.Object);

            // When
            resource.Put(request);

            // Then
            _client.Setup(b => b.BuildUri(It.IsAny<string>(), ""));
        }
Beispiel #11
0
        public void Research()
        {
            var request = new RequestRequest {
                DTO = new RequestDTO {
                    ID = Model.ID
                }, UserID = GlobalVar.UserID
            };
            var response = Helper.Call(s => s.RequestResearch(request));

            ServiceResponseHelper.CheckServiceResponse(response, "RequestResearch", request);
            Helper.NotifySuccess("درخواست تحقیق با موفقیت ثبت شد");
        }
        public void Put_CalledWithRequest_ReturnsRequestReponse()
        {
            // Given
            var response = new RequestResponse { Item = new Request { Subject = "blah blah" } };
            var request = new RequestRequest { Item = new Request { Subject = "blah blah", Id = 123 } };
            _client.Setup(b => b.Put<RequestResponse>(It.IsAny<Uri>(), request, "application/json")).Returns(response);
            var resource = new RequestResource(_client.Object);

            // When
            var result = resource.Put(request);

            // Then
            Assert.That(result, Is.EqualTo(response));
        }
        public RequestResponse RequestGetList(RequestRequest request)
        {
            List <RequestDTO> result = null;

            try
            {
                NullSafeCheck(request, "RequestRequest");

                var filter = request.Filter;

                using (var context = new CharityEntities())
                {
                    var query = context.Requests.AsNoTracking().AsQueryable();
                    if (filter != null)
                    {
                        if (filter.ID > 0)
                        {
                            query = query.Where(p => p.Active && p.ID == filter.ID);
                        }
                        else
                        {
                            if (filter.Active != null)
                            {
                                query = query.Where(p => p.Active == filter.Active);
                            }
                            if (filter.CreateDate?.From != null)
                            {
                                query = query.Where(p => p.CreateDate >= filter.CreateDate.From);
                            }
                            if (filter.CreateDate?.To != null)
                            {
                                query = query.Where(p => p.CreateDate <= filter.CreateDate.To);
                            }

                            query = query.Where(p => p.PatronID == request.Filter.PatronID);
                        }
                    }
                    result = query.Select(Mapper.RequestDTOMapper).ToList();
                }

                return(new RequestResponse {
                    Success = true, ResultList = result
                });
            }
            catch (Exception ex)
            {
                var response = ExceptionToBaseResponse(ex);
                return(response.Cast <RequestResponse>());
            }
        }
Beispiel #14
0
            public async Task WhenSendFriendRequestGetsCalled()
            {
                Setup();

                var fixture = new Fixture();

                _requestRequest = fixture.Create <RequestRequest>();

                AuthService.Setup(service => service.AuthorizeSelf(It.IsAny <string>(), It.IsAny <Guid>())).Returns(true);
                RequestValidator.Setup(validator => validator.ValidateNewRequest(It.IsAny <Request>()))
                .ReturnsAsync(new List <Error>());

                _result = await RequestsController.SendRequest(_requestRequest);
            }
 public ResponseBase RequestSet(RequestRequest request)
 {
     try
     {
         NullSafeCheck(request, "RequestRequest");
         NullSafeCheck(request.DTO, "RequestDTO");
         UserCheck(request, request.DTO);
         var result = EntitySet <RequestDTO, Request>(request.DTO);
         return(new ResponseBase(true, result));
     }
     catch (Exception ex)
     {
         return(ExceptionToBaseResponse(ex));
     }
 }
        public async void PostAsync_Called_BuildsUri()
        {
            // Given
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah"
                }
            };
            var requestResource = new RequestResource(_client.Object);

            // When
            await requestResource.PostAsync(request);

            // Then
            _client.Setup(b => b.BuildUri(It.IsAny <string>(), ""));
        }
        public void Put_Called_BuildsUri()
        {
            // Given
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah", Id = 123
                }
            };
            var resource = new RequestResource(_client.Object);

            // When
            resource.Put(request);

            // Then
            _client.Setup(b => b.BuildUri(It.IsAny <string>(), ""));
        }
        public async void PutAsync_Called_BuildsUri()
        {
            // Given
            var client  = new Mock <IRestClient>();
            var request = new RequestRequest {
                Item = new Request {
                    Subject = "blah blah", Id = 123
                }
            };
            var resource = new RequestResource(client.Object);

            // When
            await resource.PutAsync(request);

            // Then
            client.Verify(b => b.BuildUri(It.IsAny <string>(), ""));
        }
 public ResponseBase RequestResearch(RequestRequest request)
 {
     try
     {
         NullSafeCheck(request, "RequestRequest");
         NullSafeCheck(request.DTO, "RequestDTO");
         UserCheck(request, request.DTO);
         using (var context = new CharityEntities())
         {
             var entity = context.Requests.FirstOrDefault(r => r.ID == request.DTO.ID);
             entity.ResearchDate = DateTime.Now;
             context.SaveChanges();
         }
         return(new ResponseBase(true, 1));
     }
     catch (Exception ex)
     {
         return(ExceptionToBaseResponse(ex));
     }
 }
Beispiel #20
0
        public async Task <IActionResult> SendRequest([FromBody] RequestRequest requestRequest)
        {
            var tkn = Request.Headers["Authorization"];

            if (!_authService.AuthorizeSelf(tkn, requestRequest.SenderId))
            {
                return(Unauthorized());
            }

            var newRequest = new Request(requestRequest);

            var validationResult = await _requestValidator.ValidateNewRequest(newRequest);

            if (validationResult.Any())
            {
                return(BadRequest(validationResult));
            }

            await _requestsRepository.CreateRequest(newRequest);

            return(Ok());
        }
Beispiel #21
0
        public async Task <Response> RegisterRequestAsync(string urlBase, string servicePrefix, string controller, RequestRequest requestRequest, string tokenType, string accessToken)
        {
            try
            {
                string        request = JsonConvert.SerializeObject(requestRequest);
                StringContent content = new StringContent(request, Encoding.UTF8, "application/json");
                HttpClient    client  = new HttpClient
                {
                    BaseAddress = new Uri(urlBase)
                };

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tokenType, accessToken);
                string url = $"{servicePrefix}{controller}";
                HttpResponseMessage response = await client.PostAsync(url, content);

                string answer = await response.Content.ReadAsStringAsync();

                if (!response.IsSuccessStatusCode)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = answer
                    });
                }

                return(new Response
                {
                    IsSuccess = true
                });
            }
            catch (Exception ex)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = ex.Message
                });
            }
        }
Beispiel #22
0
 public async Task <IResponse <Request> > PostAsync(RequestRequest request)
 {
     return(await PostAsync <RequestRequest, RequestResponse>(request).ConfigureAwait(false));
 }
Beispiel #23
0
 public IResponse <Request> Post(RequestRequest request)
 {
     return(Post <RequestRequest, RequestResponse>(request));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public async Task <RequestResponse> Create(RequestRequest request)
 {
     return(await PostAsync <RequestResponse>(request));
 }
        public void Put_RequestHasNoId_ThrowsException()
        {
            // Given
            var response = new RequestResponse { Item = new Request { Subject = "blah blah" } };
            var request = new RequestRequest { Item = new Request { Subject = "blah blah" } };
            _client.Setup(b => b.Put<RequestResponse>(It.IsAny<Uri>(), request, "application/json")).Returns(response);
            var requestResource = new RequestResource(_client.Object);

            // When, Then
            Assert.Throws<ArgumentException>(() => requestResource.Put(request));
        }
Beispiel #26
0
 public IResponse <Request> Put(RequestRequest request)
 {
     ValidateRequest(request);
     return(Put <RequestRequest, RequestResponse>(request, $"{ResourceUri}/{request.Item.Id}"));
 }
Beispiel #27
0
 public async Task <IResponse <Request> > PutAsync(RequestRequest request)
 {
     ValidateRequest(request);
     return(await PutAsync <RequestRequest, RequestResponse>(request, $"{ResourceUri}/{request.Item.Id}").ConfigureAwait(false));
 }