public void AddSerializedDataDoesNotAppendValueWhenDataAlreadyStored()
        {
            var key       = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
            var value     = Guid.NewGuid().ToString();
            var nextValue = Guid.NewGuid().ToString();

            var sut = new TimeoutException();

            sut.AddSerializedData(key, value);
            sut.AddSerializedData(key, nextValue);

            var actual = sut.Data[key];

            _output.WriteLine("Stored data is: {0}", actual);

            actual.Should().Be(value);
        }
        public void AddSerializedDataThrowsExceptionWithNullData()
        {
            var key = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);

            var sut = new TimeoutException();

            Action action = () => sut.AddSerializedData(key, null);

            action.Should().Throw <ArgumentNullException>();
        }
        public void AddSerializedDataDoesNotAppendValueWhenSerializationAndToStringBothFail()
        {
            var key   = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
            var value = new ToStringFailure();

            var sut = new TimeoutException();

            sut.AddSerializedData(key, value);

            sut.Data.Contains(key).Should().BeFalse();
        }
        public void AddSerializedDataDoesNotIncludeNullNestedTypeInExceptionData()
        {
            var key   = Guid.NewGuid().ToString();
            var value = Model.Ignoring <Company>(x => x.Owner).Create <Company>();

            var sut = new TimeoutException();

            sut.AddSerializedData(key, value);

            var expected = sut.Data[key] as string;

            expected.Should().NotContain(typeof(SerializeFailure).FullName);
        }
        public void AddSerializedDataAppendsValueTypeValuesTest(object value)
        {
            var key = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);

            var sut = new TimeoutException();

            sut.AddSerializedData(key, value);

            var actual = sut.Data[key];

            _output.WriteLine("Stored data is: {0}", actual);

            actual.Should().Be(value);
        }
        public void AddSerializedDataAppendsDataToStringWhenSerializationReturnsEmptyJson()
        {
            var key   = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
            var value = new EmptyModel();

            var sut = new TimeoutException();

            sut.AddSerializedData(key, value);

            var actual = sut.Data[key].As <string>();

            _output.WriteLine("Stored data is: {0}", actual);

            actual.Should().Be(typeof(EmptyModel).FullName);
        }
        public void AddSerializedDataIgnoresFailureToReadPropertiesForExceptionData()
        {
            var key   = Guid.NewGuid().ToString();
            var value = new SerializeFailure
            {
                Name = Guid.NewGuid().ToString()
            };

            var sut = new TimeoutException();

            sut.AddSerializedData(key, value);

            var expected = sut.Data[key] as string;

            expected.Should().Be(typeof(SerializeFailure).FullName);
        }
        public void AddSerializedDataAppendsSerializedValueToException()
        {
            var key      = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
            var value    = Model.Create <Company>();
            var expected = JsonConvert.SerializeObject(value, ExceptionData.SerializerSettings);

            var sut = new TimeoutException();

            sut.AddSerializedData(key, value);

            var actual = sut.Data[key].As <string>();

            _output.WriteLine("Stored data is: {0}", actual);

            actual.Should().Be(expected);
        }
        public void AddSerializedDataAppendsSerializedNonSystemValueType()
        {
            var key      = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
            var value    = SystemClock.Instance.GetCurrentInstant();
            var expected = JsonConvert.SerializeObject(value, ExceptionData.SerializerSettings);

            var sut = new TimeoutException();

            sut.AddSerializedData(key, value);

            var actual = sut.Data[key];

            _output.WriteLine("Stored data is: {0}", actual);

            actual.Should().Be(expected);
        }
        public void AddSerializedDataValidatesKeyValueTest(string key, bool isValid)
        {
            var value = Guid.NewGuid().ToString();

            var sut = new TimeoutException();

            Action action = () => sut.AddSerializedData(key, value);

            if (isValid)
            {
                action.Should().NotThrow();
            }
            else
            {
                action.Should().Throw <ArgumentException>();
            }
        }
        public void AddSerializedDataOnlyAppendsStringsWithContentsTest(string value, bool expected)
        {
            var key = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);

            var sut = new TimeoutException();

            sut.AddSerializedData(key, value);

            var actual = sut.Data[key];

            _output.WriteLine("Stored data is: {0}", actual);

            if (expected)
            {
                actual.Should().Be(value);
            }
            else
            {
                sut.Data.Contains(key).Should().BeFalse();
                actual.Should().BeNull();
            }
        }