/// <summary>
 /// Determines whether the specified <see cref="ExceptionCentricTestSpecification" /> is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="ExceptionCentricTestSpecification" /> to compare with this instance.</param>
 /// <returns>
 ///   <c>true</c> if the specified <see cref="ExceptionCentricTestSpecification" /> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 protected bool Equals(ExceptionCentricTestSpecification other)
 {
     return
         (Equals(_givens, other._givens) &&
          Equals(_when, other._when) &&
          Equals(_throws, other._throws));
 }
コード例 #2
0
 void WriteThrows(ExceptionCentricTestSpecification specification)
 {
     _writer.WriteLine("Throws");
     _writer.Indent++;
     _writer.WriteLine("[{0}] {1}", specification.Throws.GetType().Name, specification.Throws.Message);
     _writer.Indent--;
 }
コード例 #3
0
 void WriteThrows(ExceptionCentricTestSpecification specification)
 {
     _writer.WriteLine("Throws");
     _writer.Indent++;
     _writer.WriteLine("[{0}] {1}", specification.Throws.GetType().Name, specification.Throws.Message);
     _writer.Indent--;
 }
コード例 #4
0
        void WriteGivens(ExceptionCentricTestSpecification specification)
        {
            if (specification.Givens.Length == 0) return;

            _writer.WriteLine("Given");
            WriteFacts(specification.Givens);
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionCentricTestResult"/> class.
 /// </summary>
 /// <param name="specification">The specification.</param>
 /// <param name="state">The state.</param>
 /// <param name="actualException">The actual exception.</param>
 /// <param name="actualEvents">The actual events.</param>
 internal ExceptionCentricTestResult(ExceptionCentricTestSpecification specification, TestResultState state,
                                     Optional<Exception> actualException,
                                     Optional<Fact[]> actualEvents)
 {
     _specification = specification;
     _state = state;
     _actualException = actualException;
     _actualEvents = actualEvents;
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionCentricTestResult"/> class.
 /// </summary>
 /// <param name="specification">The specification.</param>
 /// <param name="state">The state.</param>
 /// <param name="actualException">The actual exception.</param>
 /// <param name="actualEvents">The actual events.</param>
 internal ExceptionCentricTestResult(ExceptionCentricTestSpecification specification, TestResultState state,
                                     Optional <Exception> actualException,
                                     Optional <Fact[]> actualEvents)
 {
     _specification   = specification;
     _state           = state;
     _actualException = actualException;
     _actualEvents    = actualEvents;
 }
        public void UsingDefaultConstructorReturnsInstanceWithExpectedProperties(Tuple <string, object>[] givens,
                                                                                 object when, Exception throws)
        {
            var sut = new ExceptionCentricTestSpecification(givens, when, throws);

            Assert.That(sut.Givens, Is.EquivalentTo(givens));
            Assert.That(sut.When, Is.SameAs(when));
            Assert.That(sut.Throws, Is.SameAs(throws));
        }
コード例 #8
0
        public void FailReturnsExpectedResult()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);
            var result = sut.Fail();

            Assert.That(result.Specification, Is.SameAs(sut));
            Assert.That(result.Passed, Is.False);
            Assert.That(result.Failed, Is.True);
            Assert.That(result.But, Is.EqualTo(Optional<Exception>.Empty));
        }
コード例 #9
0
        void WriteGivens(ExceptionCentricTestSpecification specification)
        {
            if (specification.Givens.Length == 0)
            {
                return;
            }

            _writer.WriteLine("Given");
            WriteEvents(specification.Givens);
        }
        public void FailReturnsExpectedResult()
        {
            var sut    = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);
            var result = sut.Fail();

            Assert.That(result.Specification, Is.SameAs(sut));
            Assert.That(result.Passed, Is.False);
            Assert.That(result.Failed, Is.True);
            Assert.That(result.But, Is.EqualTo(Optional <Exception> .Empty));
        }
        public void FailWithActualExceptionReturnsExpectedResult()
        {
            var sut    = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);
            var actual = new Exception();

            var result = sut.Fail(actual);

            Assert.That(result.Specification, Is.SameAs(sut));
            Assert.That(result.Passed, Is.False);
            Assert.That(result.Failed, Is.True);
            Assert.That(result.ButException, Is.EqualTo(new Optional <Exception>(actual)));
        }
コード例 #12
0
        public void WriteExceptionCentricTestSpecificationResultsInExpectedOutput(
            ExceptionCentricTestSpecification specification, string result)
        {
            using (var writer = new StringWriter())
            {
                var sut = new TestSpecificationTextWriter(writer);

                sut.Write(specification);

                Assert.That(writer.ToString(), Is.EqualTo(result));
            }
        }
コード例 #13
0
        public void WriteExceptionCentricTestSpecificationResultsInExpectedOutput(
            ExceptionCentricTestSpecification specification, string result)
        {
            using (var writer = new StringWriter())
            {
                var sut = new TestSpecificationTextWriter(writer);

                sut.Write(specification);

                Assert.That(writer.ToString(), Is.EqualTo(result));
            }
        }
        public void FailWithActualExceptionReturnsExpectedResult()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);
            var actual = new Exception();

            var result = sut.Fail(actual);

            Assert.That(result.Specification, Is.SameAs(sut));
            Assert.That(result.Passed, Is.False);
            Assert.That(result.Failed, Is.True);
            Assert.That(result.ButException, Is.EqualTo(new Optional<Exception>(actual)));
        }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionCentricTestResult"/> class.
 /// </summary>
 /// <param name="specification">The specification.</param>
 /// <param name="state">The state.</param>
 /// <param name="actualException">The actual exception.</param>
 /// <param name="actualEvents">The actual events.</param>
 internal ExceptionCentricTestResult(ExceptionCentricTestSpecification specification, TestResultState state,
                                     Exception actualException = null,
                                     Tuple<string, object>[] actualEvents = null)
 {
     _specification = specification;
     _state = state;
     _actualException = actualException == null
                            ? Optional<Exception>.Empty
                            : new Optional<Exception>(actualException);
     _actualEvents = actualEvents == null
                         ? Optional<Tuple<string, object>[]>.Empty
                         : new Optional<Tuple<string, object>[]>(actualEvents);
 }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExceptionCentricTestResult"/> class.
 /// </summary>
 /// <param name="specification">The specification.</param>
 /// <param name="state">The state.</param>
 /// <param name="actualException">The actual exception.</param>
 /// <param name="actualEvents">The actual events.</param>
 internal ExceptionCentricTestResult(ExceptionCentricTestSpecification specification, TestResultState state,
                                     Exception actualException             = null,
                                     Tuple <string, object>[] actualEvents = null)
 {
     _specification   = specification;
     _state           = state;
     _actualException = actualException == null
                            ? Optional <Exception> .Empty
                            : new Optional <Exception>(actualException);
     _actualEvents = actualEvents == null
                         ? Optional <Tuple <string, object>[]> .Empty
                         : new Optional <Tuple <string, object>[]>(actualEvents);
 }
        public void FailWithActualEventsReturnsExpectedResult()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            var actual = new[] { new Tuple <string, object>(Model.Identifier1, new object()) };

            var result = sut.Fail(actual);

            Assert.That(result.Specification, Is.SameAs(sut));
            Assert.That(result.Passed, Is.False);
            Assert.That(result.Failed, Is.True);
            Assert.That(result.Buts, Is.EqualTo(new Optional <Tuple <string, object>[]>(actual)));
            Assert.That(result.But, Is.EqualTo(Optional <Exception> .Empty));
        }
コード例 #18
0
        public void FailWithActualEventsReturnsExpectedResult()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            var actual = new[] {new Tuple<string, object>(Model.Identifier1, new object())};

            var result = sut.Fail(actual);

            Assert.That(result.Specification, Is.SameAs(sut));
            Assert.That(result.Passed, Is.False);
            Assert.That(result.Failed, Is.True);
            Assert.That(result.Buts, Is.EqualTo(new Optional<Tuple<string, object>[]>(actual)));
            Assert.That(result.But, Is.EqualTo(Optional<Exception>.Empty));
        }
コード例 #19
0
        public void DoesEqualItself()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            Assert.That(sut.Equals(sut), Is.True);
        }
コード例 #20
0
        public void UsingDefaultConstructorReturnsInstanceWithExpectedProperties(Tuple<string, object>[] givens,
                                                                                 object when, Exception throws)
        {
            var sut = new ExceptionCentricTestSpecification(givens, when, throws);

            Assert.That(sut.Givens, Is.EquivalentTo(givens));
            Assert.That(sut.When, Is.SameAs(when));
            Assert.That(sut.Throws, Is.SameAs(throws));
        }
コード例 #21
0
 void WriteWhen(ExceptionCentricTestSpecification specification)
 {
     _writer.WriteLine("When");
     WriteMessage(specification.When);
 }
コード例 #22
0
        public void DoesNotEqualNull()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            Assert.That(sut.Equals(null), Is.False);
        }
コード例 #23
0
 /// <summary>
 /// Writes the specified test specification.
 /// </summary>
 /// <param name="specification">The test specification to write.</param>
 public void Write(ExceptionCentricTestSpecification specification)
 {
     WriteGivens(specification);
     WriteWhen(specification);
     WriteThrows(specification);
 }
コード例 #24
0
        public void DoesNotEqualObjectOfOtherType()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            Assert.That(sut.Equals(new object()), Is.False);
        }
コード例 #25
0
 void WriteWhen(ExceptionCentricTestSpecification specification)
 {
     _writer.WriteLine("When");
     WriteMessage(specification.When);
 }
        public void DoesEqualItself()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            Assert.That(sut.Equals(sut), Is.True);
        }
コード例 #27
0
        public void FailWithNullExceptionThrows()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            Assert.Throws<ArgumentNullException>(() => { var _ = sut.Fail((Exception) null); });
        }
        public void DoesNotEqualObjectOfOtherType()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            Assert.That(sut.Equals(new object()), Is.False);
        }
        public void DoesNotEqualNull()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            Assert.That(sut.Equals(null), Is.False);
        }
コード例 #30
0
 /// <summary>
 /// Determines whether the specified <see cref="ExceptionCentricTestSpecification" /> is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="ExceptionCentricTestSpecification" /> to compare with this instance.</param>
 /// <returns>
 ///   <c>true</c> if the specified <see cref="ExceptionCentricTestSpecification" /> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 protected bool Equals(ExceptionCentricTestSpecification other)
 {
     return
         Equals(_givens, other._givens) &&
         Equals(_when, other._when) &&
         Equals(_throws, other._throws);
 }
        public void FailWithNullEventsThrows()
        {
            var sut = new ExceptionCentricTestSpecification(NoEvents, Message, Exception);

            Assert.Throws <ArgumentNullException>(() => { var _ = sut.Fail((Tuple <string, object>[])null); });
        }
コード例 #32
0
 /// <summary>
 /// Writes the specified test specification.
 /// </summary>
 /// <param name="specification">The test specification to write.</param>
 public void Write(ExceptionCentricTestSpecification specification)
 {
     WriteGivens(specification);
     WriteWhen(specification);
     WriteThrows(specification);
 }