Beispiel #1
0
 public Configuration()
 {
     IdentifierFactory = new DefaultIdentifierFactory();
     ContentSerializer = new JsonContentSerializer();
     IsolationLevel    = IsolationLevel.ReadCommitted;
     TablePrefix       = "";
     SessionPoolSize   = 16;
 }
        public void ShouldThrowExceptionOnSerialization()
        {
            // Arrange
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act & Assert
            Should.Throw<ArgumentNullException>(() => serializer.Serialize((object)null));
        }
Beispiel #3
0
        private static FluentClient CreateClient(FakeResponseMode mode = FakeResponseMode.Capture)
        {
            var serializer = new JsonContentSerializer();
            var fakeHttp = new FakeMessageHandler { Mode = mode };

            var client = new FluentClient(serializer, fakeHttp);
            return client;
        }
        public void ShouldThrowExceptionOnSerialization()
        {
            // Arrange
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act & Assert
            Should.Throw <ArgumentNullException>(() => serializer.Serialize((object)null));
        }
Beispiel #5
0
 public DefaultApiRequestSettings()
 {
     ParameterListTransformers = new DefaultParameterListTransformers();
     InsertMissingSlashBetweenBaseLocationAndVerbAttributeUrl = true;
     EncodeUrlSegmentSeparatorsInUrlSegmentSubstitutions      = false;
     ContentSerializer          = new JsonContentSerializer(new Newtonsoft.Json.JsonSerializer());
     ParameterValueFormatter    = new DefaultParameterValueFormatter();
     QueryParameterListStrategy = new NormalQueryParamaterListStrategy();
 }
        public void SerializeNullItemThrows()
        {
            var message    = new HttpRequestMessage();
            var serializer = new JsonContentSerializer();

            Assert.Throws <ArgumentNullException>
            (
                () => serializer.Serialize <Uom>(message, null)
            );
        }
Beispiel #7
0
 public Configuration()
 {
     IdentifierFactory  = new DefaultIdentifierFactory();
     ContentSerializer  = new JsonContentSerializer();
     IsolationLevel     = IsolationLevel.ReadCommitted;
     TablePrefix        = "";
     SessionPoolSize    = 16;
     QueryGatingEnabled = true;
     LinearBlockSize    = 20;
 }
        public void SerializeNullMessageThrows()
        {
            var uom        = new Uom();
            var serializer = new JsonContentSerializer();

            Assert.Throws <ArgumentNullException>
            (
                () => serializer.Serialize <Uom>(null, uom)
            );
        }
Beispiel #9
0
 public Configuration()
 {
     IdentifierFactory  = new DefaultIdentifierFactory();
     ContentSerializer  = new JsonContentSerializer();
     IdGenerator        = new DefaultIdGenerator();
     IsolationLevel     = IsolationLevel.ReadCommitted;
     TablePrefix        = "";
     SessionPoolSize    = 16;
     QueryGatingEnabled = true;
     Logger             = NullLogger.Instance;
 }
        public void ShouldDeserializeObject()
        {
            // Arrange
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act
            var resource = serializer.Deserialize <Resource>("{\"name\":\"foo\"}");

            // Assert
            serializer.Serialize(resource).ShouldBe("{\"name\":\"foo\"}");
        }
Beispiel #11
0
        private static FluentClient CreateClient(FakeResponseMode mode = FakeResponseMode.Capture)
        {
            var serializer = new JsonContentSerializer();
            var fakeHttp   = new FakeMessageHandler {
                Mode = mode
            };

            var client = new FluentClient(serializer, fakeHttp);

            return(client);
        }
        public void ShouldDeserializeObject()
        {
            // Arrange
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act
            var resource = serializer.Deserialize<Resource>("{\"name\":\"foo\"}");

            // Assert
            serializer.Serialize(resource).ShouldBe("{\"name\":\"foo\"}");
        }
        public void ShouldThrowExceptionOnDeserialization()
        {
            // Arrange
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act
            var resource = new { resource = new List<Resource>() };

            // Act & Assert
            Should.Throw<ArgumentNullException>(() => serializer.Deserialize(null, resource));
            Should.Throw<ArgumentNullException>(() => serializer.Deserialize<object>((string)null));
        }
        public void ShouldThrowExceptionOnDeserialization()
        {
            // Arrange
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act
            var resource = new { resource = new List <Resource>() };

            // Act & Assert
            Should.Throw <ArgumentNullException>(() => serializer.Deserialize(null, resource));
            Should.Throw <ArgumentNullException>(() => serializer.Deserialize <object>((string)null));
        }
        private static FluentClient CreateClient()
        {
            var serializer = new JsonContentSerializer();

            var fakeStore = MemoryMessageStore.Current;
            var fakeHttp = new FakeMessageHandler(fakeStore, FakeResponseMode.Fake);

            var client = new FluentClient(serializer, fakeHttp);
            client.BaseUri = new Uri("http://httpbin.org/", UriKind.Absolute);

            return client;
        }
Beispiel #16
0
        private static IFluentClient CreateClient()
        {
            var serializer = new JsonContentSerializer();

            var httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri("https://maps.googleapis.com/maps/api/", UriKind.Absolute);

            var fluentClient = new FluentClient(httpClient, serializer);

            return(fluentClient);
        }
        public void ShouldDeserializeAnonymousObject()
        {
            // Arrange
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act
            var resource = new { resource = new List<Resource>() };
            resource = serializer.Deserialize(TestJson, resource);

            // Assert
            serializer.Serialize(resource).ShouldBe(TestJson);
        }
        public void ShouldSerializeObject()
        {
            // Arrange
            var resources = new { resource = CreateTestObject() };
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act
            string json = serializer.Serialize(resources);

            // Assert
            json.ShouldBe(TestJson);
        }
        public void ShouldSerializeObject()
        {
            // Arrange
            var resources = new { resource = CreateTestObject() };
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act
            string json = serializer.Serialize(resources);

            // Assert
            json.ShouldBe(TestJson);
        }
Beispiel #20
0
        private static FluentClient CreateClient()
        {
            var contentSerializer = new JsonContentSerializer();

            var httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri("https://api.github.com/", UriKind.Absolute);

            var fluentClient = new FluentClient(httpClient, contentSerializer);

            return(fluentClient);
        }
        public async Task SerializeSucceeds()
        {
            var expectedItem = new Uom(1, "TheUom", "TheDescription");
            var message      = new HttpRequestMessage();
            var serializer   = new JsonContentSerializer();

            serializer.Serialize <Uom>(message, expectedItem);
            var deserializer = new JsonContentDeserializer();
            var actualItem   = await deserializer.DeserializeAsync <Uom>(message.Content);

            Assert.True(UomEqual.Check(expectedItem, actualItem));
        }
        private static FluentClient CreateClient()
        {
            var serializer = new JsonContentSerializer();

            var fakeStore = MemoryMessageStore.Current;
            var fakeHttp  = new FakeMessageHandler(fakeStore, FakeResponseMode.Fake);

            var client = new FluentClient(serializer, fakeHttp);

            client.BaseUri = new Uri("http://httpbin.org/", UriKind.Absolute);

            return(client);
        }
Beispiel #23
0
        protected ISaveItemService <TItem> BuildSaveItemService <TItem>(IComponentContext context)
            where TItem : class, IEntity
        {
            var httpService = BuildWriteHttpService(context);
            var serializer  = new JsonContentSerializer();
            var saveItemServiceBuildRequest = new SaveItemServiceBuildRequest <TItem>(httpService, serializer);
            var itemUrlBuilder          = context.Resolve <IItemWriteUrlBuilder <TItem> >();
            var saveItemServiceBuildUrl = new SaveItemServiceBuildUrl <TItem>(itemUrlBuilder, saveItemServiceBuildRequest);
            var validator = new Validator();
            var saveItemServiceValidator = new SaveItemServiceValidate <TItem>(validator, saveItemServiceBuildUrl);

            return(new SaveItemService <TItem>(saveItemServiceValidator));
        }
        public void ShouldDeserializeAnonymousObject()
        {
            // Arrange
            JsonContentSerializer serializer = new JsonContentSerializer();

            // Act
            var resource = new { resource = new List <Resource>() };

            resource = serializer.Deserialize(TestJson, resource);

            // Assert
            serializer.Serialize(resource).ShouldBe(TestJson);
        }
Beispiel #25
0
 public Configuration()
 {
     IdentifierAccessorFactory = new PropertyAccessorFactory("Id");
     VersionAccessorFactory    = new PropertyAccessorFactory("Version");
     ContentSerializer         = new JsonContentSerializer();
     IdGenerator         = new DefaultIdGenerator();
     IsolationLevel      = IsolationLevel.ReadCommitted;
     TablePrefix         = "";
     CommandsPageSize    = 500;
     QueryGatingEnabled  = true;
     Logger              = NullLogger.Instance;
     ConcurrentTypes     = new HashSet <Type>();
     TableNameConvention = new DefaultTableNameConvention();
 }
Beispiel #26
0
        private static FluentClient CreateClient()
        {
            var serializer = new JsonContentSerializer();

            var fakeStore = new FileMessageStore();
            fakeStore.StorePath = @".\GitHub\Responses";

            var fakeHttp = new FakeMessageHandler(fakeStore, FakeResponseMode.Fake);

            var client = new FluentClient(serializer, fakeHttp);
            client.BaseUri = new Uri("https://api.github.com/", UriKind.Absolute);

            return client;
        }
Beispiel #27
0
        private static FluentClient CreateClient()
        {
            var serializer = new JsonContentSerializer();

            var fakeStore = new FileMessageStore();

            fakeStore.StorePath = @".\GitHub\Responses";

            var fakeHttp = new FakeMessageHandler(fakeStore, FakeResponseMode.Fake);

            var client = new FluentClient(serializer, fakeHttp);

            client.BaseUri = new Uri("https://api.github.com/", UriKind.Absolute);

            return(client);
        }
Beispiel #28
0
        public ConfigureRefit(IServiceCollection services)
        {
            _services = services;
            var serializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                }
            };
            var serializer = new JsonContentSerializer(serializerSettings);

            _settings = new RefitSettings
            {
                ContentSerializer = serializer
            };
        }
Beispiel #29
0
        public void ThenResponseContentIsComposedByAllFieldsWithValue(int id)
        {
            //arrange
            var responseObject = new Post()
            {
                Id = 2, Body = "2", Title = "2", UserId = "2"
            };

            MemoryMessageStore.Current.Register(b => b
                                                .Url($"{apiUrl}/posts/{id}")
                                                .StatusCode(HttpStatusCode.OK)
                                                .ReasonPhrase("OK")
                                                .Content(c => c
                                                         .Header("Content-Type", "application/json; charset=utf-8")
                                                         .Data(responseObject) // object to be JSON serialized
                                                         )
                                                );

            // use memory store by default
            var serializer = new JsonContentSerializer();
            var fakeHttp   = new FakeMessageHandler();
            var client     = new FluentClient(serializer, fakeHttp);

            client.BaseUri = new Uri(apiUrl, UriKind.Absolute);

            //act
            response = client.GetAsync(b => b
                                       .AppendPath("posts")
                                       .AppendPath(id.ToString())).Result;

            //assert
            Assert.NotNull(response);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            result = response.DeserializeAsync <Post>().Result;
            Assert.NotNull(result);
            Assert.AreEqual(id, result.Id);
            Assert.AreEqual(id.ToString(), result.Title);
            Assert.AreEqual(id.ToString(), result.UserId);
            Assert.AreEqual(id.ToString(), result.Body);
        }
        public IApi Create(string authUserToken, string authAccessToken, string endpointAddress)
        {
            var httpClientHandler = new AuthenticatedHttpClientHandler(authUserToken, authAccessToken);

            var httpClient = new HttpClient(httpClientHandler)
            {
                BaseAddress = new Uri(endpointAddress)
            };

            var jsonSerializerSettings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.None
            };

            var contentSerializer = new JsonContentSerializer(jsonSerializerSettings);

            var refitSettings = new RefitSettings
            {
                ContentSerializer = contentSerializer
            };

            return(RestService.For <IApi>(httpClient, refitSettings));
        }
Beispiel #31
0
    public SampleRequestHandler MakeHandler()
    {
        IContentSerializer requestSerializer;
        IContentSerializer responseSerializer;

        if (RequestSerializer == SerializerType.Json)
        {
            requestSerializer = new JsonContentSerializer();
        }
        else
        {
            requestSerializer = new MessagePackContentSerializer();
        }

        if (ResponseSerializer == SerializerType.Json)
        {
            responseSerializer = new JsonContentSerializer();
        }
        else
        {
            responseSerializer = new MessagePackContentSerializer();
        }

        var client = new HttpClient();

        client.DefaultRequestHeaders.Add("User-Agent", "TestAgent");

        var nozomi = new NozomiClient(client, BaseAddress, requestSerializer, responseSerializer);

        if (AuthToken != null)
        {
            nozomi.client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AuthToken);
        }
        var requestHandler = new SampleRequestHandler(nozomi);

        return(requestHandler);
    }
 internal RestClientResourceBase(IHttpClientCreator httpClientCreator, string path)
 {
     HttpClientCreator = httpClientCreator;
     Path       = path;
     Serializer = new JsonContentSerializer();
 }
 public JamFilesReader()
 {
     JamInfoSerializer = new JsonContentSerializer <JamInfo>();
 }
Beispiel #34
0
 public JamFilesWriter()
 {
     JamInfoSerializer = new JsonContentSerializer <JamInfo>();
     EntryFilesWriter  = new JamEntryFilesWriter();
 }
Beispiel #35
0
 public ExporterInfoFilesWriter()
 {
     ExporterInfoSerializer = new JsonContentSerializer <ExporterInfo>();
 }
 public JamRankingFilesWriter()
 {
     JamRankingInfoSerializer = new JsonContentSerializer <JamRankingInfo>();
 }