public void CopyConstructor()
        {
            // Act
            var copy = new MessagePackMediaTypeFormatter(_formatter);

            // Assert
            Assert.Same(_serializerOptions, copy.SerializerOptions);
        }
        public void DefaultConstructor()
        {
            // Act
            var formatter = new MessagePackMediaTypeFormatter();

            // Assert
            Assert.NotNull(formatter.SerializerOptions);
        }
Esempio n. 3
0
        /// <summary>
        /// Client constructor Auth credentials / ApiKey can be passed through config
        /// </summary>
        /// <param name="config">Config</param>
        /// <param name="Url">String</param>
        /// /// <param name="policy">String</param>
        public Client(IArtesianServiceConfig config, string Url, ArtesianPolicyConfig policy)
        {
            _url    = config.BaseAddress.ToString().AppendPathSegment(Url);
            _apiKey = config.ApiKey;
            _config = config;

            var cfg = new JsonSerializerSettings();

            cfg                  = cfg.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
            cfg                  = cfg.ConfigureForDictionary();
            cfg                  = cfg.ConfigureForNodaTimeRanges();
            cfg.Formatting       = Formatting.Indented;
            cfg.ContractResolver = new DefaultContractResolver();
            cfg.Converters.Add(new StringEnumConverter());
            cfg.TypeNameHandling       = TypeNameHandling.None;
            cfg.ObjectCreationHandling = ObjectCreationHandling.Replace;

            var jsonFormatter = new JsonMediaTypeFormatter
            {
                SerializerSettings = cfg
            };

            _jsonFormatter = jsonFormatter;
            _jsonFormatter.SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/problem+json"));

            _msgPackFormatter    = new MessagePackMediaTypeFormatter(CustomCompositeResolver.Instance);
            _lz4msgPackFormatter = new LZ4MessagePackMediaTypeFormatter(CustomCompositeResolver.Instance);
            //Order of formatters important for correct weight in accept header
            var formatters = new MediaTypeFormatterCollection();

            formatters.Clear();
            formatters.Add(_lz4msgPackFormatter);
            formatters.Add(_msgPackFormatter);
            formatters.Add(_jsonFormatter);
            _formatters = formatters;

            _resilienceStrategy = policy.GetResillianceStrategy();

            if (config.ApiKey == null)
            {
                var domain = new Uri(config.Domain);

                var tenantId = domain.Segments
                               .Select(s => s.Trim('/'))
                               .Where(w => !string.IsNullOrWhiteSpace(w))
                               .FirstOrDefault();

                _confidentialClientApplication = ConfidentialClientApplicationBuilder
                                                 .Create(config.ClientId)
                                                 .WithTenantId(tenantId)
                                                 .WithClientSecret(config.ClientSecret)
                                                 .Build();
            }

            _client = new FlurlClient(_url);
            _client.WithTimeout(TimeSpan.FromMinutes(ArtesianConstants.ServiceRequestTimeOutMinutes));
        }
        public void ConstructorWithOptions()
        {
            // Arrange
            var options = MessagePackSerializerOptions.Standard;

            // Act
            var formatter = new MessagePackMediaTypeFormatter(options);

            // Assert
            Assert.Same(options, formatter.SerializerOptions);
        }
        public static void SetUp()
        {
            data = new Url
            {
                UrlId     = 1,
                Address   = "http://webapicontrib.github.com/",
                Title     = "Web API Contrib",
                CreatedAt = DateTime.Now,
                CreatedBy = "Me",
            };

            formatter = new MessagePackMediaTypeFormatter();

            content = new ObjectContent <Url>(data, formatter);
        }
 public MessagePackMediaTypeFormatterTest()
 {
     _serializerOptions = MessagePackSerializerOptions.Standard;
     _content           = new StreamContent(new MemoryStream());
     _formatter         = new MessagePackMediaTypeFormatter(_serializerOptions);
 }
 public FunctionalTest()
 {
     _options   = MessagePackSerializerOptions.Standard;
     _formatter = new MessagePackMediaTypeFormatter(_options);
 }