예제 #1
0
        public void CheckIfHasValidRestAllowedOperationsWithDisabledGet()
        {
            RestAllowedOperations expectedAllowedOperations = new RestModelOptionsBuilder()
                                                              .WithDisabledGet()
                                                              .AllowedOperations;
            RestAllowedOperations testAllowedOperations = typeof(ClassWithDisabledGetForGetRestAllowedOperationsTest)
                                                          .GetRestAllowedOperations();

            Assert.Equal(expectedAllowedOperations, testAllowedOperations);
        }
예제 #2
0
        public void CheckIfTypeIsRegisteredWithValidAllowedOperations()
        {
            RestRegistry          registry = new RestRegistry();
            Type                  testType = typeof(ClassForRestRegistryTest);
            RestAllowedOperations testTypeAllowedOperations = RestAllowedOperations.All;
            RestRegistryEntry     testTypeEntry             = new RestRegistryEntry(testType, testTypeAllowedOperations);

            registry.Register(testTypeEntry);
            RestRegistryEntry registeredEntry = registry.Entries
                                                .Single(e => e.Type == testType);

            Assert.Equal(testTypeAllowedOperations, registeredEntry.AllowedOperations);
        }
예제 #3
0
        public void CheckIfTypeIsRegistered()
        {
            RestRegistry          registry = new RestRegistry();
            Type                  testType = typeof(ClassForRestRegistryTest);
            RestAllowedOperations testTypeAllowedOperations = RestAllowedOperations.All;
            RestRegistryEntry     testTypeEntry             = new RestRegistryEntry(testType, testTypeAllowedOperations);

            registry.Register(testTypeEntry);
            RestRegistryEntry registeredEntry = registry.Entries
                                                .SingleOrDefault(e => e.Type == testType);

            Assert.NotNull(registeredEntry);
        }
        private static RestOptionsBuilder RegisterRestModelTypes(this IServiceCollection services, IEnumerable <Type> modelTypes)
        {
            IRestRegistry restRegistry        = new RestRegistry();
            Type          iDataRepositoryType = typeof(IDataRepository <>);
            Type          dataRepositoryType  = typeof(DataRepository <>);

            foreach (Type modelType in modelTypes)
            {
                RestAllowedOperations modelAllowedOperations = modelType.GetRestAllowedOperations();
                RestRegistryEntry     modelTypeEntry         = new RestRegistryEntry(modelType, modelAllowedOperations);
                restRegistry.Register(modelTypeEntry);
                services.AddScoped(
                    iDataRepositoryType.MakeGenericType(modelType),
                    dataRepositoryType.MakeGenericType(modelType)
                    );
            }

            services.AddSingleton(typeof(IRestRegistry), restRegistry);
            services.AddSingleton <IRestRouter, RestRouter>();
            services.AddRouting();
            RestOptionsBuilder options = new RestOptionsBuilder(restRegistry);

            return(options);
        }
예제 #5
0
        private bool IsOperationAllowed <TModel>(RestAllowedOperations operation) where TModel : RestModel
        {
            RestAllowedOperations modelAllowedOperations = RestRegistry.GetAllowedOperations <TModel>();

            return((modelAllowedOperations & operation) == operation);
        }
예제 #6
0
 public RestRegistryEntry(Type type, RestAllowedOperations allowedOperations)
 {
     Type = type;
     AllowedOperations = allowedOperations;
 }
예제 #7
0
 public RestModelOptionsBuilder(RestAllowedOperations initialAllowedOperations)
 {
     AllowedOperations = initialAllowedOperations;
 }