Beispiel #1
0
        public void Attributes_with_empty_values_are_valid_attributes()
        {
            var filter = new AttributeFilter(new AttributeFilter.Settings());

            var attribDef = AttributeDefinitionBuilder
                            .CreateCustomAttribute("test", AttributeDestinations.All)
                            .Build(filter);

            var attribVals = new AttributeValueCollection(AttributeValueCollection.AllTargetModelTypes);

            var trySetResult = attribDef.TrySetValue(attribVals, string.Empty);

            var actualAttribVal = attribVals.GetAttributeValues(AttributeClassification.UserAttributes)
                                  .FirstOrDefault(x => x.AttributeDefinition == attribDef);

            NrAssert.Multiple(
                () => Assert.IsTrue(trySetResult),
                () => Assert.AreEqual(string.Empty, actualAttribVal.Value)
                );
        }
Beispiel #2
0
        private void TestValue(object attributeValue, object expectedResult)
        {
            var filter = new AttributeFilter(new AttributeFilter.Settings());

            var attribDef = AttributeDefinitionBuilder
                            .CreateCustomAttribute("test", AttributeDestinations.All)
                            .Build(filter);

            var attribVals = new AttributeValueCollection(AttributeValueCollection.AllTargetModelTypes);

            attribDef.TrySetValue(attribVals, attributeValue);

            var actualAttribVal = attribVals.GetAttributeValues(AttributeClassification.UserAttributes)
                                  .FirstOrDefault(x => x.AttributeDefinition == attribDef);


            NrAssert.Multiple(
                () => Assert.IsNotNull(actualAttribVal),
                () => Assert.AreEqual(expectedResult, actualAttribVal.Value)
                );
        }
Beispiel #3
0
        public void Attributes_key_size()
        {
            var filter     = new AttributeFilter(new AttributeFilter.Settings());
            var attribVals = new AttributeValueCollection(AttributeValueCollection.AllTargetModelTypes);

            var testKeys = new string[]
            {
                new string('x', 255),
                new string('a', 256),
                string.Empty,
                " ",
                null as string
            };

            var testResults = new bool[testKeys.Length];


            for (var i = 0; i < testKeys.Length; i++)
            {
                var attribDef = AttributeDefinitionBuilder
                                .CreateCustomAttribute(testKeys[i], AttributeDestinations.All)
                                .Build(filter);

                testResults[i] = attribDef.IsDefinitionValid;

                attribDef.TrySetValue(attribVals, 9);
            }



            NrAssert.Multiple(
                () => Assert.IsTrue(testResults[0]),
                () => Assert.IsFalse(testResults[1]),
                () => Assert.IsFalse(testResults[2]),
                () => Assert.IsFalse(testResults[3]),
                () => Assert.IsFalse(testResults[4]),
                () => Assert.AreEqual(1, attribVals.GetAttributeValues(AttributeClassification.UserAttributes).Count())
                );
        }