示例#1
0
        public void InheritedDisabledKwyjiboShouldNotThrow()
        {
            var options = new KwyjiboOptions();

            options.ForContext <KwyjiboFixture>()
            .When <IIdentity>(s => s.Name.Contains("kwyjibo"))
            .Throw <SecurityException>();
            options.ForContext("Kwyjibo")
            .Disable();
            var mock = new Mock <IIdentity>();

            mock.SetupGet(i => i.Name).Returns("kwyjibo");

            var builder = new KwyjiboBuilder(options);
            var kwyjibo = builder.Build <KwyjiboFixture>();

            Assert.DoesNotThrow(() => kwyjibo.Assert(mock.Object));
        }
示例#2
0
        public void UnconfiguredContextShouldBeNull()
        {
            var options = new KwyjiboOptions();

            options.ForContext <ContextFixture>()
            .Enable()
            .When <IIdentity>(id => id.Name.Contains("kwyjibo"))
            .Throw <InvalidOperationException>();

            var tree    = new ContextTree(options);
            var context = tree.GetContext <KwyjiboFixture>();

            context.Should().BeNull();
        }
示例#3
0
        public void ContextShouldNotHaveUndefinedHandler()
        {
            var options = new KwyjiboOptions();

            options.ForContext <ContextFixture>()
            .Enable()
            .Named("alien")
            .When <IIdentity>(id => id.Name.Contains("kwyjibo"))
            .Throw <InvalidOperationException>();

            var tree    = new ContextTree(options);
            var context = tree.GetContext <ContextFixture>();
            var handler = context.GetHandler("foobar");

            handler.Should().BeNull();
        }
示例#4
0
        public void KwyjiboShouldThrowWithAdditionalData()
        {
            var options = new KwyjiboOptions();

            options.ForContext <KwyjiboFixture>()
            .When <IIdentity>(s => s.Name.Contains("kwyjibo"))
            .Throw <SecurityException>();
            var mock = new Mock <IIdentity>();

            mock.SetupGet(i => i.Name).Returns("kwyjibo");

            var builder = new KwyjiboBuilder(options);
            var kwyjibo = builder.Build <KwyjiboFixture>();

            Assert.Throws <SecurityException>(() => kwyjibo.Assert(mock.Object));
        }
示例#5
0
        public void KwyjiboThatDoesNotSatisfyPredicateShouldNotThrow()
        {
            var options = new KwyjiboOptions();

            options.ForContext <KwyjiboFixture>()
            .When <IIdentity>(s => false)
            .Throw <SecurityException>();
            var mock = new Mock <IIdentity>();

            mock.SetupGet(i => i.Name).Returns("kwyjibo");

            var builder = new KwyjiboBuilder(options);
            var kwyjibo = builder.Build <KwyjiboFixture>(mock.Object);

            Assert.DoesNotThrow(() => kwyjibo.Assert());
        }
示例#6
0
        private IKwyjibo CreateKwyjibo <TDefinitionContext, TKwyjiboContext>(string name)
        {
            var options = new KwyjiboOptions();

            options.ForContext <TDefinitionContext>()
            .Named(name)
            .When <IIdentity>(s => s.Name.Contains("kwyjibo"))
            .Throw <SecurityException>();
            var mock = new Mock <IIdentity>();

            mock.SetupGet(i => i.Name).Returns("kwyjibo");

            var builder = new KwyjiboBuilder(options);

            return(builder.Build <TKwyjiboContext>(mock.Object));
        }
示例#7
0
        public void InitialisedConfigurationShouldCreateContext()
        {
            var options = new KwyjiboOptions();

            options.ForContext <ContextFixture>()
            .Disable()
            .When <IIdentity>(id => id.Name.Contains("kwyjibo"))
            .Throw <InvalidOperationException>();

            var tree = new ContextTree(options);

            tree.Enabled.Should().BeTrue();
            var context = tree.GetContext <ContextFixture>();

            context.Enabled.Should().BeFalse();
            context.Name.Should().Be(this.GetType().Name);
            context.FullName.Should().Be(this.GetType().FullName);
        }
示例#8
0
        public void InitialisedConfigurationShouldCreateIntermediateContexts()
        {
            var options = new KwyjiboOptions();

            options.ForContext <ContextFixture>()
            .Enable()
            .When <IIdentity>(id => id.Name.Contains("kwyjibo"))
            .Throw <InvalidOperationException>();

            var tree    = new ContextTree(options);
            var context = tree.GetContext <ContextFixture>();

            context.FullName.Should().Be(this.GetType().FullName);
            context.Parent.FullName.Should().Be(this.GetType().Namespace);
            context.Parent.Status.Should().Be(Status.Inherit);
            context.Parent.Enabled.Should().BeTrue();
            context.Parent.Parent.Parent.Parent.Should().Be(tree);
            context.Parent.Parent.Parent.Parent.Parent.Should().BeNull();
        }
        public void SpecifiedConfigurationShouldBeReadCorrectly()
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("Configuration/sample.json")
                                .Build();

            var options = new KwyjiboOptions();

            options.Configure(configuration);
            options.ForContext <KwyjiboConfigurationExtensionsFixture>()
            .When <IIdentity>(id => id.Name.Contains("kwyjibo"))
            .Throw <SecurityException>();
            var tree = new ContextTree(options);

            tree.Enabled.Should().BeFalse();
            var context = tree.GetContext <KwyjiboConfigurationExtensionsFixture>();

            context.Enabled.Should().BeFalse();
            context.Parent.Enabled.Should().BeFalse();
            context.Parent.Parent.Enabled.Should().BeTrue();
            context.Parent.Parent.Parent.Enabled.Should().BeTrue();
        }
示例#10
0
        public void ContextShouldHaveHandler()
        {
            var options = new KwyjiboOptions();

            options.ForContext <ContextFixture>()
            .Enable()
            .Named("foobar")
            .When <IIdentity>(id => id.Name.Contains("kwyjibo"))
            .Throw <InvalidOperationException>();

            var tree    = new ContextTree(options);
            var context = tree.GetContext <ContextFixture>();
            var handler = context.GetHandler("foobar");

            handler.Should().NotBeNull();
            handler.InputType.Should().Be(typeof(IIdentity));

            var mockIdentity = new Mock <IIdentity>();

            mockIdentity.SetupGet(id => id.Name).Returns("kwyjibo");
            handler.Predicate(mockIdentity.Object).Should().BeTrue();
            handler.ExceptionBuilder().Should().BeOfType <InvalidOperationException>();
        }