<commit_before>﻿using System;
using FluentAssertions;
using Xunit;

namespace Stripe.Tests.Xunit
{
    public class when_constructing_an_event : IClassFixture<events_fixture>
    {
        private readonly events_fixture fixture;
        public StripeEvent ConstructedEvent { get; set; }

        public when_constructing_an_event(events_fixture fixture)
        {
            this.fixture = fixture;
        }

        [Fact]
        public void it_should_throw_with_outdated_timestamp()
        {
            // This throws an error because the tolerance is higher than allowed
            var exception = Assert.Throws<StripeException>(() =>
                StripeEventUtility.ConstructEvent(fixture.StripeJson, fixture.StripeSignature, fixture.StripeSecret)
            );

            exception.Message.Should().Be("The webhook cannot be processed because the current timestamp is above the allowed tolerance.");
        }

        [Fact]
        public void it_should_validate_with_right_data()
        {
            // A timestamp within the default tolerance of 300 seconds
            int ReasonablyCloseTime = fixture.EventTimestamp + 120;

            ConstructedEvent = StripeEventUtility.ConstructEvent(fixture.StripeJson, fixture.StripeSignature, fixture.StripeSecret, ReasonablyCloseTime);

            ConstructedEvent.Should().NotBeNull();
            ConstructedEvent.Request.Id.Should().Be("req_FAKE");
            ConstructedEvent.Request.IdempotencyKey.Should().Be("placeholder");
            ConstructedEvent.Account.Should().Be("acct_CONNECT");
        }

        [Fact]<commit_msg>Fix test for webhook signature<commit_after>﻿using System;
using FluentAssertions;
using Xunit;

namespace Stripe.Tests.Xunit
{
    public class when_constructing_an_event : IClassFixture<events_fixture>
    {
        private readonly events_fixture fixture;
        public StripeEvent ConstructedEvent { get; set; }

        public when_constructing_an_event(events_fixture fixture)
        {
            this.fixture = fixture;
        }

        [Fact]
        public void it_should_throw_with_outdated_timestamp()
        {
            // This throws an error because the tolerance is higher than allowed
            var exception = Assert.Throws<StripeException>(() =>
                StripeEventUtility.ConstructEvent(fixture.StripeJson, fixture.StripeSignature, fixture.StripeSecret)
            );

            exception.Message.Should().Be("The webhook cannot be processed because the current timestamp is outside of the allowed tolerance.");
        }

        [Fact]
        public void it_should_validate_with_right_data()
        {
            // A timestamp within the default tolerance of 300 seconds
            int ReasonablyCloseTime = fixture.EventTimestamp + 120;

            ConstructedEvent = StripeEventUtility.ConstructEvent(fixture.StripeJson, fixture.StripeSignature, fixture.StripeSecret, ReasonablyCloseTime);

            ConstructedEvent.Should().NotBeNull();
            ConstructedEvent.Request.Id.Should().Be("req_FAKE");
            ConstructedEvent.Request.IdempotencyKey.Should().Be("placeholder");
            ConstructedEvent.Account.Should().Be("acct_CONNECT");
        }

        [Fact]
{'fraction_non_alphanumeric': 0.07920792079207921, 'fraction_numerical': 0.0037128712871287127, 'mean_word_length': 2.7418981481481484, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2140515', 'n_tokens_mistral': 862, 'n_tokens_neox': 829, 'n_words': 182}