Ejemplo n.º 1
0
        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);
            });
        }
Ejemplo n.º 2
0
 /// <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();
 }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
 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));
 }
Ejemplo n.º 5
0
 /// <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;
 }
Ejemplo n.º 6
0
 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;
        }
Ejemplo n.º 8
0
        /// <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;
        }
Ejemplo n.º 9
0
        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);
            });
        }
Ejemplo n.º 10
0
            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));
            }
Ejemplo n.º 11
0
 internal override string Serialize(IRequestSerializer requestSerializer)
 {
     return(requestSerializer.SerializeBulk(this.request.GetRequests()));
 }
Ejemplo n.º 12
0
 internal override string Serialize(IRequestSerializer requestSerializer)
 {
     return(requestSerializer.Serialize(this.request));
 }
Ejemplo n.º 13
0
            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()));
            }
Ejemplo n.º 14
0
 internal abstract (List <RpcResponse>, TResponse) Deserialize(string responseJson, IRequestSerializer requestSerializer);
Ejemplo n.º 15
0
 internal abstract string Serialize(IRequestSerializer requestSerializer);
Ejemplo n.º 16
0
 public new HttpRpcClientBuilder UsingRequestSerializer(IRequestSerializer requestSerializer)
 {
     return((HttpRpcClientBuilder)base.UsingRequestSerializer(requestSerializer));
 }
Ejemplo n.º 17
0
 public static RpcResponse <T> Deserialize <T>(this IRequestSerializer jsonSerializer, string json)
 {
     return((RpcResponse <T>)jsonSerializer.Deserialize(json, typeof(T)));
 }
Ejemplo n.º 18
0
 public static List <RpcResponse <T> > DeserializeBulk <T>(this IRequestSerializer jsonSerializer, string json)
 {
     return(jsonSerializer.DeserializeBulk(json, id => typeof(T))
            .Cast <RpcResponse <T> >()
            .ToList());
 }
Ejemplo n.º 19
0
 public PostHttpRequestBuilderCommand(string methodName, IRequestSerializer requestSerializer)
 {
     _methodName        = methodName;
     _requestSerializer = requestSerializer;
 }
Ejemplo n.º 20
0
 public RequestBuilderCommandFactory(IVerbPrefixes verbPrefixes, IRequestBaseNameStrategy requestBaseNameStrategy, IRequestSerializer requestSerializer)
 {
     _verbPrefixes            = verbPrefixes;
     _requestBaseNameStrategy = requestBaseNameStrategy;
     _requestSerializer       = requestSerializer;
 }