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); }); }
/// <param name="baseUrl">Base url for the rpc server</param> /// <param name="authHeaderValue">Http authentication header for rpc request</param> /// <param name="jsonSerializer">(Optional) Json serializer for serializing requests and deserializing responses. Defaults to built in serializer</param> /// <param name="encoding">(Optional)Encoding type for request. Defaults to UTF-8</param> /// <param name="contentType">(Optional)Content type header for the request. Defaults to application/json</param> /// <param name="headers">(Optional)Extra headers</param> public RpcClient(Uri baseUrl, IRequestSerializer jsonSerializer = null, IRpcTransportClient transportClient = null) { this.BaseUrl = baseUrl; this.JsonSerializer = jsonSerializer ?? new DefaultRequestJsonSerializer(); this.TransportClient = transportClient ?? new HttpRpcTransportClient(); }
public static List <RpcResponse> DeserializeBulk(this IRequestSerializer jsonSerializer, string json, IDictionary <RpcId, Type> resultTypeMap) { return(jsonSerializer.DeserializeBulk(json, GetType)); Type GetType(RpcId id) { resultTypeMap.TryGetValue(id, out Type value); return(value); } }
internal RpcClient(Uri baseUrl, IRpcTransportClient transportClient, IRequestSerializer requestSerializer, RpcEvents events) { this.BaseUrl = baseUrl; this.transportClient = transportClient ?? throw new ArgumentNullException(nameof(transportClient)); this.requestSerializer = requestSerializer ?? throw new ArgumentNullException(nameof(requestSerializer)); this.Events = events ?? throw new ArgumentNullException(nameof(events)); }
/// <summary> /// Initialize a new instance of the <see cref="MsmqJobQueueFactory"/> /// </summary> /// <param name="payloadFormatter">Formats object payloads added to queue</param> /// <param name="requestSerializer">Deserializes payload coming from the queue</param> /// <param name="accessControlList">Specifies users and their access to the queue</param> public MsmqJobQueueFactory( IPayloadFormatter payloadFormatter, IRequestSerializer requestSerializer, System.Messaging.AccessControlList accessControlList = null) { _queueFactory = new MsmqMessageQueueFactory(accessControlList); _messageFactory = new MsmqMessageFactory(); _payloadFormatter = payloadFormatter; _requestSerializer = requestSerializer; }
public RequestQueuer( TQueueConfig queueConfig, ILogger <RequestQueuer <TQueueConfig> > logger, IRequestSerializer requestSerializer) { this.producer = new Producer <string, string>(queueConfig.ProducerSettings, new StringSerializer(Encoding.UTF8), new StringSerializer(Encoding.UTF8)); this.queueConfig = queueConfig; this.logger = logger; this.requestSerializer = requestSerializer; }
internal UkrlpSoapApiClient( HttpClient httpClient, UkrlpApiConfiguration configuration, ILogger <UkrlpSoapApiClient> logger, IRequestSerializer requestSerializer, IResponseDeserializer responseDeserializer) { _httpClient = httpClient; _httpClient.BaseAddress = new Uri(configuration.WebServiceUrl, UriKind.Absolute); _configuration = configuration; _logger = logger; _requestSerializer = requestSerializer; _responseDeserializer = responseDeserializer; }
/// <summary> /// Initializes a new instance of the <see cref="JobQueue"/> class /// </summary> /// <param name="queueFactory">Factory for creating the queue</param> /// <param name="messageFactory">Factory for creating new messages</param> /// <param name="formatter">Formatter for formatting payloads</param> /// <param name="serializer">Serializer for serializing requests</param> /// <param name="handlerConfiguration">Configuration creating handlers (used to copy into a <see cref="QueueCreationOptions"/> object</param> public JobQueue( IMessageQueueFactory queueFactory, IMessageFactory messageFactory, IPayloadFormatter formatter, IRequestSerializer serializer, HandlerConfiguration handlerConfiguration) { if (handlerConfiguration == null) { throw new ArgumentNullException(nameof(handlerConfiguration)); } _messageQueueFactory = queueFactory ?? throw new ArgumentNullException(nameof(queueFactory)); _messageFactory = messageFactory ?? throw new ArgumentNullException(nameof(messageFactory)); _formatter = formatter ?? throw new ArgumentNullException(nameof(formatter)); _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); _queue = _messageQueueFactory.Create(handlerConfiguration.ToQueueCreationOptions()); _queue.ReceivedMessage += OnReceivedJob; }
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 (List <RpcResponse>, RpcBulkResponse) Deserialize(string responseJson, IRequestSerializer requestSerializer) { IDictionary <RpcId, Type> typeMap = this.request.GetTypeMap(); var responses = requestSerializer.Deserialize(responseJson, typeMap); return(responses, RpcBulkResponse.FromResponses(responses)); }
internal override string Serialize(IRequestSerializer requestSerializer) { return(requestSerializer.SerializeBulk(this.request.GetRequests())); }
internal override string Serialize(IRequestSerializer requestSerializer) { return(requestSerializer.Serialize(this.request)); }
internal override (List <RpcResponse>, RpcResponse <TResponse>) Deserialize(string responseJson, IRequestSerializer requestSerializer) { var typeMap = new Dictionary <RpcId, Type> { [this.request.Id] = typeof(TResponse) }; var responses = requestSerializer.Deserialize(responseJson, typeMap); return(responses, RpcResponse <TResponse> .FromResponse(responses.Single())); }
internal abstract (List <RpcResponse>, TResponse) Deserialize(string responseJson, IRequestSerializer requestSerializer);
internal abstract string Serialize(IRequestSerializer requestSerializer);
public new HttpRpcClientBuilder UsingRequestSerializer(IRequestSerializer requestSerializer) { return((HttpRpcClientBuilder)base.UsingRequestSerializer(requestSerializer)); }
public static RpcResponse <T> Deserialize <T>(this IRequestSerializer jsonSerializer, string json) { return((RpcResponse <T>)jsonSerializer.Deserialize(json, typeof(T))); }
public static List <RpcResponse <T> > DeserializeBulk <T>(this IRequestSerializer jsonSerializer, string json) { return(jsonSerializer.DeserializeBulk(json, id => typeof(T)) .Cast <RpcResponse <T> >() .ToList()); }
public PostHttpRequestBuilderCommand(string methodName, IRequestSerializer requestSerializer) { _methodName = methodName; _requestSerializer = requestSerializer; }
public RequestBuilderCommandFactory(IVerbPrefixes verbPrefixes, IRequestBaseNameStrategy requestBaseNameStrategy, IRequestSerializer requestSerializer) { _verbPrefixes = verbPrefixes; _requestBaseNameStrategy = requestBaseNameStrategy; _requestSerializer = requestSerializer; }