Пример #1
0
        public void AddTokenManager_ThrowsAnExceptionForInvalidManager()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddOptions();

            var builder = new OpenIddictBuilder(services);

            builder.TokenType = typeof(object);

            // Act and assert
            var exception = Assert.Throws <InvalidOperationException>(() => builder.AddTokenManager(typeof(object)));

            Assert.Equal("Custom managers must be derived from OpenIddictTokenManager.", exception.Message);
        }
        public void AddTokenManager_OverridesDefaultManager()
        {
            // Arrange
            var services = new ServiceCollection();

            services.AddOptions();

            var builder = new OpenIddictBuilder(services);

            builder.TokenType = typeof(object);

            var type = new Mock <OpenIddictTokenManager <object> >(
                Mock.Of <IOpenIddictTokenStore <object> >(),
                Mock.Of <ILogger <OpenIddictTokenManager <object> > >()).Object.GetType();

            // Act
            builder.AddTokenManager(type);

            var provider = services.BuildServiceProvider();
            var manager  = provider.GetRequiredService <OpenIddictTokenManager <object> >();

            // Assert
            Assert.IsType(type, manager);
        }