Пример #1
0
 public void Setup()
 {
     _contactDetails = new Models.ContactDetails()
     {
         CustomerId = Guid.Parse(ValidCustomerId)
     };
     _contactDetailsPatch = new Models.ContactDetailsPatch();
     _request             = new DefaultHttpRequest(new DefaultHttpContext());
     _log                            = new Mock <ILogger>();
     _resourceHelper                 = new Mock <IResourceHelper>();
     _validate                       = new Validate();
     _httpRequestMessageHelper       = new Mock <IHttpRequestHelper>();
     _patchContactHttpTriggerService = new Mock <IPatchContactDetailsHttpTriggerService>();
     _provider                       = new Mock <IDocumentDBProvider>();
     _httpResponseMessageHelper      = new HttpResponseMessageHelper();
     _function                       = new PatchContactHttpTrigger(_resourceHelper.Object, _httpRequestMessageHelper.Object, _validate, _patchContactHttpTriggerService.Object, _provider.Object, _httpResponseMessageHelper);
 }
Пример #2
0
        public async Task PatchContactHttpTrigger_ReturnsStatusCodeUnprocessableEntity_WhenContactHasFailedValidation()
        {
            // Arrange
            _httpRequestMessageHelper.Setup(x => x.GetDssTouchpointId(_request)).Returns("0000000001");
            _httpRequestMessageHelper.Setup(x => x.GetDssApimUrl(_request)).Returns("http://localhost:7071/");
            _httpRequestMessageHelper.Setup(x => x.GetResourceFromRequest <Models.ContactDetailsPatch>(_request)).Returns(Task.FromResult(_contactDetailsPatch));
            var val = new Mock <IValidate>();
            var validationResults = new List <ValidationResult> {
                new ValidationResult("contactDetail Id is Required")
            };

            val.Setup(x => x.ValidateResource(It.IsAny <Models.ContactDetailsPatch>(), _contactDetails, false)).Returns(validationResults);
            _resourceHelper.Setup(x => x.DoesCustomerExist(It.IsAny <Guid>())).Returns(Task.FromResult(true));
            _patchContactHttpTriggerService.Setup(x => x.GetContactDetailsForCustomerAsync(It.IsAny <Guid>(), It.IsAny <Guid>())).Returns(Task.FromResult <Models.ContactDetails>(_contactDetails));
            _function = new PatchContactHttpTrigger(_resourceHelper.Object, _httpRequestMessageHelper.Object, val.Object, _patchContactHttpTriggerService.Object, _provider.Object, _httpResponseMessageHelper);

            // Act
            var result = await RunFunction(ValidCustomerId, ValidContactId);

            // Assert
            Assert.IsInstanceOf <HttpResponseMessage>(result);
            Assert.AreEqual(422, (int)result.StatusCode);
        }
Пример #3
0
 private async Task <HttpResponseMessage> RunFunction(string customerId, string contactDetailId)
 {
     return(await PatchContactHttpTrigger.RunAsync(
                _request, _log, customerId, contactDetailId, _resourceHelper, _httpRequestMessageHelper, _validate, _patchContactHttpTriggerService, _provider).ConfigureAwait(false));
 }