public void GetService_GenericAndSpecificRegistered_ReturnsSpecificService()
        {
            // Arrange

            var loggerFactory = new NullLoggerFactory();

            var logger = new Logger <CouchbaseServiceProvider>(loggerFactory);

            var provider = new CouchbaseServiceProvider(new[]
            {
                new KeyValuePair <Type, IServiceFactory>(typeof(ILoggerFactory), new SingletonServiceFactory(loggerFactory)),
                new KeyValuePair <Type, IServiceFactory>(typeof(ILogger <>), new SingletonGenericServiceFactory(typeof(Logger <>))),
                new KeyValuePair <Type, IServiceFactory>(typeof(ILogger <CouchbaseServiceProvider>), new SingletonServiceFactory(logger))
            });

            // Act

            var result = provider.GetService(typeof(ILogger <CouchbaseServiceProvider>));

            // Assert

            Assert.NotNull(result);
            var resultLogger = Assert.IsAssignableFrom <Logger <CouchbaseServiceProvider> >(result);

            Assert.Equal(logger, resultLogger);
        }
        public void GetService_IServiceProvider_ReturnsSelf()
        {
            // Arrange

            var provider = new CouchbaseServiceProvider(new KeyValuePair <Type, IServiceFactory>[] { });

            // Act

            var result = provider.GetService(typeof(IServiceProvider));

            // Assert

            Assert.Equal(provider, result);
        }
        public void GetServiceT_Unregistered_ReturnsNull()
        {
            // Arrange

            var provider = new CouchbaseServiceProvider(new KeyValuePair <Type, IServiceFactory>[] { });

            // Act

            var result = provider.GetService <IList <object> >();

            // Assert

            Assert.Null(result);
        }
        public void GetService_SingletonRegistered_ReturnsService()
        {
            // Arrange

            var obj     = new object();
            var factory = new SingletonServiceFactory(obj);

            var provider = new CouchbaseServiceProvider(new[]
            {
                new KeyValuePair <Type, IServiceFactory>(typeof(object), factory)
            });

            // Act

            var result = provider.GetService(typeof(object));

            // Assert

            Assert.Equal(obj, result);
        }
        public void GetServiceT_LambdaRegistered_ReturnsService()
        {
            // Arrange

            var obj     = new List <object>();
            var factory = new TransientServiceFactory(_ => obj);

            var provider = new CouchbaseServiceProvider(new[]
            {
                new KeyValuePair <Type, IServiceFactory>(typeof(IList <object>), factory)
            });

            // Act

            var result = provider.GetService <IList <object> >();

            // Assert

            Assert.Equal(obj, result);
        }
        public void GetService_LambdaRegistered_LambdaGetsServiceProvider()
        {
            // Arrange

            IServiceProvider?calledWith = null;
            var factory = new TransientServiceFactory(serviceProvider => {
                calledWith = serviceProvider;
                return(null);
            });

            var provider = new CouchbaseServiceProvider(new[]
            {
                new KeyValuePair <Type, IServiceFactory>(typeof(object), factory)
            });

            // Act

            provider.GetService(typeof(object));

            // Assert

            Assert.Equal(provider, calledWith);
        }