Example #1
0
        public void ResourceConfigurationsBuilder_Resource_PassCustomName_ShouldUsePassedTypeNameAsIs()
        {
            var builder = new ResourceConfigurationsBuilder();

            builder.Resource <ResourceWithAttribute>("driver");
            var config = builder.Build();
            var type   = config[typeof(ResourceWithAttribute)];

            Assert.That(type.TypeName, Is.EqualTo("driver"));
        }
Example #2
0
        public void ResourceConfigurationsBuilder_Resource_DontPassName_ShouldGeneratePluralizedTypeName()
        {
            var builder = new ResourceConfigurationsBuilder();

            builder.Resource <User>();
            var config = builder.Build();
            var type   = config[typeof(User)];

            Assert.That(type.TypeName, Is.EqualTo("users"));
        }
Example #3
0
        public void ResourceConfigurationsBuilder_ResourceWithNameAttribute_ShouldGeneratePluralizedTypeName()
        {
            var builder = new ResourceConfigurationsBuilder();

            builder.Resource <ResourceWithAttribute>();
            var config = builder.Build();
            var type   = config[typeof(ResourceWithAttribute)];

            Assert.That(type.TypeName, Is.EqualTo("cars"));
        }
Example #4
0
        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            var resourceConfig = new ResourceConfigurationsBuilder();

            resourceConfig
            .Resource <Car>();

            resourceConfig
            .Resource <Driver>()
            .BelongsTo <Car>(x => x.CarId);

            config.UseJsonApi(o =>
            {
                o.ResourceConfigurations = resourceConfig.Build();
            });

            config.MapHttpAttributeRoutes();
            app.UseWebApi(config);
        }