<commit_before>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;

namespace AncoraMVVM.Base.Test
{
    [TestClass]
    public class DelegateCommandTests
    {
        [TestMethod]
        public void CanExecute_NoConstructorParams_IsTrue()
        {
            var cmd = new DelegateCommand((p) => { });
            Assert.IsTrue(cmd.CanExecute(null));
        }

        [TestMethod]
        public void Execute_CalledActionWithParameter()
        {
            var param = new object();
            object receivedParam = null;
            var cmd = new DelegateCommand(p => receivedParam = p);

            cmd.Execute(param);
            Assert.AreSame(param, receivedParam);
        }


        private class DummyNotifier : INotifyPropertyChanged
        {
            private int number;
            public int Number
            {
                get
                {
                    return number;
                }
                set
                {
                    number = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Number"));
                }
            }

            public event PropertyChangedEventHandler PropertyChanged;
        }

        [TestMethod]
        public void BindToPropertyChange_Propagated()
        {
            bool wasCalled = false;
            var not = new DummyNotifier();
            var cmd = new DelegateCommand((p) => { }, (p) => p != null);
            cmd.BindCanExecuteToProperty(not, "Number");
            cmd.CanExecuteChanged += (s, e) => wasCalled = true;

            not.Number = 123;
            Assert.IsTrue(wasCalled);
        }

        [TestMethod]
        public void Execute_CalledAsyncAction_AsyncExecuted()
        {
            bool executed = false;
            var cmd = new DelegateCommand(async (p) =>
            {
                await Task.Delay(500);<commit_msg>Small error in a test.<commit_after>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;

namespace AncoraMVVM.Base.Test
{
    [TestClass]
    public class DelegateCommandTests
    {
        [TestMethod]
        public void CanExecute_NoConstructorParams_IsTrue()
        {
            var cmd = new DelegateCommand((p) => { });
            Assert.IsTrue(cmd.CanExecute(null));
        }

        [TestMethod]
        public void Execute_CalledActionWithParameter()
        {
            var param = new object();
            object receivedParam = null;
            var cmd = new DelegateCommand(p => receivedParam = p);

            cmd.Execute(param);
            Assert.AreSame(param, receivedParam);
        }

        private class DummyNotifier : INotifyPropertyChanged
        {
            private int number;
            public int Number
            {
                get
                {
                    return number;
                }
                set
                {
                    number = value;
                    if (PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs("Number"));
                }
            }

            public event PropertyChangedEventHandler PropertyChanged;
        }

        [TestMethod]
        public void BindToPropertyChange_Propagated()
        {
            bool wasCalled = false;
            var not = new DummyNotifier();
            var cmd = new DelegateCommand((p) => { }, (p) => p != null);
            cmd.BindCanExecuteToProperty(not, "Number");
            cmd.CanExecuteChanged += (s, e) => wasCalled = true;

            not.Number = 123;
            Assert.IsTrue(wasCalled);
        }

        [TestMethod]
        public void Execute_CalledAsyncAction_AsyncExecuted()
        {
            bool executed = false;
            var cmd = new DelegateCommand(async (p) =>
            {
                await Task.Delay(200);
{'fraction_non_alphanumeric': 0.08345642540620384, 'fraction_numerical': 0.0029542097488921715, 'mean_word_length': 1.537788881948782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '9431', 'n_tokens_mistral': 1024, 'n_tokens_neox': 986, 'n_words': 225}