public void CreateMetadata_WithDisplayAttributeMatchingResourceKey_ReturnsResourceValue()
        {
            var model = new TestModel {PropertyWithDisplayAttributeMatchingResourceKey = "HelloWorld"};
            var provider = new ConventionalModelMetadataProvider(false);

            var metadata = provider.GetMetadataForProperty(() => model, model.GetType(),
                "PropertyWithDisplayAttributeMatchingResourceKey");

            Assert.Equal("Property With Display Name From Resource File", metadata.DisplayName);
        }
        public void CreateMetadata_WithDisplayAttributeNorResourceWithName_ReturnsSpecifiedName()
        {
            var model = new TestModel {PropertyWithDisplayAttributeHavingName = "HelloWorld"};
            var provider = new ConventionalModelMetadataProvider(false);

            var metadata = provider.GetMetadataForProperty(() => model, model.GetType(),
                "PropertyWithDisplayAttributeHavingName");

            Assert.Equal("Property That Has A Display Attribute With A Name", metadata.DisplayName);
        }
        public void CreateMetadata_WithFullDisplayAttribute_ReturnsResourceValue()
        {
            var model = new TestModel {PropertyWithFullDisplayAttribute = "HelloWorld"};
            var provider = new ConventionalModelMetadataProvider(false);

            var metadata = provider.GetMetadataForProperty(() => model, model.GetType(),
                "PropertyWithFullDisplayAttribute");

            Assert.Equal("Property with full display attribute.", metadata.DisplayName);
        }
        public void CreateMetadata_WithPropertyMatchingResourceKey_ReturnsResourceValue()
        {
            // arrange
            var model = new TestModel { PropertyWithMatchingResourceKey = "HelloWorld" };
            var provider = new ConventionalModelMetadataProvider(requireConventionAttribute: false);

            // act
            var metadata = provider.GetMetadataForProperty(() => model, model.GetType(), "PropertyWithMatchingResourceKey");

            // assert
            Assert.Equal("Property With Property Name Matching Resource File", metadata.DisplayName);
        }
        public void Replace_WithEnumerationAndNullSource_ReturnsNewEnumerationWithItemReplaced()
        {
            // arrange
            var replacement = new TestModel { Id = 5 };
            var items = new TestModel[] {
                new TestModel { Id = 1 },
                new TestModel { Id = 3 },
                new TestModel { Id = 4 },
            };

            // act
            var newItems = items.Replace(null, replacement);

            // assert
            Assert.Contains(replacement, newItems);
        }
        public void Replace_WithEnumeration_ReturnsNewEnumerationWithItemReplaced()
        {
            // arrange
            var testModel = new TestModel { Id = 2 };
            var replacement = new TestModel { Id = 5 };
            var items = new TestModel[] {
                new TestModel { Id = 1 },
                testModel,
                new TestModel { Id = 3 },
                new TestModel { Id = 4 },
            };

            // act
            var newItems = items.Replace(testModel, replacement);

            // assert
            Assert.Contains(replacement, newItems);
            Assert.DoesNotContain(testModel, newItems);
        }