public void Indeed()
        {
            var container = CompositionRoot.Get();

            var host = (IDiagnosticsHost)container.Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey);
            var misconfigurations = host.GetDiagnostic <IPotentialLifestyleMismatchesDiagnostic>().Inspect();

            if (misconfigurations.Any())
            {
                var diagnosticOutput = new StringBuilder();

                diagnosticOutput.AppendLine("Following dependency chains have inconsistent accessibility:" + Environment.NewLine);

                foreach (var misconfiguration in misconfigurations)
                {
                    diagnosticOutput.AppendLine(
                        string.Join(
                            " -> ",
                            misconfiguration
                            .Where(m => m.ComponentModel.Services.Any())
                            .Select(m => $"{m.ComponentModel.Services.First().Name} ({m.ComponentModel.LifestyleType})")));
                }

                Assert.Fail(diagnosticOutput.ToString());
            }
        }
Ejemplo n.º 2
0
        public void Indeed()
        {
            var coreServices = new[] {
                "Lansky.CloselyWatchedCompositionRoot.ImapMailReceiver"
            };

            var container = CompositionRoot.Get();

            var services          = container.Kernel.GraphNodes.Where(n => n is ComponentModel).Cast <ComponentModel>();
            var usefulServices    = new HashSet <ComponentModel>();
            var servicesToProcess = new Stack <ComponentModel>(
                services.Where(service =>
                               coreServices.Any(coreService =>
                                                service.ComponentName.Name == coreService)));

            while (servicesToProcess.TryPop(out var service))
            {
                usefulServices.Add(service);

                foreach (var subservice in service.Dependents.Where(n => n is ComponentModel).Cast <ComponentModel>())
                {
                    servicesToProcess.Push(subservice);
                }
            }

            var unusefulServices = new HashSet <ComponentModel>(services);

            unusefulServices.ExceptWith(usefulServices);

            Assert.AreEqual(0, unusefulServices.Count, "Following services are registered and are not needed: " + string.Join(", ", unusefulServices));
        }
Ejemplo n.º 3
0
        public void Indeed()
        {
            var container = CompositionRoot.Get();

            var host = (IDiagnosticsHost)container.Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey);
            var misconfigurations = host.GetDiagnostic <IPotentiallyMisconfiguredComponentsDiagnostic>().Inspect();

            if (misconfigurations.Any())
            {
                var diagnosticOutput = new StringBuilder();

                foreach (IExposeDependencyInfo problem in misconfigurations)
                {
                    problem.ObtainDependencyDetails(new DependencyInspector(diagnosticOutput));
                }

                Assert.Fail(diagnosticOutput.ToString());
            }
        }
Ejemplo n.º 4
0
        public void Indeed()
        {
            var container = CompositionRoot.Get();

            var host     = (IDiagnosticsHost)container.Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey);
            var locators = host.GetDiagnostic <IUsingContainerAsServiceLocatorDiagnostic>().Inspect();

            if (locators.Any())
            {
                var diagnosticOutput = new StringBuilder();

                diagnosticOutput.AppendLine("Following components looks suspiciously like a service locator:" + Environment.NewLine);
                foreach (var locator in locators)
                {
                    diagnosticOutput.AppendLine(locator.ToString());
                }

                Assert.Fail(diagnosticOutput.ToString());
            }
        }
 public void Indeed(Type t)
 {
     CompositionRoot.Get().Resolve(t);
 }