Esempio n. 1
0
        /// <summary>
        /// 1. 직렬화된 정보를 <see cref="RequestSerializer"/>를 이용하여, 역직렬화를 수행. <see cref="XdsRequestDocument"/>를 빌드<br/>
        /// 2. 요청정보를  <see cref="XmlDataManager"/>에 전달하여, 실행 후, 응답정보를 반환 받음<br/>
        /// 3. 응답정보를 <see cref="ResponseSerializer"/>를 통해 직렬화하여 byte[] 로 반환함.
        /// </summary>
        /// <param name="requestBytes">직렬화된 요청 Data</param>
        /// <returns>응답정보를 직렬화한 byte[]</returns>
        public virtual byte[] Execute(byte[] requestBytes)
        {
            if (IsDebugEnabled)
            {
                log.Debug("XML 포맷 방식의 정보를 처리를 시작합니다... IXmlDataManager=[{0}]", XmlDataManager);
            }

            requestBytes.ShouldNotBeNull("requestBytes");

            try {
                var requestMsg          = RequestSerializer.Deserialize(requestBytes);
                var XdsResponseDocument = XmlDataManager.Execute(requestMsg);
                var responseBytes       = ResponseSerializer.Serialize(XdsResponseDocument);

                if (IsDebugEnabled)
                {
                    log.Debug("요청을 모두 처리하고, 응답 정보를 포맷으로 반환합니다!!!");
                }

                return(responseBytes);
            }
            catch (Exception ex) {
                if (log.IsErrorEnabled)
                {
                    log.ErrorException("요청 처리 중 예외가 발생했습니다.", ex);
                }

                return(ResponseSerializer.Serialize(XmlDataTool.CreateResponseWithError(ex)));
            }
        }
Esempio n. 2
0
        public HubSpotContactClientTest(ITestOutputHelper output) : base(output)
        {
            _mockHttpClient = A.Fake <IRapidHttpClient>(opts => opts.Strict());

            A.CallTo(() => _mockHttpClient.SendAsync(A <HttpRequestMessage> .Ignored))
            .Returns(Task.FromResult(CreateNewEmptyOkResponse()));

            _mockSerializer = A.Fake <RequestSerializer>(opts => opts.Strict());
            A.CallTo(() => _mockSerializer.SerializeEntity(A <ContactHubSpotEntity> .Ignored))
            .Returns("{}");

            A.CallTo(() => _mockSerializer.DeserializeEntity <ContactHubSpotEntity>(A <string> .Ignored))
            .Returns(new ContactHubSpotEntity());

            A.CallTo(() => _mockSerializer.DeserializeListEntity <ContactListHubSpotEntity <ContactHubSpotEntity> >(A <string> .Ignored))
            .Returns(new ContactListHubSpotEntity <ContactHubSpotEntity>());

            _client = new HubSpotContactClient(
                _mockHttpClient,
                Logger,
                _mockSerializer,
                "https://api.hubapi.com",
                "HapiKeyFisk"
                );
        }
Esempio n. 3
0
 /// <summary>
 /// Mockable and container ready constructor
 /// </summary>
 /// <param name="httpClient"></param>
 /// <param name="logger"></param>
 /// <param name="serializer"></param>
 /// <param name="hubSpotBaseUrl"></param>
 /// <param name="apiKey"></param>
 public HubSpotListOfContactsClient(
     IRapidHttpClient httpClient,
     ILogger <HubSpotListOfContactsClient> logger,
     RequestSerializer serializer,
     string hubSpotBaseUrl,
     string apiKey)
     : base(httpClient, logger, serializer, hubSpotBaseUrl, apiKey)
 {
 }
 /// <summary>
 /// Mockable and container ready constructor
 /// </summary>
 /// <param name="httpClient"></param>
 /// <param name="logger"></param>
 /// <param name="serializer"></param>
 /// <param name="hubSpotBaseUrl"></param>
 /// <param name="apiKey"></param>
 public HubSpotCompanyPropertiesClient(
     IRapidHttpClient httpClient,
     ILogger <HubSpotCompanyClient> logger,
     RequestSerializer serializer,
     string hubSpotBaseUrl,
     string apiKey)
     : base(httpClient, logger, serializer, hubSpotBaseUrl, apiKey)
 {
 }
        public async ValueTask <HttpResponseMessage> EmitRequest(HttpRequestMessage request)
        {
            using (var connection = await Tunnel.GetConnection())
            {
                await RequestSerializer.SerializeAsync(request, await connection.GetWriteStream());

                return(await ResponseSerializer.DeserializeAsync(await connection.GetReadStream()));
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Mockable and container ready constructor
 /// </summary>
 /// <param name="httpClient"></param>
 /// <param name="logger"></param>
 /// <param name="serializer"></param>
 /// <param name="hubSpotBaseUrl"></param>
 /// <param name="apiKey"></param>
 public HubSpotAssociationsClient(
     IRapidHttpClient httpClient,
     ILogger logger,
     RequestSerializer serializer,
     string hubSpotBaseUrl,
     string apiKey)
     : base(httpClient, logger, serializer, hubSpotBaseUrl, apiKey)
 {
 }
Esempio n. 7
0
        public Response <TxSessionCredentials> TemporaryLogin(TemporaryLoginRequest request)
        {
            var response = client.PostAsync(TEMPORARY_ORGANIZER_LOGIN, RequestSerializer.Content(request)).Result;

            if (response.IsSuccessStatusCode)
            {
                return(Newtonsoft.Json.JsonConvert.DeserializeObject <Response <TxSessionCredentials> >(response.Content.ReadAsStringAsync().Result));
            }
            return(new Response <TxSessionCredentials>(response.RequestMessage.ToString(), (int)response.StatusCode));
        }
Esempio n. 8
0
        public Response <EmptyResponse> CreateTournament(CreateTournamentRequest request)
        {
            var response = client.PostAsync("tournament", RequestSerializer.Content(request)).Result;

            if (response.IsSuccessStatusCode)
            {
                return(Newtonsoft.Json.JsonConvert.DeserializeObject <Response <EmptyResponse> >(response.Content.ReadAsStringAsync().Result));
            }
            return(new Response <EmptyResponse>(response.RequestMessage.ToString(), (int)response.StatusCode));
        }
        public void ThenItShouldReturnValidXml(ProviderQueryRequest request)
        {
            var serializer = new RequestSerializer();

            var actual = serializer.Serialize(request);

            XDocument doc = null;

            Assert.DoesNotThrow(() => doc = XDocument.Parse(actual));
            Assert.IsNotNull(doc);
        }
Esempio n. 10
0
        public Response <TxSessionCredentials> Login(AdminLoginRequest request)
        {
            var response = client.PostAsync(ADMIN_LOGIN, RequestSerializer.Content(request)).Result;

            if (response.IsSuccessStatusCode)
            {
                var userResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <Response <TxSessionCredentials> >(response.Content.ReadAsStringAsync().Result);
                return(userResponse);
            }
            return(new Response <TxSessionCredentials>(response.RequestMessage.ToString(), (int)response.StatusCode));
        }
Esempio n. 11
0
        public Response <GetAccessTokenResponse> GenerateTemporaryOrganizer(TxSessionCredentials credentials, GenerateTemporaryOrganizerRequest request)
        {
            client.DefaultRequestHeaders.Add("SessionId", credentials.SessionId);
            var response = client.PostAsync(TEMPORARY_ORGANIZER, RequestSerializer.Content(request)).Result;

            if (response.IsSuccessStatusCode)
            {
                return(Newtonsoft.Json.JsonConvert.DeserializeObject <Response <GetAccessTokenResponse> >(response.Content.ReadAsStringAsync().Result));
            }

            return(new Response <GetAccessTokenResponse>(response.RequestMessage.ToString(), (int)response.StatusCode));
        }
Esempio n. 12
0
        public RequestProvider(
            RequestSerializer serializer,
            Navigator navigator)
        {
            this.serializer = serializer;
            this.navigator  = navigator;

            navigator.WhenSelected()
            .Where(f => f != null && !f.IsDirectory)
            .Where(f => f.Path.EndsWith(".req"))
            .Subscribe(ObserveSelection);
        }
Esempio n. 13
0
        protected byte[] Serialize <T>(T resource) where T : class
        {
            byte[] result;

            using (var stream = RequestSerializer.Serialize(resource))
            {
                result = new byte[stream.Length];
                stream.Read(result, 0, result.Length);
            }

            return(result);
        }
Esempio n. 14
0
        public Response <EmptyResponse> UpdatePlayer(TxSessionCredentials credentials, PlayerRequest request)
        {
            client.DefaultRequestHeaders.Add("UserId", credentials.UserId);
            client.DefaultRequestHeaders.Add("SessionId", credentials.SessionId);
            var response = client.PostAsync($"players/{request.Id}/notifications", RequestSerializer.Content(request)).Result;

            if (response.IsSuccessStatusCode)
            {
                return(Newtonsoft.Json.JsonConvert.DeserializeObject <Response <EmptyResponse> >(response.Content.ReadAsStringAsync().Result));
            }
            return(new Response <EmptyResponse>(response.RequestMessage.ToString(), (int)response.StatusCode));
        }
Esempio n. 15
0
 protected HubSpotBaseClient(
     IRapidHttpClient httpClient,
     ILogger logger,
     RequestSerializer serializer,
     string hubSpotBaseUrl,
     string apiKey)
 {
     HttpClient     = httpClient;
     Logger         = logger;
     _serializer    = serializer;
     HubSpotBaseUrl = hubSpotBaseUrl.TrimEnd('/');
     _apiKey        = apiKey;
 }
Esempio n. 16
0
 public void Message(ClientSession session, MessageRequest request)
 {
     if (session.HasLobby && session.HasChat)
     {
         var chatLobby   = ChatLobbyManager.GetLobby(session.ChatLobbyId);
         var chatSession = chatLobby.GetSession(session.ChatSessionId);
         var data        = RequestSerializer.Serialize <RequestBase>(request);
         if (chatSession != null)
         {
             chatSession.SendToSpecificMember(session.RemoteEndPoint, data);
         }
     }
 }
Esempio n. 17
0
        public async Task TestTempLogin()
        {
            // Arrange
            var request = new TemporaryLoginRequest("x1ckkk", TEST_EMAIL);

            // Act
            var client   = _testHostFixture.Client;
            var response = await client.PostAsync("/api/organizer/login", RequestSerializer.Content(request));

            // Assert
            response
            .StatusCode
            .Should()
            .Be(HttpStatusCode.OK);
        }
Esempio n. 18
0
        public async Task TestGrantAccessToken_WrongPostBody()
        {
            // Arrange
            var request = new GenerateTemporaryOrganizerRequest();

            // Act
            var client   = _testHostFixture.Client;
            var response = await client.PostAsync("/api/organizer/accessToken", RequestSerializer.Content(request));

            // Assert
            response
            .StatusCode
            .Should()
            .Be(HttpStatusCode.BadRequest);
        }
Esempio n. 19
0
        public async Task TestGrantAccessToken()
        {
            // Arrange
            var request = new GenerateTemporaryOrganizerRequest(TEST_TOURNAMENT_ID, TEST_NAME, TEST_EMAIL);

            // Act
            var client   = _testHostFixture.ClientWithMockedAuthorization();
            var response = await client.PostAsync("/api/organizer/accessToken", RequestSerializer.Content(request));

            // Assert
            response
            .StatusCode
            .Should()
            .Be(HttpStatusCode.OK);
        }
        public async Task TestAdminLogin()
        {
            // Arrange
            var request = new AdminLoginRequest("ToTheMoon2018");

            // Act
            var client   = _testHostFixture.Client;
            var response = await client.PostAsync("/api/admin/login", RequestSerializer.Content(request));

            // Assert
            response
            .StatusCode
            .Should()
            .Be(HttpStatusCode.OK);
        }
        public async Task TestAdminLogin_WrongPostBodyCredentials()
        {
            // Arrange
            var request = new AdminLoginRequest("bar");

            // Act
            var client   = _testHostFixture.Client;
            var response = await client.PostAsync("/api/admin/login", RequestSerializer.Content(request));

            // Assert
            response
            .StatusCode
            .Should()
            .Be(HttpStatusCode.BadRequest);
        }
        public async Task RunAsync(CancellationToken cancellationToken)
        {
            while (true)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var connection = await Tunnel.GetConnection(cancellationToken);

                var task = Task.Run(async() =>
                {
                    var request  = await RequestSerializer.DeserializerAsync(await connection.GetReadStream(cancellationToken), cancellationToken);
                    var response = await Handler.ProcessRequest(request, cancellationToken);
                    await ResponseSerializer.SerializeAsync(response, await connection.GetWriteStream(cancellationToken), cancellationToken);
                });
            }
        }
        public void ThenItShouldIncludeTheRequestQueryId(ProviderQueryRequest request)
        {
            var serializer = new RequestSerializer();

            var actual = serializer.Serialize(request);

            var doc            = XDocument.Parse(actual);
            var requestElement = doc?
                                 .Element(RequestSerializer.SoapNs + "Envelope")?
                                 .Element(RequestSerializer.SoapNs + "Body")?
                                 .Element(RequestSerializer.UkrlpNs + "ProviderQueryRequest");
            var expectedElement = requestElement?.Element("QueryId");

            Assert.IsNotNull(expectedElement);
            Assert.AreEqual(request.QueryId.ToString(), expectedElement.Value);
        }
        public async Task TestCreateTournament()
        {
            // Arrange
            int TEST_STYLE_ID = 1;
            int TEST_NUM_OF_STATIONS = 4;
            var request = new CreateTournamentRequest(TEST_TOURNAMENT_ID, TEST_STYLE_ID, TEST_NUM_OF_STATIONS);

            // Act
            var client = _testHostFixture.Client;
            var response = await client.PostAsync("/api/tournament/create", RequestSerializer.Content(request));

            // Assert
            response
            .StatusCode
            .Should()
            .Be(HttpStatusCode.OK);
        }
Esempio n. 25
0
        public async Task <TResp> Request <TReq, TResp>(TReq req)
        {
            if (Message.Method == HttpMethod.Get)
            {
                var querystring = req.ToQueryString();
                Message.RequestUri = new Uri(Message.RequestUri.ToString() + querystring);
            }
            else
            {
                Message.Content = await RequestSerializer.SerializeAsync <TReq>(req);

                var body = await Message.Content.ReadAsStringAsync();
            }
            using (var response = await Client.SendAsync(Message, CancellationToken))
            {
                return(await GetResponse <TResp>(response));
            }
        }
        public void ThenItShouldIncludeApprovedProvidersOnly(ProviderQueryRequest request)
        {
            var serializer = new RequestSerializer();

            var actual = serializer.Serialize(request);

            var doc            = XDocument.Parse(actual);
            var requestElement = doc?
                                 .Element(RequestSerializer.SoapNs + "Envelope")?
                                 .Element(RequestSerializer.SoapNs + "Body")?
                                 .Element(RequestSerializer.UkrlpNs + "ProviderQueryRequest");
            var expectedElement = requestElement?
                                  .Element("SelectionCriteria")?
                                  .Element("ApprovedProvidersOnly");

            Assert.IsNotNull(expectedElement);
            Assert.AreEqual(request.SelectionCriteria.ApprovedProvidersOnly.ToString(), expectedElement.Value);
        }
        public void ThenItShouldWrapTheRequestInASoapPackage(ProviderQueryRequest request)
        {
            var serializer = new RequestSerializer();

            var actual = serializer.Serialize(request);

            XDocument doc = XDocument.Parse(actual);

            Assert.IsNotNull(doc.Root.Name == RequestSerializer.SoapNs + "Envelope");
            Assert.IsNotNull(doc?
                             .Element(RequestSerializer.SoapNs + "Envelope")?
                             .Element(RequestSerializer.SoapNs + "Header"));
            Assert.IsNotNull(doc?
                             .Element(RequestSerializer.SoapNs + "Envelope")?
                             .Element(RequestSerializer.SoapNs + "Body"));
            Assert.IsNotNull(doc?
                             .Element(RequestSerializer.SoapNs + "Envelope")?
                             .Element(RequestSerializer.SoapNs + "Body")?
                             .Element(RequestSerializer.UkrlpNs + "ProviderQueryRequest"));
        }
Esempio n. 28
0
        public void DeserializeTest()
        {
            var id             = 3;
            var rCenterPos     = -0.15;
            var iCenterPos     = 0.0;
            var width          = 2.75;
            var height         = 1.5;
            var pointsDistance = 0.276666;
            var iterations     = Int32.MaxValue;
            var threshold      = 2;


            MemoryStream stream       = new MemoryStream(52);
            var          streamWriter = new BinaryWriter(stream);

            streamWriter.Write(id);             // id
            streamWriter.Write(rCenterPos);     // r center pos
            streamWriter.Write(iCenterPos);     // i center pos
            streamWriter.Write(width);          // width
            streamWriter.Write(height);         // height
            streamWriter.Write(pointsDistance); // distance of points
            streamWriter.Write(iterations);     // iterations
            streamWriter.Write(threshold);      // threshold
            streamWriter.Flush();

            //stream.Read(buffer, 0, 52);
            var buffer = stream.GetBuffer();

            var request = RequestSerializer.Deserialize(buffer);

            Assert.AreEqual(id, request.Id);
            Assert.AreEqual(iCenterPos, request.ImaginaryCenter);
            Assert.AreEqual(rCenterPos, request.RealCenter);
            Assert.AreEqual(width, request.Width);
            Assert.AreEqual(height, request.Height);
            Assert.AreEqual(pointsDistance, request.Resolution);
            Assert.AreEqual(iterations, request.MaxIterations);
            Assert.AreEqual(threshold, request.MaxMagnitude);
        }
Esempio n. 29
0
 public async Task SendRequest(Request request)
 {
     _pendingRequests.Add(request);
     await _endPoint.Send(RequestSerializer.Serialize(request));
 }
Esempio n. 30
0
        public RequestSerializerTests()
        {
            var builder = new ResourceObjectBuilder(ResourceGraph, new ResourceObjectBuilderSettings());

            _serializer = new RequestSerializer(ResourceGraph, builder);
        }