示例#1
0
        public void MultipleAttributesCanSetValuesOnMetadata()
        {
            // Arrange
            string name1 = "name1";
            string name2 = "name2";

            object value1 = new object();
            object value2 = new object();
            object value3 = new object();

            ModelMetadata modelMetadata       = new ModelMetadata(new Mock <ModelMetadataProvider>().Object, null, null, typeof(object), null);
            AdditionalMetadataAttribute attr1 = new AdditionalMetadataAttribute(name1, value1);
            AdditionalMetadataAttribute attr2 = new AdditionalMetadataAttribute(name2, value2);
            AdditionalMetadataAttribute attr3 = new AdditionalMetadataAttribute(name1, value3);

            // Act
            attr1.OnMetadataCreated(modelMetadata);
            attr2.OnMetadataCreated(modelMetadata);
            attr3.OnMetadataCreated(modelMetadata);

            // Assert
            Assert.Equal(2, modelMetadata.AdditionalValues.Count);
            Assert.Equal(modelMetadata.AdditionalValues[name1], value3);
            Assert.Equal(modelMetadata.AdditionalValues[name2], value2);

            Assert.NotEqual(attr1.TypeId, attr2.TypeId);
            Assert.NotEqual(attr2.TypeId, attr3.TypeId);
            Assert.NotEqual(attr3.TypeId, attr1.TypeId);
        }
        public void MultipleAttributesCanSetValuesOnMetadata()
        {
            // Arrange
            string name1 = "name1";
            string name2 = "name2";

            object value1 = new object();
            object value2 = new object();
            object value3 = new object();

            ModelMetadata modelMetadata = new ModelMetadata(new Mock<ModelMetadataProvider>().Object, null, null, typeof(object), null);
            AdditionalMetadataAttribute attr1 = new AdditionalMetadataAttribute(name1, value1);
            AdditionalMetadataAttribute attr2 = new AdditionalMetadataAttribute(name2, value2);
            AdditionalMetadataAttribute attr3 = new AdditionalMetadataAttribute(name1, value3);

            // Act
            attr1.OnMetadataCreated(modelMetadata);
            attr2.OnMetadataCreated(modelMetadata);
            attr3.OnMetadataCreated(modelMetadata);

            // Assert
            Assert.Equal(2, modelMetadata.AdditionalValues.Count);
            Assert.Equal(modelMetadata.AdditionalValues[name1], value3);
            Assert.Equal(modelMetadata.AdditionalValues[name2], value2);

            Assert.NotEqual(attr1.TypeId, attr2.TypeId);
            Assert.NotEqual(attr2.TypeId, attr3.TypeId);
            Assert.NotEqual(attr3.TypeId, attr1.TypeId);
        }
        public void NameValueProperties() {
            // Act
            AdditionalMetadataAttribute attr = new AdditionalMetadataAttribute("someName", "someValue");

            // Assert
            Assert.AreEqual("someName", attr.Name);
            Assert.AreEqual("someValue", attr.Value);
        }
        public void TypeIdProperty() {
            // Arrange
            AdditionalMetadataAttribute attrFoo1 = new AdditionalMetadataAttribute("foo", "fooValue1");
            AdditionalMetadataAttribute attrFoo2 = new AdditionalMetadataAttribute("Foo", "fooValue2");
            AdditionalMetadataAttribute attrBar = new AdditionalMetadataAttribute("bar", "barValue1");

            // Act & assert
            Assert.AreEqual(attrFoo1.TypeId.GetHashCode(), attrFoo2.TypeId.GetHashCode(), "TypeId hash codes should match - case insensitive comparison.");
            Assert.AreEqual(attrFoo1.TypeId, attrFoo2.TypeId, "TypeId values should match - case insentivie comparison.");
            Assert.AreNotEqual(attrFoo1.TypeId, attrBar.TypeId, "TypeId values should not match between 'foo' and 'bar' keys.");
        }
        public void GuardClauses() {
            // Act & assert
            ExceptionHelper.ExpectArgumentNullException(
                () => new AdditionalMetadataAttribute(null, new object()),
                "name");

            AdditionalMetadataAttribute attr = new AdditionalMetadataAttribute("key", null);
            ExceptionHelper.ExpectArgumentNullException(
                () => attr.OnMetadataCreated(null),
                "metadata");
        }
        public void GuardClauses()
        {
            // Act & assert
            Assert.ThrowsArgumentNull(
                () => new AdditionalMetadataAttribute(null, new object()),
                "name");

            AdditionalMetadataAttribute attr = new AdditionalMetadataAttribute("key", null);
            Assert.ThrowsArgumentNull(
                () => attr.OnMetadataCreated(null),
                "metadata");
        }
示例#7
0
        public void GuardClauses()
        {
            // Act & assert
            Assert.ThrowsArgumentNull(
                () => new AdditionalMetadataAttribute(null, new object()),
                "name"
                );

            AdditionalMetadataAttribute attr = new AdditionalMetadataAttribute("key", null);

            Assert.ThrowsArgumentNull(() => attr.OnMetadataCreated(null), "metadata");
        }
        public void OnMetadataCreated_SetsAdditionalValuesKey() {
            // Arrange
            ModelMetadata metadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(object));
            metadata.AdditionalValues["someKey"] = "oldValue";

            AdditionalMetadataAttribute attr = new AdditionalMetadataAttribute("someKey", "newValue");

            // Act
            ((IMetadataAware)attr).OnMetadataCreated(metadata);

            // Assert
            Assert.AreEqual("newValue", metadata.AdditionalValues["someKey"]);
        }
示例#9
0
        public void GuardClauses()
        {
            // Act & assert
            ExceptionHelper.ExpectArgumentNullException(
                () => new AdditionalMetadataAttribute(null, new object()),
                "name");

            AdditionalMetadataAttribute attr = new AdditionalMetadataAttribute("key", null);

            ExceptionHelper.ExpectArgumentNullException(
                () => attr.OnMetadataCreated(null),
                "metadata");
        }
        public void OnMetaDataCreatedSetsAdditionalValue() {
            // Arrange
            string name = "name";
            object value = new object();

            ModelMetadata modelMetadata = new ModelMetadata(new Mock<ModelMetadataProvider>().Object, null, null, typeof(object), null);
            AdditionalMetadataAttribute attr = new AdditionalMetadataAttribute(name, value);

            // Act
            attr.OnMetadataCreated(modelMetadata);

            // Assert
            Assert.AreEqual(modelMetadata.AdditionalValues[name], value);
            Assert.AreEqual(attr.Name, name);
            Assert.AreEqual(attr.Value, value);
        }
示例#11
0
        public void OnMetaDataCreatedSetsAdditionalValue()
        {
            // Arrange
            string name  = "name";
            object value = new object();

            ModelMetadata modelMetadata      = new ModelMetadata(new Mock <ModelMetadataProvider>().Object, null, null, typeof(object), null);
            AdditionalMetadataAttribute attr = new AdditionalMetadataAttribute(name, value);

            // Act
            attr.OnMetadataCreated(modelMetadata);

            // Assert
            Assert.Equal(modelMetadata.AdditionalValues[name], value);
            Assert.Equal(attr.Name, name);
            Assert.Equal(attr.Value, value);
        }