public void Collection_is_invalid_when_dependency_is_missing()
        {
            var services = GetEmptyServiceCollection();

            services.AddScoped <Wrapper>();

            ServicesValidator.IsValid(services).Should().BeFalse();
        }
        public void Validator_evaluates_complex_dependencies_correctly()
        {
            var services = GetEmptyServiceCollection();

            services.AddScoped <Dependency>();
            services.AddScoped <Wrapper>((x) => new Wrapper(x.GetService <Dependency>()));

            ServicesValidator.IsValid(services).Should().BeTrue();
        }
        public void Collection_is_valid_when_all_dependencies_are_registered()
        {
            var services = GetEmptyServiceCollection();

            services.AddScoped <Wrapper>();
            services.AddScoped <Dependency>();

            ServicesValidator.IsValid(services).Should().BeTrue();
        }
        public void Diagnostic_output_shows_information_about_missing_dependency_and_misconfigured_class()
        {
            var services = GetEmptyServiceCollection();

            services.AddScoped <Wrapper>();

            var result = ServicesValidator.IsValid(services, out var diagnostics);

            result.Should().BeFalse();
            diagnostics.Should().Contain($"{nameof(Dependency)}");
            diagnostics.Should().Contain($"{nameof(Wrapper)}");
        }
        public void Collection_is_valid_when_class_with_missing_dependency_is_ignored()
        {
            var services = GetEmptyServiceCollection();

            services.AddScoped <Wrapper>();
            var classesNotToBeAnalyzed = new List <Type>()
            {
                typeof(Wrapper)
            };

            var result = ServicesValidator.IsValid(services, classesNotToBeAnalyzed);

            result.Should().BeTrue();
        }
        public void Collection_is_valid_when_missing_dependency_is_ignored()
        {
            var services = GetEmptyServiceCollection();

            services.AddScoped <Wrapper>();
            var dependenciesToSkip = new List <Type>()
            {
                typeof(Dependency)
            };

            var result = ServicesValidator.IsValid(services,
                                                   dependenciesToSkip: dependenciesToSkip);

            result.Should().BeTrue();
        }
        public void Collection_is_invalid_when_class_is_missing_dependency_and_is_itself_ignored_as_missing_dependency()
        {
            var services = GetEmptyServiceCollection();

            services.AddScoped <Wrapper>();
            var dependenciesToSkip = new List <Type>()
            {
                typeof(Wrapper)
            };

            var result = ServicesValidator.IsValid(services,
                                                   dependenciesToSkip: dependenciesToSkip);

            result.Should().BeFalse();
        }
        public void Collection_is_valid_when_missing_dependency_is_skipped_and_set_not_to_be_analyzed()
        {
            var services = GetEmptyServiceCollection();

            services.AddScoped <Wrapper>();
            var classesNotToBeAnalyzed = new List <Type>()
            {
                typeof(Dependency)
            };

            var result = ServicesValidator.IsValid(services,
                                                   classesNotToBeAnalyzed,
                                                   classesNotToBeAnalyzed);

            result.Should().BeTrue();
        }