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

            // Act

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

            // Assert
            Assert.Null(model.Client);
            Assert.Null(model.RedirectUris);
            Assert.IsType <NotFoundResult>(get);
        }
Exemple #2
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(),
                RedirectUris = new List <ClientRedirectUri>
                {
                    new ClientRedirectUri(),
                    new ClientRedirectUri(),
                    new ClientRedirectUri()
                }
            };
            RedirectUrisModel 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 RedirectUrisModel(context);
                get   = await model.OnGetAsync(client.Id).ConfigureAwait(false);
            }

            // Assert
            Assert.NotNull(model.Client);
            Assert.Equal(client.Id, model.Client.Id);
            var redirectUris = Assert.IsAssignableFrom <IEnumerable <ClientRedirectUri> >(model.RedirectUris);

            Assert.Equal(client.RedirectUris.Count, redirectUris.Count());
            Assert.IsType <PageResult>(get);
        }
Exemple #3
0
        public async Task OnGetAsync_InvalidModel()
        {
            // Arrange
            var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}";
            var options      = new DbContextOptionsBuilder <IdentityServerDbContext>()
                               .UseInMemoryDatabase(databaseName)
                               .Options;
            RedirectUrisModel model;
            IActionResult     get;

            // Act
            using (var context = new IdentityServerDbContext(options, _configurationStoreOptions.Object, _operationalStoreOptions.Object))
            {
                model = new RedirectUrisModel(context);
                get   = await model.OnGetAsync(Random.Next()).ConfigureAwait(false);
            }

            // Assert
            Assert.Null(model.Client);
            Assert.Null(model.RedirectUris);
            Assert.IsType <NotFoundResult>(get);
        }