public void Constructor_WithParameters_CreatesNewInstance()
        {
            // Call
            var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.Name),
                                                                                             nameof(TestObject.Unit),
                                                                                             nameof(TestObject.Value));

            // Assert
            Assert.IsInstanceOf <Attribute>(attribute);
        }
        public void GetValue_InvalidValueProperty_ThrowsArgumentException()
        {
            // Setup
            var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.Name),
                                                                                             nameof(TestObject.Unit),
                                                                                             "IDoNotExist");

            // Call
            void Call() => attribute.GetValue(new TestObject());

            // Assert
            const string expectedMessage = "Value property 'IDoNotExist' was not found on type TestObject.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(Call, expectedMessage);
        }
        public void GetValue_WithObjectWithRoundedDoubleProperty_ReturnsValueOfPropertyWithoutTrailingZeroes(double doubleValue, string expectedResult)
        {
            // Setup
            var roundedDoubleValue = new RoundedDouble(5, doubleValue);
            var attribute          = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.Name),
                                                                                                      nameof(TestObject.Unit),
                                                                                                      nameof(TestObject.Value));

            // Call
            string value = attribute.GetValue(new TestObject
            {
                Value = roundedDoubleValue
            });

            // Assert
            Assert.AreEqual(expectedResult, value);
        }
        public void GetName_ValidProperties_ReturnsExpectedValue()
        {
            // Setup
            const string expectedName = "expectedName";
            const string expectedUnit = "kN";

            var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.Name),
                                                                                             nameof(TestObject.Unit),
                                                                                             nameof(TestObject.Value));

            // Call
            string name = attribute.GetName(new TestObject
            {
                Name = expectedName,
                Unit = expectedUnit
            });

            // Assert
            Assert.AreEqual($"{expectedName} [{expectedUnit}]", name);
        }
        public void GetValue_WithObjectWithNonStringProperty_ThrowsArgumentException()
        {
            // Setup
            int expectedValue = new Random(21).Next(3, 50);

            var attribute = new KeyValueAsRoundedDoubleWithoutTrailingZeroesElementAttribute(nameof(TestObject.Name),
                                                                                             nameof(TestObject.Unit),
                                                                                             nameof(TestObject.NonRoundedDoubleValue));

            // Call
            void Call() =>
            attribute.GetValue(new TestObject
            {
                NonRoundedDoubleValue = expectedValue
            });

            // Assert
            const string expectedMessage = "Value property 'NonRoundedDoubleValue' was not of type RoundedDouble.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(Call, expectedMessage);
        }