예제 #1
0
        public async Task OnGetAsync_InvalidId()
        {
            // Arrange
            var model = new PropertiesModel(new Mock <IConfigurationDbContext>().Object);

            // Act

            var get = await model.OnGetAsync(0).ConfigureAwait(false);

            // Assert
            Assert.Null(model.IdentityResource);
            Assert.Null(model.Properties);
            Assert.IsType <NotFoundResult>(get);
        }
예제 #2
0
        public async Task OnGetAsync()
        {
            // Arrange
            var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}";
            var options      = new DbContextOptionsBuilder <OidcDbContext>()
                               .UseInMemoryDatabase(databaseName)
                               .Options;
            var identityResource = new IdentityResource
            {
                Id         = Random.Next(),
                Properties = new List <IdentityResourceProperty>
                {
                    new IdentityResourceProperty(),
                    new IdentityResourceProperty(),
                    new IdentityResourceProperty()
                }
            };
            PropertiesModel model;
            IActionResult   get;

            using (var context = new OidcDbContext(options))
            {
                context.Add(identityResource);
                await context.SaveChangesAsync().ConfigureAwait(false);
            }

            // Act
            using (var context = new OidcDbContext(options))
            {
                model = new PropertiesModel(context);
                get   = await model.OnGetAsync(identityResource.Id).ConfigureAwait(false);
            }

            // Assert
            Assert.NotNull(model.IdentityResource);
            Assert.Equal(identityResource.Id, model.IdentityResource.Id);
            var properties = Assert.IsAssignableFrom <IEnumerable <IdentityResourceProperty> >(model.Properties);

            Assert.Equal(identityResource.Properties.Count, properties.Count());
            Assert.IsType <PageResult>(get);
        }
예제 #3
0
        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(),
                Properties = new List <ClientProperty>
                {
                    new ClientProperty(),
                    new ClientProperty(),
                    new ClientProperty()
                }
            };
            PropertiesModel 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 PropertiesModel(context);
                get   = await model.OnGetAsync(client.Id).ConfigureAwait(false);
            }

            // Assert
            Assert.NotNull(model.Client);
            Assert.Equal(client.Id, model.Client.Id);
            var properties = Assert.IsAssignableFrom <IEnumerable <ClientProperty> >(model.Properties);

            Assert.Equal(client.Properties.Count, properties.Count());
            Assert.IsType <PageResult>(get);
        }
예제 #4
0
        public async Task OnGetAsync_InvalidModel()
        {
            // Arrange
            var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}";
            var options      = new DbContextOptionsBuilder <OidcDbContext>()
                               .UseInMemoryDatabase(databaseName)
                               .Options;
            PropertiesModel model;
            IActionResult   get;

            // Act
            using (var context = new OidcDbContext(options))
            {
                model = new PropertiesModel(context);
                get   = await model.OnGetAsync(Random.Next()).ConfigureAwait(false);
            }

            // Assert
            Assert.Null(model.IdentityResource);
            Assert.Null(model.Properties);
            Assert.IsType <NotFoundResult>(get);
        }