Exemplo n.º 1
0
        public void CheckIfExceptionThrownOnInvalidTypeRegister()
        {
            RestRegistry      registry = new RestRegistry();
            RestRegistryEntry entry    = new RestRegistryEntry(typeof(string), RestAllowedOperations.All);

            Assert.Throws <ArgumentException>(() =>
            {
                registry.Register(entry);
            });
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }