Пример #1
0
        public static void CheckEitherLeft <TLeft>(EitherLeft <TLeft> either, [NotNull] TLeft expectedValue)
        {
            Assert.IsTrue(either.IsLeft);
            Assert.IsFalse(either.IsRight);

            CheckLeftEither <TLeft, int>(either, expectedValue); // Use int as fallback for right value, but it's not relevant
        }
Пример #2
0
        public void EitherLeftSerialization()
        {
            EitherLeft <int> either             = new EitherLeft <int>(42);
            EitherLeft <int> deserializedEither = SerializeAndDeserialize(either);

            CheckEitherLeft(deserializedEither, 42);
        }
Пример #3
0
        public void LeftShouldSucceed()
        {
            // Arrange
            var value = "value";

            // Act
            EitherLeft <string> left = Left <string>(value);

            // Assert
            left.ToString().Should().Be("Left(value)");
        }
Пример #4
0
        public void EqualsObjectShouldReturnFalseWhenFirstValueNull()
        {
            // Arrange
            var first  = new EitherLeft <string>(null);
            var second = new EitherLeft <string>("value");

            // Act
            var result = Equals(first, second);

            // Assert
            result.Should().BeFalse();
        }
Пример #5
0
        public void EqualsObjectShouldReturnFalseWhenDifferentTypes()
        {
            // Arrange
            var first  = new EitherLeft <string>("1");
            var second = new EitherLeft <int>(1);

            // Act
            var result = Equals(first, second);

            // Assert
            result.Should().BeFalse();
        }
Пример #6
0
        public void EqualsObjectShouldReturnFalseWhenSameTypeAndDifferentValues()
        {
            // Arrange
            var first  = new EitherLeft <string>("value1");
            var second = new EitherLeft <string>("value2");

            // Act
            var result = Equals(first, second);

            // Assert
            result.Should().BeFalse();
        }
Пример #7
0
        public void EqualsObjectShouldReturnTrueWhenBothValueSameNotNull()
        {
            // Arrange
            var first  = new EitherLeft <string>("value");
            var second = new EitherLeft <string>("value");

            // Act
            var result = Equals(first, second);

            // Assert
            result.Should().BeTrue();
        }
Пример #8
0
        public void CtorShouldSetCorrectValue()
        {
            // Arrange
            var value      = "left";
            var eitherLeft = new EitherLeft <string>(value);

            // Act
            var result = eitherLeft.Value;

            // Assert
            result.Should().Be(value);
        }
Пример #9
0
        public void EqualsEitherLeftShouldReturnFalse()
        {
            // Arrange
            var first  = new EitherLeft <string>("value1");
            var second = new EitherLeft <string>("value2");

            // Act
            var result = first.Equals(second);

            // Assert
            result.Should().BeFalse();
        }
Пример #10
0
        public void EqualsEitherLeftShouldReturnTrueWhenBothValueNull()
        {
            // Arrange
            var first  = new EitherLeft <string>(null);
            var second = new EitherLeft <string>(null);

            // Act
            var result = first.Equals(second);

            // Assert
            result.Should().BeTrue();
        }
Пример #11
0
        public void ToStringShouldProvideExpectedRepresentation()
        {
            // Arrange
            var value          = "left";
            var expectedResult = $"Left({value})";
            var eitherLeft     = new EitherLeft <string>(value);

            // Act
            var result = eitherLeft.ToString();

            // Assert
            result.Should().Be(expectedResult);
        }
Пример #12
0
        public void ImplicitOperatorOverloadingShouldSucceedWithEitherLeft()
        {
            // Arrange
            var value      = "value";
            var eitherLeft = new EitherLeft <string>(value);

            // Act
            Either <string, int> either = eitherLeft;
            var result = either.ToString();

            // Assert
            result.Should().Be("Left(value)");
        }