コード例 #1
0
        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);
        }
コード例 #2
0
        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>();
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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>();
            }
        }
コード例 #11
0
        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();
            }
        }