public void WHEN_Delimiter_Set_For_LookupAttribute_LookupDelimiter_SHOULD_Be_Equivalent()
        {
            var property = GetType().GetProperty("LookupProperty2");

            var sut = new InstancePropertyMetadata(property);

            sut.LookupDelimiter.Should().Be("-");
        }
        public void WHEN_LookupAttributePresent_SHOULD_Lookup_Properties_Be_Set()
        {
            var property = GetType().GetProperty("LookupProperty");

            var sut = new InstancePropertyMetadata(property);

            sut.LookupProperty.Should().BeTrue();
            sut.LookupName.Should().Be("Brand");
            sut.LookupDelimiter.Should().Be(", ");
        }
        public void WHEN_ViewModel_Is_Null_SHOULD_Throw_ArgumentNullException()
        {
            // Arrange
            var propertyInfo = typeof(TestViewModel).GetProperty("Property");
            var sut          = new InstancePropertyMetadata(propertyInfo);

            // Act
            Action action = () => sut.GetValue(null);

            // Assert
            action.ShouldThrow <ArgumentNullException>();
        }
        public void WHEN_PropertyInfo_Has_A_DisplayNameAttribute_SHOULD_Use_It_As_Display_Name()
        {
            // Arrange
            var propertyInfo = GetType().GetProperty("PropertyWithDisplayName");

            // Act
            var sut = new InstancePropertyMetadata(propertyInfo);

            // Assert
            sut.PropertyName.Should().Be("PropertyWithDisplayName");
            sut.DisplayName.Should().Be("Dummy");
            sut.PropertyType.Should().Be(typeof(int));
        }
        public void WHEN_Property_Has_FormattingAttribute_SHOULD_Formatting_Properties_Be_Set()
        {
            // Arrange
            var property = GetType().GetProperty("PropertyWithFormattingAttribute");

            // Act
            var sut = new InstancePropertyMetadata(property);

            // Assert
            sut.FormattableProperty.Should().BeTrue();
            sut.PropertyFormattingCategory.Should().Be(FormattingCategory);
            sut.PropertyFormattingKey.Should().Be(FormattingKey);
        }
        public void WHEN_Value_Is_Null_And_Property_Is_Value_Type_SHOULD_Skip()
        {
            // Arrange
            var propertyInfo = typeof(TestViewModel).GetProperty("IntProperty");
            var sut          = new InstancePropertyMetadata(propertyInfo);
            var viewModel    = new TestViewModel();

            // Act
            sut.SetValue(viewModel, null);

            // Assert
            viewModel.IntProperty.Should().Be(default(int));
        }
        public void WHEN_Value_Is_Null_And_Property_Is_Reference_Type_SHOULD_Pass()
        {
            // Arrange
            var propertyInfo = typeof(TestViewModel).GetProperty("StringProperty");
            var sut          = new InstancePropertyMetadata(propertyInfo);
            var viewModel    = new TestViewModel();

            // Act
            sut.SetValue(viewModel, null);

            // Assert
            viewModel.StringProperty.Should().Be(null);
        }
        public void WHEN_PropertyInfo_Is_Valid_SHOULD_Pass()
        {
            // Arrange
            var propertyInfo = GetType().GetProperty("Property");

            // Act
            var sut = new InstancePropertyMetadata(propertyInfo);

            // Assert
            sut.PropertyName.Should().Be("Property");
            sut.DisplayName.Should().Be("Property");
            sut.PropertyType.Should().Be(typeof(string));
            sut.FormattableProperty.Should().BeFalse();
            sut.LookupProperty.Should().BeFalse();
        }
        public void WHEN_ViewModel_And_Value_Are_Valid_SHOULD_Pass()
        {
            // Arrange
            var expectedPropertyValue = GetRandom.String(20);

            var propertyInfo = typeof(TestViewModel).GetProperty("StringProperty");
            var sut          = new InstancePropertyMetadata(propertyInfo);
            var viewModel    = new TestViewModel();

            // Act
            sut.SetValue(viewModel, expectedPropertyValue);

            // Assert
            viewModel.StringProperty.Should().Be(expectedPropertyValue);
        }
        public void WHEN_ViewModel_Is_Valid_SHOULD_Pass()
        {
            // Arrange
            var expectedPropertyValue = GetRandom.String(20);

            var propertyInfo = typeof(TestViewModel).GetProperty("Property");
            var sut          = new InstancePropertyMetadata(propertyInfo);
            var viewModel    = new TestViewModel {
                Property = expectedPropertyValue
            };

            // Act
            var result = sut.GetValue(viewModel);

            // Assert
            result.Should().Be(expectedPropertyValue);
        }