<commit_before>﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Umbraco.Core.PropertyEditors.ValueConverters;
using Umbraco.Core;

namespace Umbraco.Tests.PropertyEditors
{
    [TestFixture]
	public class PropertyEditorValueConverterTests
	{
        // see notes in the converter
        // only ONE date format is expected here

        //[TestCase("2012-11-10", true)]
        //[TestCase("2012/11/10", true)]
        //[TestCase("10/11/2012", true)]
        //[TestCase("11/10/2012", false)]
        //[TestCase("Sat 10, Nov 2012", true)]
        //[TestCase("Saturday 10, Nov 2012", true)]
        //[TestCase("Sat 10, November 2012", true)]
        //[TestCase("Saturday 10, November 2012", true)]
        //[TestCase("2012-11-10 13:14:15", true)]
        [TestCase("2012-11-10 13:14:15", true)]
        [TestCase("2012-11-10T13:14:15", true)]
        [TestCase("", false)]
		public void CanConvertDatePickerPropertyEditor(string date, bool expected)
		{
			var converter = new DatePickerValueConverter();
			var dateTime = new DateTime(2012, 11, 10, 13, 14, 15);
			var result = converter.ConvertDataToSource(null, date, false); // does not use type for conversion

		    if (expected)
		        Assert.AreEqual(dateTime.Date, ((DateTime) result).Date);
            else
                Assert.AreNotEqual(dateTime.Date, ((DateTime)result).Date);
        }

        [TestCase("TRUE", true)]
        [TestCase("True", true)]
        [TestCase("true", true)]
        [TestCase("1", true)]
        [TestCase(1, true)]
        [TestCase(true, true)]
        [TestCase("FALSE", false)]
        [TestCase("False", false)]
        [TestCase("false", false)]
        [TestCase("0", false)]
        [TestCase(0, false)]
        [TestCase(false, false)]
        [TestCase("", false)]
        [TestCase(null, false)]
        [TestCase("blah", false)]
        public void CanConvertYesNoPropertyEditor(object value, bool expected)
        {
            var converter = new YesNoValueConverter();
            var result = converter.ConvertDataToSource(null, value, false); // does not use type for conversion

            Assert.AreEqual(expected, result);
        }

        [TestCase("apples", new[] { "apples" })]
        [TestCase("apples,oranges", new[] { "apples", "oranges" })]
        [TestCase(" apples, oranges, pears ", new[] { "apples", "oranges", "pears" })]
        [TestCase("", new string[] { })]
        [TestCase(null, new string[] { })]
        public void CanConvertCheckboxListPropertyEditor(object value, IEnumerable<string> expected)
        {
            var converter = new CheckboxListValueConverter();
            var result = converter.ConvertSourceToObject(null, value, false);

            Assert.AreEqual(expected, result);
        }

        [TestCase("apples", new[] {"apples"})]
        [TestCase("apples,oranges", new[] {"apples", "oranges"})]
        [TestCase("apples , oranges, pears ", new[] {"apples", "oranges", "pears"})]
        [TestCase("", new string[] {})]
        [TestCase(null, new string[] {})]
	    public void CanConvertDropdownListMultiplePropertyEditor(object value, IEnumerable<string> expected)
	    {
	        var converter = new DropdownListMultipleValueConverter();
	        var result = converter.ConvertSourceToObject(null, value, false);

            Assert.AreEqual(expected, result);
	    }

        [TestCase("100", new[] {100})]
        [TestCase("100,200", new[] {100, 200})]
        [TestCase("100 , 200, 300 ", new[] {100, 200, 300})]
        [TestCase("", new int[] {})]
        [TestCase(null, new int[] {})]
	    public void CanConvertDropdownListMultipleWithKeysPropertyEditor(object value, IEnumerable<int> expected)
	    {
	        var converter = new DropdownListMultipleWithKeysValueConverter();
	        var result = converter.ConvertDataToSource(null, value, false);

            Assert.AreEqual(expected, result);
	    }

        [TestCase(null, "1", false, 1)]
        [TestCase(null, "1", true, 1)]
        [TestCase(null, "0", false, 0)]
        [TestCase(null, "0", true, 0)]
        [TestCase(null, null, false, 0)]
        [TestCase(null, null, true, 0)]
        [TestCase(null, "-1", false, -1)]
        [TestCase(null, "-1", true, -1)]
        public void CanConvertDecimalAliasPropertyEditor(Core.Models.PublishedContent.PublishedPropertyType propertyType, object value, bool preview, double expected)
        {
            var converter = new DecimalValueConverter();
            var result = converter.ConvertDataToSource(propertyType, value, preview);

            Assert.AreEqual(expected, result);
        }
    }
}<commit_msg>adding a few more tests.<commit_after>﻿using System;
using System.Collections.Generic;
using NUnit.Framework;
using Umbraco.Core.PropertyEditors.ValueConverters;

namespace Umbraco.Tests.PropertyEditors
{
    [TestFixture]
	public class PropertyEditorValueConverterTests
	{
        // see notes in the converter
        // only ONE date format is expected here

        //[TestCase("2012-11-10", true)]
        //[TestCase("2012/11/10", true)]
        //[TestCase("10/11/2012", true)]
        //[TestCase("11/10/2012", false)]
        //[TestCase("Sat 10, Nov 2012", true)]
        //[TestCase("Saturday 10, Nov 2012", true)]
        //[TestCase("Sat 10, November 2012", true)]
        //[TestCase("Saturday 10, November 2012", true)]
        //[TestCase("2012-11-10 13:14:15", true)]
        [TestCase("2012-11-10 13:14:15", true)]
        [TestCase("2012-11-10T13:14:15", true)]
        [TestCase("", false)]
		public void CanConvertDatePickerPropertyEditor(string date, bool expected)
		{
			var converter = new DatePickerValueConverter();
			var dateTime = new DateTime(2012, 11, 10, 13, 14, 15);
			var result = converter.ConvertDataToSource(null, date, false); // does not use type for conversion

		    if (expected)
		        Assert.AreEqual(dateTime.Date, ((DateTime) result).Date);
            else
                Assert.AreNotEqual(dateTime.Date, ((DateTime)result).Date);
        }

        [TestCase("TRUE", true)]
        [TestCase("True", true)]
        [TestCase("true", true)]
        [TestCase("1", true)]
        [TestCase(1, true)]
        [TestCase(true, true)]
        [TestCase("FALSE", false)]
        [TestCase("False", false)]
        [TestCase("false", false)]
        [TestCase("0", false)]
        [TestCase(0, false)]
        [TestCase(false, false)]
        [TestCase("", false)]
        [TestCase(null, false)]
        [TestCase("blah", false)]
        public void CanConvertYesNoPropertyEditor(object value, bool expected)
        {
            var converter = new YesNoValueConverter();
            var result = converter.ConvertDataToSource(null, value, false); // does not use type for conversion

            Assert.AreEqual(expected, result);
        }

        [TestCase("apples", new[] { "apples" })]
        [TestCase("apples,oranges", new[] { "apples", "oranges" })]
        [TestCase(" apples, oranges, pears ", new[] { "apples", "oranges", "pears" })]
        [TestCase("", new string[] { })]
        [TestCase(null, new string[] { })]
        public void CanConvertCheckboxListPropertyEditor(object value, IEnumerable<string> expected)
        {
            var converter = new CheckboxListValueConverter();
            var result = converter.ConvertSourceToObject(null, value, false);

            Assert.AreEqual(expected, result);
        }

        [TestCase("apples", new[] {"apples"})]
        [TestCase("apples,oranges", new[] {"apples", "oranges"})]
        [TestCase("apples , oranges, pears ", new[] {"apples", "oranges", "pears"})]
        [TestCase("", new string[] {})]
        [TestCase(null, new string[] {})]
	    public void CanConvertDropdownListMultiplePropertyEditor(object value, IEnumerable<string> expected)
	    {
	        var converter = new DropdownListMultipleValueConverter();
	        var result = converter.ConvertSourceToObject(null, value, false);

            Assert.AreEqual(expected, result);
	    }

        [TestCase("100", new[] {100})]
        [TestCase("100,200", new[] {100, 200})]
        [TestCase("100 , 200, 300 ", new[] {100, 200, 300})]
        [TestCase("", new int[] {})]
        [TestCase(null, new int[] {})]
	    public void CanConvertDropdownListMultipleWithKeysPropertyEditor(object value, IEnumerable<int> expected)
	    {
	        var converter = new DropdownListMultipleWithKeysValueConverter();
	        var result = converter.ConvertDataToSource(null, value, false);

            Assert.AreEqual(expected, result);
	    }

        [TestCase(null, "1", false, 1)]
        [TestCase(null, "1", true, 1)]
        [TestCase(null, "0", false, 0)]
        [TestCase(null, "0", true, 0)]
        [TestCase(null, null, false, 0)]
        [TestCase(null, null, true, 0)]
        [TestCase(null, "-1", false, -1)]
        [TestCase(null, "-1", true, -1)]
        [TestCase(null, "1.65", false, 1.65)]
        [TestCase(null, "1.65", true, 1.65)]
        [TestCase(null, "-1.65", false, -1.65)]
        [TestCase(null, "-1.65", true, -1.65)]
        public void CanConvertDecimalAliasPropertyEditor(Core.Models.PublishedContent.PublishedPropertyType propertyType, object value, bool preview, double expected)
        {
            var converter = new DecimalValueConverter();
            var result = converter.ConvertDataToSource(propertyType, value, preview);

            Assert.AreEqual(expected, result);
        }
    }
}
{'fraction_non_alphanumeric': 0.1509772847332277, 'fraction_numerical': 0.037612255678816695, 'mean_word_length': 2.781861765880943, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6273477', 'n_tokens_mistral': 2999, 'n_tokens_neox': 2643, 'n_words': 662}