private async Task <Provider[]> SendRequestAsync(ProviderQueryRequest request, CancellationToken cancellationToken) { var requestXml = _requestSerializer.Serialize(request); var httpRequest = new HttpRequestMessage { Method = HttpMethod.Post, Headers = { { "SOAPAction", "retrieveAllProviders" } }, Content = new StringContent(requestXml, Encoding.UTF8, "text/xml"), }; var response = await _httpClient.SendAsync(httpRequest, cancellationToken); var responseXml = await response.Content.ReadAsStringAsync(); var result = _responseDeserializer.DeserializeResponse(responseXml); if (!response.IsSuccessStatusCode) { // If we are here then we got a failed response without a SOAP fault throw new Exception($"Error calling UKRLP SOAP Api. Not fault returned. Http Status {(int) response.StatusCode}"); } return(result); }
public async Task Can_create_user_with_password() { // Arrange User newUser = _fakers.User.Generate(); IRequestSerializer serializer = GetRequestSerializer <User>(user => new { user.Password, user.UserName }); string requestBody = serializer.Serialize(newUser); const string route = "/api/v1/users"; // Act (HttpResponseMessage httpResponse, string responseDocument) = await _testContext.ExecutePostAsync <string>(route, requestBody); // Assert httpResponse.Should().HaveStatusCode(HttpStatusCode.Created); User responseUser = GetResponseDeserializer().DeserializeSingle <User>(responseDocument).Data; var document = JsonConvert.DeserializeObject <Document>(responseDocument); document.SingleData.Attributes.Should().NotContainKey("password"); document.SingleData.Attributes["userName"].Should().Be(newUser.UserName); await _testContext.RunOnDatabaseAsync(async dbContext => { User userInDatabase = await dbContext.Users.FirstWithIdAsync(responseUser.Id); userInDatabase.UserName.Should().Be(newUser.UserName); userInDatabase.Password.Should().Be(newUser.Password); }); }
/// <summary> /// Send a new <see cref="JobRequest"/> (serialized into an <see cref="IMessage"/>) to the queue handled by this instance /// </summary> /// <param name="type">Type of request</param> /// <param name="payload">Data to pass into generated <see cref="IMessage"/></param> /// <param name="messageLabel">Human-readable name for generated <see cref="IMessage"/></param> public virtual IMessage SendJob(string type, object payload, string messageLabel) { var request = new JobRequest { Type = type, Payload = _formatter.Write(payload), }; var bodyStream = _serializer.Serialize(request); var message = _messageFactory.Create(bodyStream, messageLabel); var msg = _queue.Send(message); return(msg); }
public async Task Can_update_user_password() { // Arrange User existingUser = _fakers.User.Generate(); await _testContext.RunOnDatabaseAsync(async dbContext => { dbContext.Users.Add(existingUser); await dbContext.SaveChangesAsync(); }); existingUser.Password = _fakers.User.Generate().Password; IRequestSerializer serializer = GetRequestSerializer <User>(user => new { user.Password }); string requestBody = serializer.Serialize(existingUser); string route = $"/api/v1/users/{existingUser.Id}"; // Act (HttpResponseMessage httpResponse, Document responseDocument) = await _testContext.ExecutePatchAsync <Document>(route, requestBody); // Assert httpResponse.Should().HaveStatusCode(HttpStatusCode.OK); responseDocument.SingleData.Attributes.Should().NotContainKey("password"); responseDocument.SingleData.Attributes["userName"].Should().Be(existingUser.UserName); await _testContext.RunOnDatabaseAsync(async dbContext => { User userInDatabase = await dbContext.Users.FirstWithIdAsync(existingUser.Id); userInDatabase.Password.Should().Be(existingUser.Password); }); }
internal override string Serialize(IRequestSerializer requestSerializer) { return(requestSerializer.Serialize(this.request)); }