<commit_before>﻿using NUnit.Framework;
using System;
using uShip.Logging.LogBuilders;
using uShip.Logging.Tests.Common;

namespace uShip.Logging.Tests
{
    [TestFixture]
    public class LoggingEventPropertiesBuilderTests
    {
        [Test]
        public void Should_Have_Different_Origin_When_First_Target_Stack_Trace_Is_Different_But_Same_Exception()
        {
            var exceptionA = GetSystemParseExceptionA();
            var loggingPropertiesA = new LoggingEventPropertiesBuilder()
                    .WithException(exceptionA)
                    .WithUniqueOrigin(string.Empty, exceptionA)
                    .Build();

            var exceptionB = GetSystemParseExceptionB();
            var loggingPropertiesB = new LoggingEventPropertiesBuilder()
                    .WithException(exceptionB)
                    .WithUniqueOrigin(string.Empty, exceptionB)
                    .Build();

            Assert.AreNotEqual(loggingPropertiesA["Origin"].ToString(), loggingPropertiesB["Origin"].ToString());
        }

        [Test]
        public void Should_Have_Different_Origin_When_First_Target_Stack_Trace_Is_Same_But_Exceptions_Differ()
        {
            var exceptionA = GetVariableSystemException(parseException: true);<commit_msg>added password sanitize test<commit_after>﻿using NUnit.Framework;
using System;
using uShip.Logging.LogBuilders;
using uShip.Logging.Tests.Common;

namespace uShip.Logging.Tests
{
    [TestFixture]
    public class LoggingEventPropertiesBuilderTests
    {
        [Test]
        public void Should_Have_Different_Origin_When_First_Target_Stack_Trace_Is_Different_But_Same_Exception()
        {
            var exceptionA = GetSystemParseExceptionA();
            var loggingPropertiesA = new LoggingEventPropertiesBuilder()
                    .WithException(exceptionA)
                    .WithUniqueOrigin(string.Empty, exceptionA)
                    .Build();

            var exceptionB = GetSystemParseExceptionB();
            var loggingPropertiesB = new LoggingEventPropertiesBuilder()
                    .WithException(exceptionB)
                    .WithUniqueOrigin(string.Empty, exceptionB)
                    .Build();

            Assert.AreNotEqual(loggingPropertiesA["Origin"].ToString(), loggingPropertiesB["Origin"].ToString());
        }

        [Test]
        public void Should_sanitize_passwords()
        {
            var loggingProperties = new LoggingEventPropertiesBuilder()
                    .Build();

            loggingProperties.Set("someInfo", "\"EmailAddress\\\":\\\"<EMAIL>\\\",\\\"Password\\\":\\\"<PASSWORD>\\\"");
            loggingProperties.Set("moreInfo", "\"emailAddress\":\"<EMAIL>\",\"password\":\"<PASSWORD>\"");

            Assert.AreEqual(loggingProperties["someInfo"], "\"EmailAddress\\\":\\\"<EMAIL>\\\",\\\"************\\\":\\\"****\\\"");
            Assert.AreEqual(loggingProperties["moreInfo"], "\"emailAddress\":\"<EMAIL>\",\"************\":\"****\"");
        }

        [Test]
        public void Should_Have_Different_Origin_When_First_Target_Stack_Trace_Is_Same_But_Exceptions_Differ()
        {
            var exceptionA = GetVariableSystemException(parseException: true);
{'fraction_non_alphanumeric': 0.12074882995319813, 'fraction_numerical': 0.0, 'mean_word_length': 2.6103603603603602, 'pattern_counts': {'":': 8, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4042853', 'n_tokens_mistral': 828, 'n_tokens_neox': 808, 'n_words': 119}