public void CheckIfHasValidRestAllowedOperationsWithDisabledGet() { RestAllowedOperations expectedAllowedOperations = new RestModelOptionsBuilder() .WithDisabledGet() .AllowedOperations; RestAllowedOperations testAllowedOperations = typeof(ClassWithDisabledGetForGetRestAllowedOperationsTest) .GetRestAllowedOperations(); Assert.Equal(expectedAllowedOperations, testAllowedOperations); }
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); }
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); }
private bool IsOperationAllowed <TModel>(RestAllowedOperations operation) where TModel : RestModel { RestAllowedOperations modelAllowedOperations = RestRegistry.GetAllowedOperations <TModel>(); return((modelAllowedOperations & operation) == operation); }
public RestRegistryEntry(Type type, RestAllowedOperations allowedOperations) { Type = type; AllowedOperations = allowedOperations; }
public RestModelOptionsBuilder(RestAllowedOperations initialAllowedOperations) { AllowedOperations = initialAllowedOperations; }