Пример #1
0
        public void CompareTemplateSelectorArgs()
        {
            StructAssert.IsCorrect <TemplateSelectorArgs <int> >();

            var arg = default(TemplateSelectorArgs <int>);

            DataTemplate template = new DataTemplate();

            Assert.AreEqual(
                template,
                TemplateSelector.Create <int>(
                    e =>
            {
                arg = e;

                return(template);
            }).SelectTemplate(1, null));

            StructAssert.AreEqual(arg, (x, y) => x == y, (x, y) => x != y);
            StructAssert.AreNotEqual(arg, default(TemplateSelectorArgs <int>), (x, y) => x == y, (x, y) => x != y);

            new HashSet <TemplateSelectorArgs <int> > {
                default(TemplateSelectorArgs <int>), arg, arg
            };
        }
        public void NoFunctions()
        {
            // invalid error strategy
            ExceptionAssert.Throws <ArgumentOutOfRangeException>(
                () => TemplateSelector.Create <int>(errorStrategy: (SelectorErrorStrategy)int.MaxValue),
                "errorStrategy");

            // with ConverterErrorStrategy.ReturnDefaultValue (default)
            Assert.AreEqual <DataTemplate?>(null, TemplateSelector.Create <int>().SelectTemplate(1, null));

            // with ConverterErrorStrategy.ReturnNewEmptyDataTemplate
            DataTemplate result = TemplateSelector.Create <int>(errorStrategy: SelectorErrorStrategy.ReturnNewEmptyDataTemplate).SelectTemplate(1, null);

            Assert.IsNotNull(result);
            Assert.IsFalse(result.HasContent);
        }
        public void WithSelectFunction()
        {
            // with an input value of an unexpected type (use default error strategy)
            Assert.IsNull(TemplateSelector.Create <int>(e => new DataTemplate()).SelectTemplate(true, null));
            Assert.IsNull(TemplateSelector.Create <int>(e => new DataTemplate()).SelectTemplate(null, null));

            // with a valid input value
            DataTemplate template = new DataTemplate();

            Assert.AreEqual(template, TemplateSelector.Create <int>(
                                e =>
            {
                Assert.AreEqual(1, e.Item);

                return(template);
            }).SelectTemplate(1, null));
        }