<commit_before>﻿// <copyright file="Step.cs" company="<NAME>">
//  Copyright (c) <NAME>. All rights reserved.
// </copyright>

namespace Xbehave.Sdk
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using Xbehave.Sdk.Infrastructure;

    [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Step", Justification = "By design.")]
    public class Step
    {
        private readonly string name;
        private readonly Action body;
        private readonly List<Action> teardowns = new List<Action>();

        public Step(string name, Action body)
        {
            Guard.AgainstNullArgument("body", body);

            this.name = name;
            this.body = body;
        }

        public virtual string Name
        {
            get { return this.name; }
        }

        public string SkipReason { get; set; }

        public bool InIsolation { get; set; }

        public int MillisecondsTimeout { get; set; }

        public void AddTeardown(Action teardown)
        {
            if (teardown != null)
            {
                this.teardowns.Add(teardown);
            }
        }

        [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Object is disposed after step execution.")]
        public void Execute()
        {
            try
            {
                if (this.MillisecondsTimeout > 0)
                {
                    var result = this.body.BeginInvoke(null, null);

                    // NOTE: we do not call the WaitOne(int) overload because it wasn't introduced until .NET 3.5 SP1 and we want to support pre-SP1
                    if (!result.AsyncWaitHandle.WaitOne(this.MillisecondsTimeout, false))
                    {
                        throw new Xunit.Sdk.TimeoutException(this.MillisecondsTimeout);
                    }

                    this.body.EndInvoke(result);
                }
                else
                {
                    this.body();
                }
            }
            finally
            {
                foreach (var teardown in this.teardowns)
                {
                    CurrentScenario.AddDisposable(new Disposable(teardown));
                }
            }
        }
    }<commit_msg>re #20 removed side effect (non addition of nulls) from Step.AddTeardown<commit_after>﻿// <copyright file="Step.cs" company="<NAME>">
//  Copyright (c) <NAME>. All rights reserved.
// </copyright>

namespace Xbehave.Sdk
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.Linq;
    using Xbehave.Sdk.Infrastructure;

    [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Step", Justification = "By design.")]
    public class Step
    {
        private readonly string name;
        private readonly Action body;
        private readonly List<Action> teardowns = new List<Action>();

        public Step(string name, Action body)
        {
            Guard.AgainstNullArgument("body", body);

            this.name = name;
            this.body = body;
        }

        public virtual string Name
        {
            get { return this.name; }
        }

        public string SkipReason { get; set; }

        public bool InIsolation { get; set; }

        public int MillisecondsTimeout { get; set; }

        public void AddTeardown(Action teardown)
        {
            this.teardowns.Add(teardown);
        }

        [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Object is disposed after step execution.")]
        public void Execute()
        {
            try
            {
                if (this.MillisecondsTimeout > 0)
                {
                    var result = this.body.BeginInvoke(null, null);

                    // NOTE: we do not call the WaitOne(int) overload because it wasn't introduced until .NET 3.5 SP1 and we want to support pre-SP1
                    if (!result.AsyncWaitHandle.WaitOne(this.MillisecondsTimeout, false))
                    {
                        throw new Xunit.Sdk.TimeoutException(this.MillisecondsTimeout);
                    }

                    this.body.EndInvoke(result);
                }
                else
                {
                    this.body();
                }
            }
            finally
            {
                foreach (var teardown in this.teardowns.Where(teardown => teardown != null))
                {
                    CurrentScenario.AddDisposable(new Disposable(teardown));
                }
            }
        }
    }
{'fraction_non_alphanumeric': 0.08970588235294118, 'fraction_numerical': 0.0058823529411764705, 'mean_word_length': 1.5735135135135134, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 18, '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': '1052084', 'n_tokens_mistral': 1267, 'n_tokens_neox': 1188, 'n_words': 309}