Beispiel #1
0
        public void SimpleTest()
        {
            // Arrange
            Test test = TestThat
                        .Given(() => new { x = 1, y = 1 })
                        .When(given => given.x + given.y)
#if NET6_0
                        .ThenReturns((_, sum) => sum.Should().Be(2));
Beispiel #2
0
        public void SimpleTest()
        {
            // Arrange
            Test test = TestThat
                        .Given(() => new StringBuilder())
                        .When(sb => { sb.Append('A'); })
#if NET6_0
                        .ThenReturns(sb => sb.Length.Should().Be(1));
Beispiel #3
0
        public void MinimalTest()
        {
            // Arrange
            Test test = TestThat
                        .When(() => 1)
                        .ThenReturns();

            // Act & Assert
            ((Action)(() => test.Arrange(new TestContext()))).Should().NotThrow();
            test.Cases.Count.Should().Be(1);

            ((Action)test.Cases.Single().Act).Should().NotThrow();
            test.Cases.Single().Assertions.Count.Should().Be(1);

            var assertion = test.Cases.Single().Assertions.Single();

            assertion.ToString().Should().Be("Test function should return successfully");
            ((Action)assertion.Assert).Should().NotThrow();
        }
Beispiel #4
0
        public void TriangleIsRight_FuzzyTest()
        {
            var rnd = new Random();

            var a = rnd.NextDouble();
            var b = rnd.NextDouble();
            var c = Math.Sqrt(a * a + b * b);

            if (a > b)
            {
                (a, b) = (b, a);
            }
            if (b > c)
            {
                (b, c) = (c, b);
            }

            var expected = Math.Abs(a * a + b * b - c * c) < Constants.FloatingPointPrecision;

            var actual = TestThat.TriangleIsRight(a, b, c);

            Assert.Equal(expected, actual);
        }
Beispiel #5
0
        public void TriangleIsRight_BasicTest(double a, double b, double c, bool expected)
        {
            var actual = TestThat.TriangleIsRight(a, b, c);

            Assert.Equal(expected, actual);
        }
Beispiel #6
0
        public void TriangleIsRight_NonPositiveArgumentsTest(double a, double b, double c)
        {
            var exception = Assert.Throws <ArgumentException>(() => TestThat.TriangleIsRight(a, b, c));

            Assert.StartsWith("Side length should not be negative.", exception.Message);
        }