Exemplo n.º 1
0
        public void UseDefaultResourceInspectors_GetSet()
        {
            var options = new HalOptions();

            options.UseDefaultResourceInspectors = false;
            Assert.IsFalse(options.UseDefaultResourceInspectors);
        }
Exemplo n.º 2
0
        public static IHalBuilder AddHal(this IServiceCollection services, Action <HalOptions> optionsAction)
        {
            var options = new HalOptions();

            optionsAction.Invoke(options);

            throw new NotImplementedException();
        }
Exemplo n.º 3
0
        public void SupportedMediaTypes_GetSet()
        {
            var options    = new HalOptions();
            var mediaTypes = new List <string>();

            options.SupportedMediaTypes = mediaTypes;
            Assert.AreSame(mediaTypes, options.SupportedMediaTypes);
        }
Exemplo n.º 4
0
        public void ResourceInspectors_GetSet()
        {
            var options    = new HalOptions();
            var inspectors = Mock.Of <IList <IHalResourceInspectorMetadata> >();

            options.ResourceInspectors = inspectors;
            Assert.AreSame(inspectors, options.ResourceInspectors);
        }
Exemplo n.º 5
0
        public void SupportedMediaTypes_DefaultHalJson()
        {
            var options    = new HalOptions();
            var mediaTypes = options.SupportedMediaTypes;

            Assert.AreEqual(1, mediaTypes.Count);
            Assert.AreEqual("application/hal+json", mediaTypes.First());
        }
Exemplo n.º 6
0
        public void Configure_UseDefaultResourceInspectorsFalse_DoesNotAddResourceInspectors()
        {
            var resourceFactory = ResourceFactory.Object;
            IConfigureOptions <HalOptions> setup = new HalSetup(ServiceProvider.Object, resourceFactory);
            var options = new HalOptions
            {
                UseDefaultResourceInspectors = false
            };

            setup.Configure(options);
            Assert.AreEqual(0, options.ResourceInspectors.Count);
        }
Exemplo n.º 7
0
        public void Configure_UseDefaultResourceInspectors_AddsResourceValidationInspector()
        {
            var services = new ServiceCollection();

            services.AddMvcCore();
            services.AddLogging();
            services.AddSingleton(Mock.Of <LinkService>());
            var provider = services.BuildServiceProvider();
            IConfigureOptions <HalOptions> setup = new HalSetup(provider, ResourceFactory.Object);
            var options = new HalOptions
            {
                UseDefaultResourceInspectors = true
            };

            setup.Configure(options);
            Assert.That(options.ResourceInspectors, Has.One.InstanceOf <ResourceValidationInspector>());
        }
Exemplo n.º 8
0
        public HalJsonOutputFormatter(
            JsonSerializerSettings serializerSettings,
            ArrayPool <char> charPool,
            HalOptions options)
            : base(serializerSettings, charPool)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            this.SupportedMediaTypes.Clear();
            if (options.SupportedMediaTypes != null)
            {
                foreach (var mediaType in options.SupportedMediaTypes)
                {
                    this.SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(mediaType));
                }
            }
        }
 public ResourceInspectorSelector(HalOptions options)
 {
     this.options = options
                    ?? throw new ArgumentNullException(nameof(options));
 }
Exemplo n.º 10
0
        public void UseDefaultResourceInspectors_DefaultTrue()
        {
            var options = new HalOptions();

            Assert.IsTrue(options.UseDefaultResourceInspectors);
        }
Exemplo n.º 11
0
        public void ResourceInspectors_ThrowsIfNull()
        {
            var options = new HalOptions();

            Assert.Throws <ArgumentNullException>(() => options.ResourceInspectors = null);
        }
Exemplo n.º 12
0
        public void ResourceInspectors_DefaultInitialized()
        {
            var options = new HalOptions();

            Assert.NotNull(options.ResourceInspectors);
        }
Exemplo n.º 13
0
        public void SupportedMediaTypes_ThrowsIfNull()
        {
            var options = new HalOptions();

            Assert.Throws <ArgumentNullException>(() => options.SupportedMediaTypes = null);
        }