Exemple #1
0
 private static void SetOnTypeAttributes(ServiceMatcher matcher, IList <AttributePack> onType)
 {
     foreach (var attribute in onType)
     {
         matcher.SetAttributeOnType(attribute.AttributeType, attribute.CtorParamsMapping,
                                    attribute.PropsValuesMapping);
     }
 }
        public void Specified_Interface_Must_Be_Attributed_Correctly()
        {
            var interfaceType = typeof(ISimpleInterface);
            var attributeType = typeof(SomeAttribute);

            var ctorParams = new Dictionary <Type, object> {
                { typeof(string), "attributeName" }
            };
            var props = new Dictionary <string, object> {
                { "Index", 879 }
            };

            var matcher = new ServiceMatcher(interfaceType, TypeCategories.Class);

            matcher.SetAttributeOnType(attributeType, ctorParams, props);

            var servicePack = matcher.Pack();

            AssertOnHavingAttribute(servicePack.MatchType, attributeType, props);
        }
        public void Specified_Simple_Dto_Must_Be_Evaluated_With_Correct_Service_Pack()
        {
            var simpleDtoType = typeof(SimpleDto);
            var attributeType = typeof(SomeAttribute);

            var ctorParamsValuesMapping = new Dictionary <Type, object>
            {
                { typeof(string), "Hello" },
            };

            var propertiesValuesMapping = new Dictionary <string, object>
            {
                { nameof(SomeAttribute.Index), 5 },
            };

            var matcher = new ServiceMatcher(simpleDtoType, TypeCategories.Dto);

            matcher.SetAttributeOnType(
                attributeType,
                ctorParamsValuesMapping,
                propertiesValuesMapping);

            matcher.SetAttributeForAllMembers(
                attributeType,
                ctorParamsValuesMapping,
                propertiesValuesMapping);

            var simpleDtoServicePack = matcher.Pack();

            AssertMatchedPropertyHasProperProperties(simpleDtoType, simpleDtoServicePack.MatchType);

            AssertOnHavingAllRelatedTypes(simpleDtoServicePack, simpleDtoType);

            AssertOnHavingAttributeOnType(simpleDtoServicePack.MatchType, attributeType, propertiesValuesMapping);

            AssertOnHavingAttributeOnAllProperties(simpleDtoServicePack.MatchType, attributeType, propertiesValuesMapping);
        }