Esempio n. 1
0
        /// <summary>
        /// Cleans up after test item execution.
        /// </summary>
        public override void Terminate()
        {
            this.method             = null;
            this.variationAttribute = null;

            base.Terminate();
        }
Esempio n. 2
0
                public void AddChild(TestFunc myFunction, int priority, string description, params object[] paramList)
                {
                    TestVariation      myVariation = new TestVariation(myFunction);
                    VariationAttribute myAttribute = new VariationAttribute(description, paramList);

                    myAttribute.Priority  = priority;
                    myVariation.Attribute = myAttribute;
                    this.AddChild(myVariation);
                }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the VariationTestItem class for given <see cref="MethodInfo"/> and <see cref="VariationAttribute"/>.
        /// </summary>
        /// <param name="parentTestCase">The parent test case.</param>
        /// <param name="methodInfo">Method info</param>
        /// <param name="variationAttribute"><see cref="VariationAttribute"/> that describes variation metadata.</param>
        public VariationTestItem(TestItem parentTestCase, MethodInfo methodInfo, VariationAttribute variationAttribute)
            : this(parentTestCase, methodInfo)
        {
            ExceptionUtilities.CheckArgumentNotNull(variationAttribute, "variationAttribute");

            this.variationAttribute = variationAttribute;

            ReadMetadataFromAttribute(variationAttribute);

            this.Timeout = variationAttribute.Timeout;
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the VariationTestItem class for given <see cref="MethodInfo"/> and <see cref="VariationAttribute"/>.
        /// </summary>
        /// <param name="parentTestCase">The parent test case.</param>
        /// <param name="methodInfo">Method info</param>
        /// <param name="variationAttribute"><see cref="VariationAttribute"/> that describes variation metadata.</param>
        public VariationTestItem(TestItem parentTestCase, MethodInfo methodInfo, VariationAttribute variationAttribute)
            : this(parentTestCase, methodInfo)
        {
            ExceptionUtilities.CheckArgumentNotNull(variationAttribute, "variationAttribute");

            this.variationAttribute = variationAttribute;

            ReadMetadataFromAttribute(variationAttribute);

            this.Timeout = variationAttribute.Timeout;
        }
Esempio n. 5
0
        private VariationAttribute DwDesignVariationAttribute()
        {
            var designVariations = new VariationAttribute();

            try
            {
                if (AvailableVariations != null)
                {
                    designVariations = AvailableVariations.Find(x => x.Id == "design" && x.Values.Any());
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("Product.DWDesignVariationAttribute", ErrorSeverity.FollowUp, ErrorType.RequestError));
                return(designVariations);
            }
            return(designVariations);
        }
Esempio n. 6
0
        private VariationAttribute DWColorVariationAttribute()
        {
            var colorVariations = new VariationAttribute();

            try
            {
                if (AvailableVariations != null)
                {
                    colorVariations = AvailableVariations.Find(x => x.Id == "color" && x.Values.Any());
                }
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("Product.ColorImages", ErrorSeverity.FollowUp, ErrorType.RequestError));
                return(new VariationAttribute());
            }

            return(colorVariations);
        }
Esempio n. 7
0
        public TestVariation GenerateVariation(TestCase testcase, MethodInfo method, VariationAttribute testVarAttrib)
        {
            //do not generate variations for tests which have KeepInContent set to false and the version is not V2
            if (!this.KeepInContent && !Versioning.Server.SupportsV2Features)
            {
                return(null);
            }

            TestVariation ffTestVariation;
            MethodInfo    generateEpmMappingsMethod = testcase.GetType().GetMethod("GenerateEpmMappings");

            FilterResourcesLambda = GenerateLambda();

            TestFunc testMethodAction = delegate()
            {
                bool thisTestFailed = true;

                SkipInvalidRuns();

                try
                {
                    generateEpmMappingsMethod.Invoke(testcase, new object[] {
                        KeepInContent,             //bool pKeepInContent,
                        RemoveUnEligibleTypes,     //bool pRemoveUnEligibleTypes,
                        GenerateClientTypes,       //bool pGenerateClientTypes,
                        MapToAtomElements,         //bool pMapPropertiesToAtomElements,
                        MapToNonAtomElements,      //bool pMapPropertiesToNonAtomElements,
                        GenerateServerEPMMappings, //bool GenerateServerEPMMappings,
                        KeepSameNamespace,         //bool KeepSameNamespace,
                        IncludeComplexTypes,       //bool  IncludeComplexTypes
                        PreDefinedPaths,           //string[] PreDefinedPaths
                        FilterResourcesLambda      //Func<ResourceType, bool> pFilterResourcesLambda
                    });
                    method.Invoke(testcase, null);


                    thisTestFailed = AstoriaTestLog.FailureFound;
                }
                catch (Microsoft.OData.Client.DataServiceClientException dsException)
                {
                    if (dsException.InnerException != null)
                    {
                        AstoriaTestLog.WriteLine(dsException.InnerException.Message);
                    }
                }
                catch (TestFailedException testException)
                {
                    AstoriaTestLog.WriteLine("Test failed  with :{0}", testException.Message);
                    AstoriaTestLog.WriteLine("Repro Details\r\nClient Code");
                }
                finally
                {
                    //Disabling this as OOM errors prevent file copying
                    thisTestFailed = false;
                    #region //Clean out all the facets after the test , so that the next test is clear
                    object       workspacePointer       = null;
                    PropertyInfo testWorkspacesProperty = testcase.Parent.GetType().GetProperty("Workspaces");
                    workspacePointer = testcase.Parent;
                    if (testWorkspacesProperty == null)
                    {
                        testWorkspacesProperty = testcase.GetType().GetProperty("Workspaces");
                        workspacePointer       = testcase;
                    }
                    Workspaces testWorkspaces = (Workspaces)testWorkspacesProperty.GetValue(workspacePointer, null);
                    foreach (Workspace workspace in testWorkspaces)
                    {
                        if (thisTestFailed)
                        {
                            string testFailureReproPath = String.Format("FF_Failure_{0}", System.Guid.NewGuid().ToString());
                            testFailureReproPath = System.IO.Path.Combine(Environment.CurrentDirectory, testFailureReproPath);
                            IOUtil.CopyFolder(workspace.DataService.DestinationFolder, testFailureReproPath, true);
                            AstoriaTestLog.WriteLine("Test failed , Repro available at : {0} ", testFailureReproPath);
                        }

                        if (!(workspace is EdmWorkspace))
                        {
                            workspace.GenerateClientTypes    = true;
                            workspace.GenerateServerMappings = false;
                            workspace.ApplyFriendlyFeeds();
                        }
                    }
                    #endregion
                }
            };

            ffTestVariation = new TestVariation(testMethodAction);
            if (testVarAttrib != null)
            {
                ffTestVariation.Params = testVarAttrib.Params;
                ffTestVariation.Param  = testVarAttrib.Param;
                ffTestVariation.Desc   = String.Format(
                    "{3} , {0},{1},{2},{4}{5}{6}{7}",
                    GenerateClientTypes ? "Client Mapped" : "",
                    GenerateServerEPMMappings ? "Server Mapped" : "",
                    MapToAtomElements ? "Mapped to Atom" : "Mapped to Non-Atom Elements",
                    testVarAttrib.Desc, InheritanceFilter.ToString(),
                    KeepSameNamespace ? "Same Namespace" : "Different NameSpaces",
                    PreDefinedPaths != null ? ",PredefinedPaths" : "", KeepInContent.ToString());
                if (AstoriaTestProperties.MaxPriority == 0)
                {
                    ffTestVariation.Id = 1;
                }
                else
                {
                    ffTestVariation.Id = idCounter++;
                }
                ffTestVariation.Priority = this.Priority;
            }
            return(ffTestVariation);
        }
Esempio n. 8
0
        private VariationTestItem InvokeMatrixCombinationCallback(MethodInfo method, VariationTestItem variation, VariationAttribute attribute)
        {
            var callbackAttr = (TestMatrixCombinationCallbackAttribute)method.GetCustomAttributes(typeof(TestMatrixCombinationCallbackAttribute), false).SingleOrDefault();

            if (callbackAttr != null)
            {
                var callbackMethod = this.GetType().GetMethod(callbackAttr.CallbackMethodName, true, false);
                ExceptionUtilities.CheckObjectNotNull(callbackMethod, "Could not find instance method '{0}' on type '{1}'", callbackAttr.CallbackMethodName, this.GetType());
                ExceptionUtilities.Assert(typeof(VariationTestItem).IsAssignableFrom(callbackMethod.ReturnType), "Matrix combination callback '{0}' returns unexpected type '{1}'", callbackMethod.Name, callbackMethod.ReturnType);

                var arguments = new object[attribute.Parameters.Length + 1];
                arguments[0] = variation;
                Array.Copy(attribute.Parameters, 0, arguments, 1, attribute.Parameters.Length);

                variation = (VariationTestItem)callbackMethod.Invoke(this, arguments);
            }

            return(variation);
        }
Esempio n. 9
0
        /// <summary>
        /// Cleans up after test item execution.
        /// </summary>
        public override void Terminate()
        {
            this.method = null;
            this.variationAttribute = null;

            base.Terminate();
        }
Esempio n. 10
0
        public ProductListExtensionResponse(ProductResult productResult, List <string> colors, string htmlRaw = "") : this()
        {
            colors.Reverse();
            foreach (var product in productResult.Products)
            {
                var productId = product.Id;
                if (!ProductIdToExtension.ContainsKey(productId))
                {
                    var extension = new ProductListItemExtension();

                    var availableVariations = product.VariationAttributes;
                    availableVariations.RemoveAll(a => a.Values == null);

                    List <VariationAttribute> outVA = new List <VariationAttribute>();
                    foreach (VariationAttribute va in availableVariations)
                    {
                        VariationAttribute attr = new VariationAttribute();

                        attr.Id   = va.Id;
                        attr.Name = va.Name;
                        foreach (VariationAttributeValue innerVa in va.Values.ToList())
                        {
                            if (va.Id == "color")
                            {
                                attr.Values.Add(new VariationAttributeValue()
                                {
                                    Image       = GetImagesForColor(product, innerVa.Value),
                                    Swatch      = GetSwatchImage(product, innerVa.Value),
                                    Name        = innerVa.Name,
                                    Value       = innerVa.Value.ToLower(),
                                    IsOrderable = innerVa.IsOrderable
                                });
                            }
                        }
                        outVA.Add(attr);
                    }

                    var colorVariations       = availableVariations.Where(a => a.Id == "color").FirstOrDefault() ?? new VariationAttribute();
                    var applicableImageGroups = product.ImageGroups.Where(z => colorVariations.Values.Any(x => z.VariationAttributes.Select(e => e.values.Where(v => v.value.Contains(x.Value)).FirstOrDefault()).Any()));



                    DWImage image       = null;
                    var     colorImages = applicableImageGroups.Where(z => z.ViewType == "hi-res" &&
                                                                      colors.Find(x => z.VariationAttributes.Select(e => e.values.Where(v => v.value.Contains(x)).FirstOrDefault()).Any()) != null &&
                                                                      z.Images.Any())
                                          .Select(z => z.Images)
                                          .FirstOrDefault();

                    if (colorImages != null)
                    {
                        image = colorImages.FirstOrDefault();
                    }
                    else
                    {
                        var genericImages = (applicableImageGroups.Count() > 0 ? applicableImageGroups : product.ImageGroups).Where(z => z.ViewType == "hi-res")
                                            .Select(z => z.Images)
                                            .FirstOrDefault();

                        if (genericImages != null)
                        {
                            image = genericImages.FirstOrDefault();
                        }
                    }

                    if (image != null)
                    {
                        extension.Image.Src   = APIHelper.GetOptimizedImageSrc(image.Link);
                        extension.Image.Title = image.Title;
                    }
                    extension.Brand  = product.Brand;
                    extension.Rating = product.AverageRating;
                    extension.IsAvailableInMultipleColors = colorVariations.Values.Count > 1;
                    extension.AvailableVariations         = outVA;
                    extension.ProductFlags = product.ProductFlags;
                    ProductIdToExtension.Add(productId, extension);
                    extension.Callout = product.Promotions.Where(promo => promo.Callout != null).Select(a => a.Callout).ToList();
                }
                SetProductBrands(productResult.Products, htmlRaw);
            }
        }
Esempio n. 11
0
        private void SetSelectedColorValue(string color, VariationAttribute colorVariations,
                                           List <ImageGroup> swatchImages, List <ImageGroup> imageGroups,
                                           List <Variant> variants, bool isOneSizeOnly, bool isGiftCard)
        {
            try
            {
                if (colorVariations == null)
                {
                    return;
                }
                Colors = colorVariations.Values
                         .Select(colorVariation =>
                {
                    var swatch = swatchImages.Where(z => z.VariationAttributes.Select(e => e.values.Where(v => v.value.Equals(colorVariation.Value)).Any()).FirstOrDefault())
                                 .Select(z => z.Images.FirstOrDefault()).FirstOrDefault() ?? new DWImage();

                    var images      = new List <ProductImage>();
                    var colorImages = ColorImages(imageGroups, colorVariation);
                    if (colorImages != null)
                    {
                        images = colorImages.Select(z => new ProductImage
                        {
                            Src      = APIHelper.GetOptimizedImageSrc(z.Link, 200) ?? string.Empty,
                            SrcMed   = APIHelper.GetOptimizedImageSrc(z.Link, 450) ?? string.Empty,
                            SrcLarge = APIHelper.GetOptimizedImageSrc(z.Link, 1400) ?? string.Empty,
                            Title    = z.Title ?? string.Empty
                        }).ToList();
                    }

                    var sizes = DwSizeOptions(variants, colorVariation, isOneSizeOnly, isGiftCard);

                    string lot = null;
                    if (!sizes.Any())
                    {
                        return new ColorOption
                        {
                            Name   = colorVariation.Name,
                            Value  = colorVariation.Value,
                            Lot    = lot,
                            Swatch = new Image {
                                Src = swatch.Link, Title = swatch.Title
                            },
                            Sizes  = sizes,
                            Images = images
                        }
                    }
                    ;

                    var sku       = sizes.First().Value;
                    var skuLength = sku.Length;
                    lot           = skuLength > 7 ? sku.Substring(0, skuLength - 3) : sku.ToString();

                    return(new ColorOption
                    {
                        Name = colorVariation.Name,
                        Value = colorVariation.Value,
                        Lot = lot,
                        Swatch = new Image {
                            Src = swatch.Link, Title = swatch.Title
                        },
                        Sizes = sizes,
                        Images = images
                    });
                }).ToList();

                SetSelectedColor(color);
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("Product.SetSelectedColorValue", ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
        }
Esempio n. 12
0
        private void DWGetDesignValues(VariationAttribute designVariations, List <ImageGroup> imageGroups,
                                       List <Variant> variants)
        {
            try
            {
                Designs = designVariations.Values
                          .Select(x =>
                {
                    List <Image> images;
                    var designImages = DwDesignImages(imageGroups, x);
                    if (designImages != null)
                    {
                        images = designImages.Select(z => new Image
                        {
                            Src   = APIHelper.GetOptimizedImageSrc(z.Link),
                            Title = z.Title
                        })
                                 .ToList();
                    }
                    else
                    {
                        images = new List <Image> {
                            new Image {
                                Src = Config.Urls.DefaultGiftCardImage
                            }
                        };
                    }

                    var values = variants.Where(z => z.VariationValues
                                                .Any(a => a.Value.Equals(x.Value)))
                                 .Select(z =>
                    {
                        int valueInt;
                        var valueStr = string.Empty;
                        if (z.VariationValues.ContainsKey("value"))
                        {
                            valueStr = z.VariationValues["value"];
                        }
                        int.TryParse(valueStr, out valueInt);

                        var name = string.Format("${0}", z.Price);

                        return(new ValueOption
                        {
                            Name = name,
                            Value = z.ProductId.ToString(),
                            IsInStock = z.IsOrderable
                        });
                    })
                                 .ToList();

                    if (!values.Any())
                    {
                        return new DesignOption
                        {
                            Lot    = null,
                            Name   = x.Name,
                            Value  = x.Value,
                            Values = values,
                            Images = images
                        }
                    }
                    ;
                    var sku       = values.First().Value;
                    var skuLength = sku.Length;
                    var lot       = skuLength > 7 ? sku.Substring(0, skuLength - 3) : sku.ToString();

                    return(new DesignOption
                    {
                        Lot = lot,
                        Name = x.Name,
                        Value = x.Value,
                        Values = values,
                        Images = images
                    });
                }).ToList();
            }
            catch (Exception ex)
            {
                _errors.Add(ex.Handle("Product.DWGetDesignValues", ErrorSeverity.FollowUp, ErrorType.RequestError));
            }
        }