<commit_before>// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics.Contracts;
using Xunit;

namespace System.Diagnostics.Contracts.Tests
{
    public class BasicContractsTest
    {
        [Fact]
        public static void AssertTrueDoesNotRaiseEvent()
        {
            bool eventRaised = false;
            Contract.ContractFailed += (s, e) =>
            {
                eventRaised = true;
                e.SetHandled();
            };

            Contract.Assert(true);
            Assert.False(eventRaised, "ContractFailed event was raised");
        }

        [Fact]
        public static void AssertFalseRaisesEvent()
        {
            bool eventRaised = false;
            Contract.ContractFailed += (s, e) =>
            {
                eventRaised = true;
                e.SetHandled();
            };

            Contract.Assert(false);
            Assert.True(eventRaised, "ContractFailed event not raised");
        }

        [Fact]
        public static void AssertFalseThrows()
        {
            bool eventRaised = false;
            Contract.ContractFailed += (s, e) =>
            {
                eventRaised = true;
                e.SetUnwind();
            };


            Assert.ThrowsAny<Exception>(() =>
            {
                Contract.Assert(false, "Some kind of user message");
            });

            Assert.True(eventRaised, "Event was not raised");
        }
    }
}<commit_msg>Update S.Diag.Contracts tests to verify behavior for DEBUG and !DEBUG<commit_after>// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics.Contracts;
using Xunit;

namespace System.Diagnostics.Contracts.Tests
{
    public class BasicContractsTest
    {
        [Fact]
        public static void AssertTrueDoesNotRaiseEvent()
        {
            bool eventRaised = false;
            Contract.ContractFailed += (s, e) =>
            {
                eventRaised = true;
                e.SetHandled();
            };

            Contract.Assert(true);

            Assert.False(eventRaised, "ContractFailed event was raised");
        }

        [Fact]
        public static void AssertFalseRaisesEvent()
        {
            bool eventRaised = false;
            Contract.ContractFailed += (s, e) =>
            {
                eventRaised = true;
                e.SetHandled();
            };

            Contract.Assert(false);
#if DEBUG
            Assert.True(eventRaised, "ContractFailed event not raised");            
#else
            Assert.False(eventRaised, "ContractFailed event was raised");
#endif            
        }

        [Fact]
        public static void AssertFalseThrows()
        {
            bool eventRaised = false;
            Contract.ContractFailed += (s, e) =>
            {
                eventRaised = true;
                e.SetUnwind();
            };


#if DEBUG
            Assert.ThrowsAny<Exception>(() =>
            {
                Contract.Assert(false, "Some kind of user message");
            });

            Assert.True(eventRaised, "Event was not raised");
#else
            Contract.Assert(false, "Some kind of user message");
            
            Assert.False(eventRaised, "ContractFailed event was raised");
#endif            
        }
    }
}
{'fraction_non_alphanumeric': 0.09232512036250354, 'fraction_numerical': 0.0, 'mean_word_length': 1.5649963689179376, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '5649984', 'n_tokens_mistral': 910, 'n_tokens_neox': 864, 'n_words': 233}