Пример #1
0
        /// <summary>
        /// Deserialises an <see cref="IEntity" /> from the <see cref="NetworkStream" />.
        /// </summary>
        /// <param name="networkStream">The <see cref="NetworkStream" /> containing the serialised <see cref="IEntity" />.</param>
        /// <returns>The deserialised <see cref="IEntity" />.</returns>
        public T Deserialise(NetworkStream networkStream)
        {
            var entity = (T)serialiser.Deserialise(networkStream);

            Log.DebugFormat("Network stream has received data and deserialised to a {0} entity", entity);
            return(entity);
        }
Пример #2
0
        /// <summary>
        /// Deserialises an <see cref="IMessage" /> that has been received.
        /// </summary>
        /// <param name="networkStream">The stream that connects the Client and Server.</param>
        /// <returns>The <see cref="IMessage" /> that was received from the networkStream.</returns>
        public virtual IMessage Deserialise(NetworkStream networkStream)
        {
            var requestMessage = (IMessage)serialiser.Deserialise(networkStream);

            Log.InfoFormat("Network stream has received data and deserialised to a {0} object", requestMessage.MessageIdentifier);
            return(requestMessage);
        }
Пример #3
0
        public async Task <GetResultsResponse> GetResults(string sessionId, string jobCategory)
        {
            var url         = $"{httpClient.BaseAddress}/result/{sessionId}/{jobCategory}";
            var jsonContent = await httpClient.GetStringAsync(url).ConfigureAwait(false);

            var resultsResponse = serialiser.Deserialise <GetResultsResponse>(jsonContent);

            return(resultsResponse);
        }
Пример #4
0
        public async Task <NewSessionResponse> NewSession(string assessmentType)
        {
            var url = $"{httpClient.BaseAddress}/assessment?assessmentType={assessmentType}";

            using (var postData = new StringContent(string.Empty))
            {
                var result = await httpClient.PostAsync(url, postData).ConfigureAwait(false);

                result.EnsureSuccessStatusCode();
                var contentResponse = await result.Content.ReadAsStringAsync().ConfigureAwait(false);

                return(serialiser.Deserialise <NewSessionResponse>(contentResponse));
            }
        }
        public void Deserialise_WithXml_ReturnsExpectedModel()
        {
            // Arrange
            var expectedModel = new ModelContext
            {
                Id    = new Guid("FE715B9E-FACC-4353-BCB1-BEC1B313423A"),
                Value = 5
            };

            var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ModelContext xmlns=\"http://api.esendex.com/ns/\" Id=\"fe715b9e-facc-4353-bcb1-bec1b313423a\"><Value>5</Value></ModelContext>";

            // Act
            var actualModel = serialiser.Deserialise <ModelContext>(xml);

            // Assert
            Assert.IsNotNull(actualModel);
            Assert.AreEqual(actualModel.Id, actualModel.Id);
            Assert.AreEqual(actualModel.Value, actualModel.Value);
        }
Пример #6
0
 public static T Deserialise <T>(string path)
 {
     CheckFileFormat(path);
     return(serialiser.Deserialise <T>(path));
 }