/// <summary>
        /// Checks the Pre/Post Entity Images to determine if the image collections contains an image with the given given key, that contains the attributes
        /// </summary>
        /// <param name="imageName"></param>
        /// <param name="attributeNames"></param>
        public void AssertEntityImageAttributesRegistered(string imageName, params string[] attributeNames)
        {
            Entity image;
            var    imageCollection = InvalidPluginStepRegistrationException.ImageCollection.Pre;

            if (PluginExecutionContext.PostEntityImages.TryGetValue(imageName, out image))
            {
                imageCollection = InvalidPluginStepRegistrationException.ImageCollection.Post;
            }
            else
            {
                PluginExecutionContext.PreEntityImages.TryGetValue(imageName, out image);
            }

            if (image == null)
            {
                throw InvalidPluginStepRegistrationException.ImageMissing(imageName);
            }

            var missingAttributes = attributeNames.Where(attribute => !image.Contains(attribute)).ToList();

            if (!missingAttributes.Any())
            {
                return;
            }

            throw InvalidPluginStepRegistrationException.ImageMissingRequiredAttributes(imageCollection, imageName, missingAttributes);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks the Pre/Post Entity Images to determine if the image collections contains an image with the given key, that contains the attributes.
        /// Throws an exception if the image name is contained in both the Pre and Post Image.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="imageName">Name of the image.</param>
        /// <param name="attributeNames">The attribute names.</param>
        public static void AssertEntityImageAttributesExist(this IPluginExecutionContext context, string imageName, params string[] attributeNames)
        {
            AssertEntityImageRegistered(context, imageName);
            var imageCollection = context.PreEntityImages.TryGetValue(imageName, out Entity preImage) ?
                                  InvalidPluginStepRegistrationException.ImageCollection.Pre :
                                  InvalidPluginStepRegistrationException.ImageCollection.Post;

            context.PostEntityImages.TryGetValue(imageName, out Entity postImage);

            var image             = preImage ?? postImage;
            var missingAttributes = attributeNames.Where(attribute => !image.Contains(attribute)).ToList();

            if (missingAttributes.Any())
            {
                throw InvalidPluginStepRegistrationException.ImageMissingRequiredAttributes(imageCollection, imageName, missingAttributes);
            }
        }