Пример #1
0
        public void Get_WithNoExodataResolver_ReturnsDefault()
        {
            var maxLength = new ExodataDeclaration <int>(7);

            var value = maxLength.For <string>();

            Assert.AreEqual(7, value);
        }
Пример #2
0
        public void Get_ByTypeOnly_UsesTypeDeclaration()
        {
            var resolver = new StandardExodataResolver();

            resolver.Bind(ExodataDeclaration <int> .TypeDeclaration, 42);

            ExodataDeclaration.SetResolver(resolver);

            Assert.AreEqual(42, ExodataDeclaration.Get <int>());
        }
Пример #3
0
        public void ValidateValue_WithoutValidValue_ThrowsException()
        {
            var betweenOneAndTen = new ComparableExodataDeclaration <int>(1, 10, 5);

            var resolver = new StandardExodataResolver();

            resolver.Bind(betweenOneAndTen, 42);

            ExodataDeclaration.SetResolver(resolver);

            Assert.Throws <ExodataValidationException <int> >(() => betweenOneAndTen.Get());
        }
Пример #4
0
        public void Resolve_ThruImplicitCastOperator_ReturnsValue()
        {
            var resolver = new StandardExodataResolver();

            resolver.Bind(StringExodata.MaxLength, 42);

            ExodataDeclaration.SetResolver(resolver);

            int value = StringExodata.MaxLength;

            Assert.AreEqual(42, value);
        }
Пример #5
0
        public void ValidateValue_WithValidValue_DoesNotThrowException()
        {
            var betweenOneAndTen = new ComparableExodataDeclaration <int>(1, 10, 5);

            var resolver = new StandardExodataResolver();

            resolver.Bind(betweenOneAndTen, 7);

            ExodataDeclaration.SetResolver(resolver);

            Assert.AreEqual(7, betweenOneAndTen.Get());
        }
Пример #6
0
        public void Get_WithValidArguments_ReturnsExodataResolverResults()
        {
            var maxLength = new ExodataDeclaration <int>(7);

            var resolver = new StandardExodataResolver();

            resolver.Bind(maxLength)
            .For <string>()
            .To(42);

            ExodataDeclaration.SetResolver(resolver);

            var value = maxLength.For <string>();

            Assert.AreEqual(42, value);
        }
Пример #7
0
        public void Get_WithNoExodataResolver_UsesResolverFromIoc()
        {
            var maxLength = new ExodataDeclaration <int>(7);

            var exodataResolver = new StandardExodataResolver();

            exodataResolver.Bind(maxLength)
            .For <string>()
            .To(42);

            Ioc.SetDependencyResolver(new DependencyResolver(symbol => symbol.ToMaybe().OfType <IDependencySymbol>().Where(x => x.DependencyType == typeof(IExodataResolver)).Select(x => (object)exodataResolver)));

            var value = maxLength.For <string>();

            Assert.AreEqual(42, value);
        }
Пример #8
0
        public void Get_OnGenericExodataWithDeclaration_ProvidesAllArgumentsToResolver()
        {
            var maxLength = new ExodataDeclaration <int>(7);

            var resolver = MockRepository.GenerateMock <IExodataResolver>();

            resolver.Expect(x => x.TryResolve <int, object, string>(null))
            .Callback <IExodataRequest <int, object, string> >(r => r.Symbol == maxLength &&
                                                               r.Context == Maybe <object> .NoValue &&
                                                               r.Subject == Maybe <string> .NoValue &&
                                                               r.Member == null)
            .Return(42.ToMaybe());

            ExodataDeclaration.SetResolver(resolver);

            maxLength.For <string>();
            resolver.VerifyAllExpectations();
        }
Пример #9
0
        public void Get_OnGenericExodataWithDeclarationSubjectAndMember_ProvidesAllArgumentsToResolver()
        {
            var    maxLength = new ExodataDeclaration <int>(7);
            string subject   = "Hello, World!";

            Expression <Func <string, object> > expression = x => x.Length;
            var member = expression.ExtractMemberInfoForExodata <string>();

            var resolver = MockRepository.GenerateMock <IExodataResolver>();

            resolver.Expect(x => x.TryResolve <int, object, string>(null))
            .Callback <IExodataRequest <int, object, string> >(r => r.Symbol == maxLength &&
                                                               r.Context == Maybe <object> .NoValue &&
                                                               r.Subject == subject &&
                                                               r.Member == member)
            .Return(42.ToMaybe());

            ExodataDeclaration.SetResolver(resolver);

            maxLength.For(subject, expression);
            resolver.VerifyAllExpectations();
        }
 public ExodataDeclarationResolutionRoot(ExodataDeclaration <TExodata> declaration, Maybe <TContext> context = default(Maybe <TContext>))
     : base(context)
 {
     _Declaration = Guard.NotNull(declaration, "declaration");
 }
Пример #11
0
        public void Get_WhenWithNoDefault_ThrowsException()
        {
            var maxLength = new ExodataDeclaration <int>();

            Assert.Throws <InvalidOperationException>(() => maxLength.Get());
        }
Пример #12
0
 public void BeforeTest()
 {
     ExodataDeclaration.SetResolver(null);
     Ioc.SetDependencyResolver(null);
 }