public void WHEN_Property_Has_LookupAttribute_Lookup_Properties_SHOULD_Be_Set()
        {
            var property = GetType().GetProperty("LookupProperty");

            var sut = new BagPropertyMetadata(property);

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

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

            // Assert
            action.ShouldThrow <ArgumentNullException>();
        }
        public void WHEN_Property_Has_Not_Been_Initialized_SHOULD_Return_Default()
        {
            // Arrange
            var propertyInfo = typeof(TestViewModel).GetProperty("Property");
            var sut          = new BagPropertyMetadata(propertyInfo);
            var viewModel    = new TestViewModel();

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

            // Assert
            result.Should().Be(default(DateTime));
        }
        public void WHEN_Property_Has_FormattingAttribute_SHOULD_Formatting_Properties_Be_Set()
        {
            // Arrange
            var property = GetType().GetProperty("PropertyWithFormattingAttribute");

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

            // Assert
            sut.FormattableProperty.Should().BeTrue();
            sut.PropertyFormattingCategory.Should().Be(FormattingCategory);
            sut.PropertyFormattingKey.Should().Be(FormattingKey);
        }
        public void WHEN_PropertyInfo_Has_A_DisplayNameAttribute_SHOULD_Use_It_As_Display_Name()
        {
            // Arrange
            var propertyInfo = GetType().GetProperty("PropertyWithDisplayName");

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

            // Assert
            sut.PropertyName.Should().Be("PropertyWithDisplayName");
            sut.DisplayName.Should().Be("Dummy");
            sut.PropertyType.Should().Be(typeof(int));
        }
Beispiel #6
0
        public void WHEN_Value_Is_Null_SHOULD_Assign_Null()
        {
            // Arrange
            var propertyInfo = typeof(TestViewModel).GetProperty("StringProperty");
            var sut          = new BagPropertyMetadata(propertyInfo);
            var viewModel    = new TestViewModel();

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

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

            // Act
            var sut = new BagPropertyMetadata(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_Is_Valid_SHOULD_Pass()
        {
            // Arrange
            var expectedValue = GetRandom.DateTime();
            var propertyInfo  = typeof(TestViewModel).GetProperty("Property");
            var sut           = new BagPropertyMetadata(propertyInfo);
            var viewModel     = new TestViewModel();

            sut.SetValue(viewModel, expectedValue);

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

            // Assert
            result.Should().Be(expectedValue);
        }
Beispiel #9
0
        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 BagPropertyMetadata(propertyInfo);
            var viewModel    = new TestViewModel();

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

            // Assert
            viewModel.Bag.Should().ContainKey("StringProperty");
            viewModel.Bag["StringProperty"].Should().Be(expectedPropertyValue);
        }