Exemple #1
0
 private static void SetForAllmembersAttributes(ServiceMatcher matcher, IList <AttributePack> forAllmembers)
 {
     foreach (var attribute in forAllmembers)
     {
         matcher.SetAttributeForAllMembers(attribute.AttributeType, attribute.CtorParamsMapping,
                                           attribute.PropsValuesMapping);
     }
 }
        public void Specified_Interface_Must_Be_Attributed_Correctly_For_All_Methods()
        {
            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.SetAttributeForAllMembers(attributeType, ctorParams, props);

            var servicePack = matcher.Pack();

            AssertOnHavingAttributeOnAllMethods(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);
        }