コード例 #1
0
        public void PostBootstrapp_Action_Should_NotBe_Invoked_IfExceptions_AndThrow()
        {
            string content = string.Empty;
            var    b       = new Bootstrapper(strict: false, checkOptimal: false, throwExceptionOnErrorNotif: true);
            var    s       = new Mock <IBootstrapperService>();

            s.SetupGet(m => m.ServiceType).Returns(BootstrapperServiceType.Other);
            s.Setup(m => m.BootstrappAction).Returns(m =>
            {
                content += "Hello ";
            });
            b.AddNotification(new BootstrapperNotification {
                Type = BootstrapperNotificationType.Error
            });
            b.AddService(s.Object);
            b.OnPostBootstrapping += (_) => content += "World!";

            try
            {
                b.Bootstrapp();
            }
            catch
            {
                //No need to handle exc
            }

            content.Should().Be("Hello ");
        }
コード例 #2
0
        public void Bootstrapp_Should_Throw_Exception_On_Error_If_Desired()
        {
            var bootstrapper = new Bootstrapper(true, false, true);

            bootstrapper.AddNotification(new BootstrapperNotification(BootstrapperNotificationType.Error, ""));

            Assert.Throws <BootstrappingException>(() => bootstrapper.Bootstrapp());
        }
コード例 #3
0
        public void PostBootstrapp_Action_Should_Be_Invoked_With_GeneratedNotifications()
        {
            string content = string.Empty;
            var    b       = new Bootstrapper();
            var    s       = new Mock <IBootstrapperService>();

            s.SetupGet(m => m.ServiceType).Returns(BootstrapperServiceType.Other);
            s.Setup(m => m.BootstrappAction).Returns(m =>
            {
                content += "Hello ";
            });
            b.AddService(s.Object);
            b.AddNotification(new BootstrapperNotification(BootstrapperNotificationType.Info, "data"));
            b.OnPostBootstrapping += (c) => content += c.Notifications.First().Message;

            b.Bootstrapp();

            content.Should().Be("Hello data");
        }
コード例 #4
0
        public void Bootstrapp_Should_Returns_CustomNotification_To_System_Ones()
        {
            var bootstrapper = new Bootstrapper();

            bootstrapper.AddIoCRegistration(new TypeRegistration(typeof(object), typeof(object)));

            bootstrapper.AddNotification(new BootstrapperNotification(BootstrapperNotificationType.Error, "error message"));

            var notifs = bootstrapper.Bootstrapp().OrderBy(n => n.ContentType).ToList();

            notifs.Should().HaveCount(2);
            notifs[0].Type.Should().Be(BootstrapperNotificationType.Error);
            notifs[0].ContentType.Should().Be(BootstapperNotificationContentType.IoCRegistrationsHasBeenMadeButNoIoCService);
            notifs[0].Message.Should().BeNullOrWhiteSpace();

            notifs[1].Type.Should().Be(BootstrapperNotificationType.Error);
            notifs[1].ContentType.Should().Be(BootstapperNotificationContentType.CustomServiceNotification);
            notifs[1].Message.Should().Be("error message");
        }