public async Task OnPostAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; IActionResult post; var client = new Client { Id = Random.Next() }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { var scopes = new ScopesModel(context) { Client = new Client { Id = Random.Next() } }; post = await scopes.OnPostAsync().ConfigureAwait(false); } // Assert Assert.IsType <PageResult>(post); }
public async Task OnPostAsync_AllRemoved() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync_AllRemoved)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; ScopesModel scopes; IActionResult post; var clientId = Random.Next(); var client = new Client { Id = clientId, AllowedScopes = new List <ClientScope> { new ClientScope { Id = Random.Next() } } }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { scopes = new ScopesModel(context) { Client = new Client { Id = clientId } }; post = await scopes.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { client = await context.Clients .Include(x => x.AllowedScopes) .SingleOrDefaultAsync(x => x.Id.Equals(clientId)) .ConfigureAwait(false); Assert.Empty(client.AllowedScopes); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/Scopes", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(Client.Id), key); Assert.Equal(scopes.Client.Id, value); }); }
public ActionResult <string> GetScopes() { try { var apiKeyModel = (ApiKey)RouteData.Values[Requests.KEY_PASS_DATA_API_KEY_MODEL]; var arrPermission = apiKeyModel.Permissions.Split(","); var arrCurrency = apiKeyModel.Wallets.Split(","); var scopeModel = new ScopesModel(); if (arrCurrency != null && arrCurrency.Length > 0) { scopeModel.Currencys = arrCurrency.ToList(); } if (arrPermission == null || arrPermission.Length <= 0) { return(CreateDataSuccess(JsonHelper.SerializeObject(scopeModel))); } var listPermissions = new List <string>(); foreach (var item in arrPermission) { if (Commons.Constants.ApiAccess.LIST_API_ACCESS.ContainsKey(item.Trim())) { listPermissions.Add(Commons.Constants.ApiAccess.LIST_API_ACCESS[item.Trim()]); } } scopeModel.Permissions = listPermissions; return(CreateDataSuccess(JsonHelper.SerializeObject(scopeModel))); } catch (Exception) { return(CreateDataSuccess(JsonHelper.SerializeObject(MessageError.SCOPES_ERROR))); } }
public async Task OnPostAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; IActionResult post; var client = new ApiResource { Id = Random.Next() }; using (var context = new OidcDbContext(options)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new OidcDbContext(options)) { var scopes = new ScopesModel(context) { ApiResource = new ApiResource { Id = Random.Next() } }; post = await scopes.OnPostAsync().ConfigureAwait(false); } // Assert Assert.IsType <PageResult>(post); }
public EditScopeViewModel(ConfigurationModel configurationModel, ScopesModel scopesModel, Scope scopeToEdit = null) { this.configurationModel = configurationModel; scope = scopeToEdit ?? new Scope(); isNew = scopeToEdit == null; DisplayName = "Edit Scope"; this.scopesModel = scopesModel; }
public IActionResult Scopes(int id) { var api = _configurationDbContext.ApiResources .Include(x => x.Scopes) .FirstOrDefault(x => x.Id == id); return(View(ScopesModel.FromEntity(api))); }
public ScopesViewModel(ScopesModel scopesModel, ConfigurationModel configurationModel, RiflesModel riflesModel, IWindowManager windowManager, IEventAggregator eventsAggregator) : base(eventsAggregator) { this.scopesModel = scopesModel; this.windowManager = windowManager; this.configurationModel = configurationModel; DisplayName = "Scopes"; this.riflesModel = riflesModel; }
public IActionResult Scopes(int id) { var api = _configurationDbContext.ApiResources .Include(x => x.Scopes) .FirstOrDefault(x => x.Id == id); var apiScopes = _configurationDbContext.ApiScopes.ToList(); var model = ScopesModel.FromEntity(api); model.ApiScopes = apiScopes; return(View(model)); }
public RiflesViewModel(RiflesModel riflesModel, ConfigurationModel configurationModel, AmmoModel cartridgesModel, ScopesModel scopesModel, IWindowManager windowManager, IEventAggregator eventsAggregator) : base(eventsAggregator) { DisplayName = "Rifles"; this.riflesModel = riflesModel; this.configurationModel = configurationModel; this.cartridgesModel = cartridgesModel; this.scopesModel = scopesModel; this.windowManager = windowManager; }
public async Task OnGetAsync_InvalidId() { // Arrange var model = new ScopesModel(new Mock <IConfigurationDbContext>().Object); // Act var get = await model.OnGetAsync(0).ConfigureAwait(false); // Assert Assert.Null(model.Client); Assert.Null(model.Scopes); Assert.IsType <NotFoundResult>(get); }
public async Task OnPostAsync_InvalidId() { // Arrange var context = new Mock <IConfigurationDbContext>(); var scopes = new ScopesModel(context.Object) { Client = new Client { Id = 0 } }; // Act var post = await scopes.OnPostAsync().ConfigureAwait(false); // Assert context.Verify(x => x.SaveChangesAsync(), Times.Never); Assert.IsType <PageResult>(post); }
public EditRifleViewModel(ConfigurationModel configurationModel, AmmoModel cartridgesModel, ScopesModel scopesModel, Rifle rifle = null) { this.cartridgesModel = cartridgesModel; this.scopesModel = scopesModel; this.configurationModel = configurationModel; this.rifle = rifle ?? new Rifle { ZeroingWeather = WeatherCondition.Default }; NotifyOfPropertyChange(() => Scope); NotifyOfPropertyChange(() => Cartridge); DisplayName = "Rifle Settings"; }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; var client = new ApiResource { Id = Random.Next(), Scopes = new List <ApiScope> { new ApiScope(), new ApiScope(), new ApiScope() } }; ScopesModel model; IActionResult get; using (var context = new OidcDbContext(options)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new OidcDbContext(options)) { model = new ScopesModel(context); get = await model.OnGetAsync(client.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.ApiResource); Assert.Equal(client.Id, model.ApiResource.Id); var scopes = Assert.IsAssignableFrom <IEnumerable <ApiScope> >(model.Scopes); Assert.Equal(client.Scopes.Count, scopes.Count()); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; var client = new Client { Id = Random.Next(), AllowedScopes = new List <ClientScope> { new ClientScope(), new ClientScope(), new ClientScope() } }; ScopesModel model; IActionResult get; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { model = new ScopesModel(context); get = await model.OnGetAsync(client.Id).ConfigureAwait(false); } // Assert Assert.NotNull(model.Client); Assert.Equal(client.Id, model.Client.Id); var scopes = Assert.IsAssignableFrom <IEnumerable <ClientScope> >(model.Scopes); Assert.Equal(client.AllowedScopes.Count, scopes.Count()); Assert.IsType <PageResult>(get); }
public async Task OnGetAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; ScopesModel model; IActionResult get; // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { model = new ScopesModel(context); get = await model.OnGetAsync(Random.Next()).ConfigureAwait(false); } // Assert Assert.Null(model.Client); Assert.Null(model.Scopes); Assert.IsType <NotFoundResult>(get); }
public async Task OnGetAsync_InvalidModel() { // Arrange var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; ScopesModel model; IActionResult get; // Act using (var context = new OidcDbContext(options)) { model = new ScopesModel(context); get = await model.OnGetAsync(Random.Next()).ConfigureAwait(false); } // Assert Assert.Null(model.ApiResource); Assert.Null(model.Scopes); Assert.IsType <NotFoundResult>(get); }
public async Task OnPostAsync() { // Arrange const string scope1OriginalScope = "Original Scope"; const string scope1EditedScope = "Edited Scope"; const string newScopeScope = "New Scope"; var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <IdentityServerDbContext>() .UseInMemoryDatabase(databaseName) .Options; ScopesModel scopes; IActionResult post; var scope1 = new ClientScope { Id = Random.Next(), Scope = scope1OriginalScope }; var scope2 = new ClientScope { Id = Random.Next() }; var clientId = Random.Next(); var client = new Client { Id = clientId, AllowedScopes = new List <ClientScope> { scope1, scope2 } }; using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { scopes = new ScopesModel(context) { Client = new Client { Id = clientId, AllowedScopes = new List <ClientScope> { new ClientScope { Id = scope1.Id, Scope = scope1EditedScope }, new ClientScope { Scope = newScopeScope } } } }; post = await scopes.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object)) { client = await context.Clients .Include(x => x.AllowedScopes) .SingleOrDefaultAsync(x => x.Id.Equals(clientId)) .ConfigureAwait(false); scope1 = client.AllowedScopes.SingleOrDefault(x => x.Id.Equals(scope1.Id)); scope2 = client.AllowedScopes.SingleOrDefault(x => x.Id.Equals(scope2.Id)); var newScope = client.AllowedScopes.SingleOrDefault(x => x.Scope.Equals(newScopeScope)); Assert.NotNull(scope1); Assert.Equal(scope1EditedScope, scope1.Scope); Assert.Null(scope2); Assert.NotNull(newScope); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/Scopes", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(Client.Id), key); Assert.Equal(scopes.Client.Id, value); }); }
public async Task OnPostAsync() { // Arrange const string scope1OriginalName = "Original Name"; const string scope1EditedName = "Edited Name"; const string newScopeName = "New Name"; var databaseName = $"{DatabaseNamePrefix}.{nameof(OnPostAsync)}"; var options = new DbContextOptionsBuilder <OidcDbContext>() .UseInMemoryDatabase(databaseName) .Options; ScopesModel scopes; IActionResult post; var scope1 = new ApiScope { Id = Random.Next(), Name = scope1OriginalName }; var scope2 = new ApiScope { Id = Random.Next() }; var client = new ApiResource { Id = Random.Next(), Scopes = new List <ApiScope> { scope1, scope2 } }; using (var context = new OidcDbContext(options)) { context.Add(client); await context.SaveChangesAsync().ConfigureAwait(false); } // Act using (var context = new OidcDbContext(options)) { scopes = new ScopesModel(context) { ApiResource = new ApiResource { Id = client.Id, Scopes = new List <ApiScope> { new ApiScope { Id = scope1.Id, Name = scope1EditedName }, new ApiScope { Name = newScopeName } } } }; post = await scopes.OnPostAsync().ConfigureAwait(false); } // Assert using (var context = new OidcDbContext(options)) { client = await context.ApiResources .Include(x => x.Scopes) .SingleOrDefaultAsync(x => x.Id.Equals(client.Id)) .ConfigureAwait(false); scope1 = client.Scopes.SingleOrDefault(x => x.Id.Equals(scope1.Id)); scope2 = client.Scopes.SingleOrDefault(x => x.Id.Equals(scope2.Id)); var newScope = client.Scopes.SingleOrDefault(x => x.Name.Equals(newScopeName)); Assert.NotNull(scope1); Assert.Equal(scope1EditedName, scope1.Name); Assert.Null(scope2); Assert.NotNull(newScope); } var result = Assert.IsType <RedirectToPageResult>(post); Assert.Equal("../Details/Scopes", result.PageName); Assert.Collection(result.RouteValues, routeValue => { var(key, value) = routeValue; Assert.Equal(nameof(ApiResource.Id), key); Assert.Equal(scopes.ApiResource.Id, value); }); }