Exemplo n.º 1
0
            public void Should_return_null_for_missing_enumeration()
            {
                var result = TestEnumeration.TryParse("Three", out TestEnumeration enumeration);

                AssertHelper.All(() => result.ShouldBeFalse(),
                                 () => enumeration.ShouldBeNull());
            }
Exemplo n.º 2
0
            public void Should_get_an_object_by_int32()
            {
                var result = TestEnumeration.TryFromInt32(2, out TestEnumeration enumeration);

                AssertHelper.All(() => result.ShouldBeTrue(),
                                 () => enumeration.ShouldNotBeNull(),
                                 () => enumeration.ShouldBe(TestEnumeration.Two));
            }
Exemplo n.º 3
0
            public void Should_get_an_object_by_display_name()
            {
                var result = TestEnumeration.TryParse("One", out TestEnumeration enumeration);

                AssertHelper.All(() => result.ShouldBeTrue(),
                                 () => enumeration.ShouldNotBeNull(),
                                 () => enumeration.ShouldBe(TestEnumeration.One));
            }
Exemplo n.º 4
0
            public void Should_get_an_object_by_predicate()
            {
                var result = TestEnumeration.TryParse(x => x.DisplayName.Equals("Two"), out TestEnumeration enumeration);

                AssertHelper.All(() => result.ShouldBeTrue(),
                                 () => enumeration.ShouldNotBeNull(),
                                 () => enumeration.ShouldBe(TestEnumeration.Two));
            }
Exemplo n.º 5
0
        public void Translate()
        {
            // Arrange
            const TestEnumeration TestValue = TestEnumeration.TranslatableValue;

            // Act
            var result = TestValue.Translate <TestEnumeration, AnotherTestEnumeration>();

            // Assert
            result.Should().Be(AnotherTestEnumeration.TranslatableValue);
        }
Exemplo n.º 6
0
        public void Should_be_equal_to_another_instance_with_the_same_id()
        {
            //Arrange
            var sut     = new TestEnumeration(3, "aaa");
            var another = new TestEnumeration(3, "bbb");

            //Act
            var areEqual = sut.Equals(another) && sut == another;

            //Assert
            areEqual.Should().BeTrue();
        }
Exemplo n.º 7
0
        public void Given_an_instance_of_Enumeration_When_ToString_is_called_Then_the_DisplayName_should_be_returned(string keyCode, string displayName)
        {
            // Arrange.
            Enumeration instanceOfEnumeration = new TestEnumeration(keyCode, displayName);
            string      expected = instanceOfEnumeration.DisplayName;

            // Act.
            string actual = instanceOfEnumeration.ToString();

            // Assert.
            actual.Should().Be(expected);
        }
Exemplo n.º 8
0
        public void Given_other_enumeration_has_a_KeyCode_with_a_lower_value_When_CompareTo_is_called_Then_result_should_be_1()
        {
            // Arrange.
            Enumeration enumeration      = new TestEnumeration("B", "other enumeration");
            Enumeration otherEnumeration = new TestEnumeration("A", "enumeration");

            // Act.
            int result = enumeration.CompareTo(otherEnumeration);

            // Assert.
            result.Should().Be(1);
        }
Exemplo n.º 9
0
        public void Should_support_serialization()
        {
            //Arrange
            var sut = new TestEnumeration(3, "sadasd asd asdsd p qwevndofgewrio qwrlhw eqhncqw ehtuwehgfqwlerg");

            //Act
            var serializedEntity   = JsonConvert.SerializeObject(sut);
            var deserializedEntity = JsonConvert.DeserializeObject <TestEnumeration>(serializedEntity);

            //Assert
            deserializedEntity.Should().Be(sut);
        }
Exemplo n.º 10
0
        public void Given_an_instance_of_Enumeration_When_GetHashCode_is_called_Then_the_hash_of_KeyCode_should_be_returned(string keyCode, string displayName)
        {
            // Arrange.
            Enumeration instanceOfEnumeration = new TestEnumeration(keyCode, displayName);
            int         expectedHashCode      = instanceOfEnumeration.KeyCode.GetHashCode();

            // Act.
            int actualHashCode = instanceOfEnumeration.GetHashCode();

            // Assert.
            actualHashCode.Should().Be(expectedHashCode);
        }
Exemplo n.º 11
0
        public void Given_both_enumerations_have_the_same_KeyCode_value_and_Type_When_Equality_operator_is_invoked_Then_true_should_be_returned()
        {
            // Arrange.
            Enumeration enumeration      = new TestEnumeration("BEANS", "are great");
            Enumeration otherEnumeration = new TestEnumeration("BEANS", "are good");

            // Act.
            bool result = enumeration == otherEnumeration;

            // Assert.
            enumeration.Should().NotBeSameAs(otherEnumeration);
            result.Should().BeTrue();
        }
Exemplo n.º 12
0
        public void Given_both_enumerations_have_the_same_KeyCode_value_and_Type_When_Inequality_operator_is_invoked_Then_false_should_be_returned()
        {
            // Arrange.
            Enumeration enumeration      = new TestEnumeration("BEANS", "Beans");
            Enumeration otherEnumeration = new TestEnumeration("BEANS", "Maybe not");

            // Act.
            bool result = enumeration != otherEnumeration;

            // Assert.
            enumeration.Should().NotBeSameAs(otherEnumeration);
            result.Should().BeFalse();
        }
Exemplo n.º 13
0
        public void Given_an_object_which_has_the_same_KeyCode_value_and_extends_Enumeration_but_is_not_of_the_same_Type_When_Equals_is_called_Then_false_should_be_returned()
        {
            // Arrange.
            Enumeration enumeration = EmployeeType.Permanent;
            Enumeration enumerationWithSameKeyCodeValue = new TestEnumeration(enumeration.KeyCode, "display name");

            // Act.
            bool result = enumeration.Equals(enumerationWithSameKeyCodeValue);

            // Assert.
            enumeration.KeyCode.Should().BeEquivalentTo(enumerationWithSameKeyCodeValue.KeyCode);
            result.Should().BeFalse();
        }
Exemplo n.º 14
0
        public void Given_both_enumerations_have_the_same_KeyCode_value_but_different_Type_When_Inequality_operator_is_invoked_Then_true_should_be_returned()
        {
            // Arrange.
            Enumeration enumeration      = EmployeeType.Permanent;
            Enumeration otherEnumeration = new TestEnumeration(enumeration.KeyCode, enumeration.DisplayName);

            // Act.
            bool result = enumeration != otherEnumeration;

            // Assert.
            enumeration.Should().NotBeSameAs(otherEnumeration);
            result.Should().BeTrue();
        }
Exemplo n.º 15
0
        public void Given_other_object_is_null_When_CompareTo_is_called_Then_an_ArgumentNullException_should_be_thrown()
        {
            // Arrange.
            Enumeration enumeration = new TestEnumeration("B", "other enumeration");
            object      otherObject = null;

            // Act.
            Action testCode = () => enumeration.CompareTo(otherObject);

            // Assert.
            testCode.Should()
            .Throw <ArgumentNullException>()
            .WithMessage("*cannot be null*Parameter name: other*");
        }
Exemplo n.º 16
0
        public void Given_other_object_is_not_of_type_Enumeration_When_CompareTo_is_called_Then_an_ArgumentException_should_be_thrown()
        {
            // Arrange.
            Enumeration enumeration = new TestEnumeration("B", "other enumeration");
            object      otherObject = new { something = "1" };

            // Act.
            Action testCode = () => enumeration.CompareTo(otherObject);

            // Assert.
            testCode.Should()
            .Throw <ArgumentException>()
            .WithMessage($"*expected to be of type [{typeof(Enumeration)}]*found [{otherObject.GetType()}]*Parameter name: other*");
        }
Exemplo n.º 17
0
        public void Given_an_object_which_has_the_same_KeyCode_value_and_has_the_same_Type_When_Equals_is_called_Then_true_should_be_returned()
        {
            // Arrange.
            Enumeration enumeration      = new TestEnumeration("SALAD", "Yummy yummy");
            Enumeration otherEnumeration = new TestEnumeration("SALAD", "In my tummy");

            // Act.
            bool result = enumeration.Equals(otherEnumeration);

            // Assert.
            // Ensure that we are asserting that Equals does equivalency by value of `KeyCode` rather than by reference equality.
            enumeration.Should().NotBeSameAs(otherEnumeration);
            result.Should().BeTrue();
        }
Exemplo n.º 18
0
 public void InvalidCast(TestEnumeration e)
 {
 }
Exemplo n.º 19
0
 public void Should_return_null_when_searching_by_nonexistent_id()
 {
     TestEnumeration.GetById("foo")
     .ShouldBeNull();
 }
Exemplo n.º 20
0
 public void ArgumentException(TestEnumeration e)
 {
 }
Exemplo n.º 21
0
 public void Should_retrieve_value_by_id()
 {
     TestEnumeration.GetById("1")
     .ShouldBe(TestEnumeration.One);
 }
Exemplo n.º 22
0
 public void Setup()
 {
     _results = TestEnumeration.GetValues();
 }
Exemplo n.º 23
0
 public void Should_retrive_value_with_null_id()
 {
     TestEnumeration.GetById(null)
     .ShouldBe(TestEnumeration.Null);
 }
Exemplo n.º 24
0
 public void InvalidCast(TestEnumeration e)
 {
 }
Exemplo n.º 25
0
 public void ArgumentException(TestEnumeration e)
 {
 }