<commit_before>using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using DotVVM.Framework.Compilation;
using DotVVM.Framework.Compilation.ControlTree.Resolved;
using DotVVM.Framework.Controls.Infrastructure;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DotVVM.Framework.Tests.Common.Runtime.ControlTree
{

    internal class TestViewModel : Tests.Binding.TestViewModel
    {
        public StructList<DateTime?>? NullableDateList { get; }
        public StructList<DateTime>? DateList { get; }

        public DateTime NonNullableDate { get; set; }
        public DateTime? NullableDate { get; set; }
    }
    public struct StructList<T> : IEnumerable<T>
    {
        public IEnumerator<T> GetEnumerator() =>
            new List<T> { default(T) }.GetEnumerator();

        IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
    }
    [TestClass]
    public class ControlValidationTests
    {


        ResolvedControl ParseControl(string markup, Type viewModel = null)
        {
            viewModel = viewModel ?? typeof(TestViewModel);
            var tree = DotvvmTestHelper.ParseResolvedTree($"@viewModel {viewModel}\n{markup}");

            var control = tree.Content.First(c => c.Metadata.Type != typeof(RawLiteral));
            return control;
        }

        [TestMethod]
        public void ComboBox_InvalidItemsType()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:ComboBox DataSource='{value: VmArray}' SelectedValue='{value: GuidProp}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void ComboBox_InvalidNullableDifference()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:ComboBox DataSource='{value: NullableDateList}' SelectedValue='{value: NonNullableDate}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void ComboBox_AllowedNullableDifference()
        {
            var control =
                ParseControl("<dot:ComboBox DataSource='{value: DateList}' SelectedValue='{value: NullableDate}' />");

            // TODO: check tree
        }

        [TestMethod]
        public void CheckBox_InvalidItemsType()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:CheckBox CheckedItems='{value: VmArray}' CheckedValue='{value: GuidProp}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void CheckBox_InvalidNullableDifference()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:CheckBox CheckedItems='{value: NullableDateList}' CheckedValue='{value: NonNullableDate}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void CheckBox_AllowedNullableDifference()
        {
            var control =
                ParseControl("<dot:CheckBox CheckedItems='{value: DateList}' CheckedValue='{value: NullableDate}' />");

            // TODO: check tree
        }

        [TestMethod]
        public void Radio_InvalidItemsType()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:RadioButton CheckedItem='{value: VmArray[0]}' CheckedValue='{value: GuidProp}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void Radio_InvalidNullableDifference()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:RadioButton CheckedItem='{value: NullableDate}' CheckedValue='{value: NonNullableDate}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void Radio_AllowedNullableDifference()
        {
            var control =
                ParseControl("<dot:RadioButton CheckedItem='{value: NonNullableDate}' CheckedValue='{value: NullableDate}' />");

            // TODO: check tree
        }
    }<commit_msg>Fixed ControlValidationTests - reversed conditions<commit_after>using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using DotVVM.Framework.Compilation;
using DotVVM.Framework.Compilation.ControlTree.Resolved;
using DotVVM.Framework.Controls.Infrastructure;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DotVVM.Framework.Tests.Common.Runtime.ControlTree
{

    internal class TestViewModel : Tests.Binding.TestViewModel
    {
        public StructList<DateTime?>? NullableDateList { get; }
        public StructList<DateTime>? DateList { get; }

        public DateTime NonNullableDate { get; set; }
        public DateTime? NullableDate { get; set; }
    }
    public struct StructList<T> : IEnumerable<T>
    {
        public IEnumerator<T> GetEnumerator() =>
            new List<T> { default(T) }.GetEnumerator();

        IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
    }
    [TestClass]
    public class ControlValidationTests
    {


        ResolvedControl ParseControl(string markup, Type viewModel = null)
        {
            viewModel = viewModel ?? typeof(TestViewModel);
            var tree = DotvvmTestHelper.ParseResolvedTree($"@viewModel {viewModel}\n{markup}");

            var control = tree.Content.First(c => c.Metadata.Type != typeof(RawLiteral));
            return control;
        }

        [TestMethod]
        public void ComboBox_InvalidItemsType()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:ComboBox DataSource='{value: VmArray}' SelectedValue='{value: GuidProp}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void ComboBox_InvalidNullableDifference()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:ComboBox DataSource='{value: NullableDateList}' SelectedValue='{value: NonNullableDate}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void ComboBox_AllowedNullableDifference()
        {
            var control =
                ParseControl("<dot:ComboBox DataSource='{value: DateList}' SelectedValue='{value: NullableDate}' />");

            // TODO: check tree
        }

        [TestMethod]
        public void CheckBox_InvalidItemsType()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:CheckBox CheckedItems='{value: VmArray}' CheckedValue='{value: GuidProp}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void CheckBox_InvalidNullableDifference()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>ParseControl("<dot:CheckBox CheckedItems='{value: DateList}' CheckedValue='{value: NullableDate}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void CheckBox_AllowedNullableDifference()
        {
            var control = ParseControl("<dot:CheckBox CheckedItems='{value: NullableDateList}' CheckedValue='{value: NonNullableDate}' />");
            // TODO: check tree
        }

        [TestMethod]
        public void Radio_InvalidItemsType()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:RadioButton CheckedItem='{value: VmArray[0]}' CheckedValue='{value: GuidProp}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void Radio_InvalidNullableDifference()
        {
            var exception = Assert.ThrowsException<DotvvmCompilationException>(() =>
                ParseControl("<dot:RadioButton CheckedItem='{value: NonNullableDate}' CheckedValue='{value: NullableDate}' />"));

            // TODO: check exception message
        }

        [TestMethod]
        public void Radio_AllowedNullableDifference()
        {
            var control = ParseControl("<dot:RadioButton CheckedItem='{value: NullableDate}' CheckedValue='{value: NonNullableDate}' />");
            // TODO: check tree
        }
    }
{'fraction_non_alphanumeric': 0.11037140854940435, 'fraction_numerical': 0.000233590282644242, 'mean_word_length': 2.620718816067653, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1222555', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2165, 'n_words': 435}