Ejemplo n.º 1
0
        public async Task OnGetAsync_InvalidId()
        {
            // Arrange
            var model = new CorsOriginsModel(new Mock <IConfigurationDbContext>().Object);

            // Act

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

            // Assert
            Assert.Null(model.Client);
            Assert.Null(model.CorsOrigins);
            Assert.IsType <NotFoundResult>(get);
        }
Ejemplo n.º 2
0
        public async Task OnGetAsync()
        {
            // Arrange
            var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync)}";
            var options      = new DbContextOptionsBuilder <OidcDbContext>()
                               .UseInMemoryDatabase(databaseName)
                               .Options;
            var client = new Client
            {
                Id = Random.Next(),
                AllowedCorsOrigins = new List <ClientCorsOrigin>
                {
                    new ClientCorsOrigin(),
                    new ClientCorsOrigin(),
                    new ClientCorsOrigin()
                }
            };
            CorsOriginsModel 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 CorsOriginsModel(context);
                get   = await model.OnGetAsync(client.Id).ConfigureAwait(false);
            }

            // Assert
            Assert.NotNull(model.Client);
            Assert.Equal(client.Id, model.Client.Id);
            var corsOrigins = Assert.IsAssignableFrom <IEnumerable <ClientCorsOrigin> >(model.CorsOrigins);

            Assert.Equal(client.AllowedCorsOrigins.Count, corsOrigins.Count());
            Assert.IsType <PageResult>(get);
        }
Ejemplo n.º 3
0
        public async Task OnGetAsync_InvalidModel()
        {
            // Arrange
            var databaseName = $"{DatabaseNamePrefix}.{nameof(OnGetAsync_InvalidModel)}";
            var options      = new DbContextOptionsBuilder <OidcDbContext>()
                               .UseInMemoryDatabase(databaseName)
                               .Options;
            CorsOriginsModel model;
            IActionResult    get;

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

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