Exemplo n.º 1
0
        public async Task <ActionResult <BrandsResponse> > PostBrand([FromBody] PostBrandRequest model)
        {
            int role = Convert.ToInt32(User.FindFirst(ClaimTypes.Role)?.Value);
            var rs   = await _brandsService.PostBrand(model, role);

            return(Ok(rs));
        }
Exemplo n.º 2
0
        public async Task <HttpResponse <BrandResponse> > Create(PostBrandRequest request)
        {
            MethodUrl = "";
            string stringPayload = await Task.Run(() => JsonConvert.SerializeObject(request));

            var response = await Post(stringPayload);

            return(response);
        }
Exemplo n.º 3
0
        public async Task <BrandsResponse> PutBrand(int id, PostBrandRequest model)
        {
            var brand = _unitOfWork.Repository <Brand>().GetAll().Where(x => x.Id == id && x.Active == true).FirstOrDefault();

            if (brand != null)
            {
                try
                {
                    brand.Name      = model.Name;
                    brand.SegmentId = model.SegmentId;
                    if (String.IsNullOrEmpty(model.ImageUrl))
                    {
                        brand.ImageUrl = model.ImageUrl;
                    }

                    if (String.IsNullOrEmpty(model.IconUrl))
                    {
                        brand.IconUrl = model.IconUrl;
                    }

                    if (model.SegmentId > 0)
                    {
                        brand.SegmentId = model.SegmentId;
                    }

                    await _unitOfWork.Repository <Brand>().Update(brand, id);

                    await _unitOfWork.CommitAsync();

                    return(new BrandsResponse
                    {
                        Id = brand.Id,
                        Name = brand.Name,
                        IconUrl = brand.IconUrl,
                        ImageUrl = brand.ImageUrl,
                        Active = brand.Active,
                        SegmentId = brand.SegmentId,
                        SegmentName = brand.Segment?.Name
                    });
                }
                catch (Exception e)
                {
                    throw new CrudException(HttpStatusCode.BadRequest, "Update Brand Error!!!", e.InnerException?.Message);
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public async Task <BrandsResponse> PostBrand(PostBrandRequest model, int role)
        {
            Brand brand = new Brand
            {
                Name   = model.Name,
                Active = true,

                SegmentId = model.SegmentId
            };

            brand.ImageUrl  = model.ImageUrl ?? "";
            brand.IconUrl   = model.IconUrl ?? "";
            brand.SegmentId = model.SegmentId > 0 ? model.SegmentId : 0;
            try
            {
                await _unitOfWork.Repository <Brand>().InsertAsync(brand);

                await _unitOfWork.CommitAsync();

                brand = await _unitOfWork.Repository <Brand>().GetAll().Where(x => x.Id == brand.Id).Include(x => x.Segment).SingleOrDefaultAsync();

                return(new BrandsResponse
                {
                    Id = brand.Id,
                    Name = brand.Name,
                    IconUrl = brand.IconUrl,
                    ImageUrl = brand.ImageUrl,
                    Active = brand.Active,
                    SegmentId = brand.SegmentId,
                    SegmentName = brand.Segment?.Name
                });
            }
            catch (Exception e)
            {
                throw new CrudException(HttpStatusCode.BadRequest, "Insert Brand Error!!!", e.InnerException?.Message);
            }
        }
Exemplo n.º 5
0
        public async Task <ActionResult <BrandsResponse> > PutBrand(int id, [FromBody] PostBrandRequest model)
        {
            var rs = await _brandsService.PutBrand(id, model);

            return(Ok(rs));
        }
Exemplo n.º 6
0
        public override async Task TestScenarioSetUp(OfferingTestData testData)
        {
            //create catalog
            CatalogRequest catalogRequest = new CatalogRequest
            {
                Name               = "Seed catalog name",
                Identifier         = Guid.NewGuid(),
                CreatedBy          = "Seed helper",
                ExternalIdentifier = testData.CatalogExtId,
                PlatformIdentifier = new Guid(ServiceConstants.AllPointsPlatformId),
                CreatedUtc         = DateTime.UtcNow.ToString(),
                UpdatedUtc         = DateTime.UtcNow.ToString()
            };
            await Client.Catalogs.Create(catalogRequest);

            //create a category
            CategoryRequest categoryRequest = new CategoryRequest
            {
                CatalogId     = testData.CatalogExtId,
                Identifier    = testData.CategoryExtId,
                FullName      = "sample category name",
                IsLanding     = false,
                ShortName     = "sample name",
                IsTopMenu     = false,
                UrlSegment    = "sample-category-name/",
                CollapseOrder = 1,
                HtmlPage      = new HtmlPage
                {
                    H1    = "H1 sample thing",
                    Title = "Title sample thing",
                    Meta  = "Meta sample thing",
                    Url   = "any-thing/"
                },
                IsSubcatalog = false,
                IsMore       = false,
                CreatedBy    = "temporal test method"
            };
            await Client.Categories.Create(categoryRequest);

            //create a brand
            PostBrandRequest brandRequest = new PostBrandRequest
            {
                CreatedBy          = "temporal test method",
                CreatedUtc         = DateTime.Now.ToString(),
                UpdatedUtc         = DateTime.Now.ToString(),
                ExternalIdentifier = testData.BrandExtId,
                Identifier         = Guid.NewGuid(),
                PlatformIdentifier = new Guid(ServiceConstants.AllPointsPlatformId),
                FullName           = "test name",
                ShortName          = "test name short",
                HtmlPage           = new HtmlPage
                {
                    H1    = "test",
                    Meta  = "meta",
                    Title = "test title",
                    Url   = "test/"
                },
                Favorability = 2,
                UrlSegment   = "test/"
            };
            await Client.Brands.Create(brandRequest);

            //create a product
            ProductRequest productRequest = new ProductRequest
            {
                CreatedBy          = "temporal product request",
                Identifier         = testData.ProductExtId,
                Cost               = 11,
                DisplayProductCode = "temporal-sku",
                IsOcm              = false,
                IsPurchaseable     = true,
                Name               = "product test name",
                ProductCode        = "temporal-sku",
                Prop65Message      = new ProductProp65Message
                {
                    MessageBody = "This product has been created through a test automation tool"
                },
                SearchKeywords = "test,seed",
                Shipping       = new ProductShippingAttributes
                {
                    FreightClass      = 179,
                    IsFreeShip        = false,
                    IsFreightOnly     = false,
                    IsQuickShip       = false,
                    WeightActual      = 6.72m,
                    WeightDimensional = 20.62m,
                    Height            = 9.61m,
                    Width             = 16.48m,
                    Length            = 9.60m
                },
                Specs = new List <ProductSpecification>
                {
                    new ProductSpecification
                    {
                        Name  = "name of spec",
                        Value = "value of spec"
                    }
                },
                OemRelationships = new List <ProductOem>
                {
                    new ProductOem
                    {
                        OemName = "oem name 01",
                        Type    = 1,
                        OemSku  = "FakeOemSku"
                    }
                },
                ProductLeadType        = 1,
                BrandSku               = "fake",
                PrimaryBrandIdentifier = testData.BrandExtId
            };
            await Client.Products.Create(productRequest);

            //create a offering
            string          offeringFullName = "temporal frozen Sturkey";
            OfferingRequest offeringRequest  = new OfferingRequest
            {
                CreatedBy    = "temporal offering",
                Identifier   = testData.OfferingExtId,
                CatalogId    = testData.CatalogExtId,
                ProductId    = testData.ProductExtId,
                HomeCategory = testData.CategoryExtId,
                CategoryIds  = new List <string>(),
                Description  = "temporal Description for this offering",
                FullName     = offeringFullName,
                HtmlPage     = new HtmlPage
                {
                    H1    = $"H1 {offeringFullName}",
                    Title = $"Title {offeringFullName}",
                    Meta  = $"Meta {offeringFullName}",
                    Url   = $"{offeringFullName.Replace(" ", "-")}"
                },
                IsPublishAble = true,
                IsPreviewAble = true,
                Links         = new List <OfferingLink>(),
            };
            await Client.Offerings.Create(offeringRequest);
        }
Exemplo n.º 7
0
        public async Task POST_Offering_Success()
        {
            string offeringFullName   = "frozen turkey ready to deploy";
            string externalIdentifier = "postOfferingExternal01";

            OfferingTestData testData = new OfferingTestData
            {
                OfferingExtId = externalIdentifier,
                CategoryExtId = "offeringCategoryExternal01",
                CatalogExtId  = "offeringCatalogExternal01",
                ProductExtId  = "offeringProductExternal01",
                BrandExtId    = "offeringBrandExternal01"
            };

            //create catalog
            CatalogRequest catalogRequest = new CatalogRequest
            {
                Name               = "Seed catalog name",
                Identifier         = Guid.NewGuid(),
                CreatedBy          = "Seed helper",
                ExternalIdentifier = testData.CatalogExtId,
                PlatformIdentifier = new Guid(ServiceConstants.AllPointsPlatformId),
                CreatedUtc         = DateTime.UtcNow.ToString(),
                UpdatedUtc         = DateTime.UtcNow.ToString()
            };
            await Client.Catalogs.Create(catalogRequest);

            //create a category
            CategoryRequest categoryRequest = new CategoryRequest
            {
                CatalogId     = testData.CatalogExtId,
                Identifier    = testData.CategoryExtId,
                FullName      = "sample category name",
                IsLanding     = false,
                ShortName     = "sample name",
                IsTopMenu     = false,
                UrlSegment    = "sample-category-name/",
                CollapseOrder = 1,
                HtmlPage      = new HtmlPage
                {
                    H1    = "H1 sample thing",
                    Title = "Title sample thing",
                    Meta  = "Meta sample thing",
                    Url   = "any-thing/"
                },
                IsSubcatalog = false,
                IsMore       = false,
                CreatedBy    = "temporal test method"
            };
            await Client.Categories.Create(categoryRequest);

            //create a brand
            PostBrandRequest brandRequest = new PostBrandRequest
            {
                CreatedBy          = "temporal test method",
                CreatedUtc         = DateTime.Now.ToString(),
                UpdatedUtc         = DateTime.Now.ToString(),
                ExternalIdentifier = testData.BrandExtId,
                Identifier         = Guid.NewGuid(),
                PlatformIdentifier = new Guid(ServiceConstants.AllPointsPlatformId),
                FullName           = "test name",
                ShortName          = "test name short",
                HtmlPage           = new HtmlPage
                {
                    H1    = "test",
                    Meta  = "meta",
                    Title = "test title",
                    Url   = "test/"
                },
                Favorability = 2,
                UrlSegment   = "test/"
            };
            await Client.Brands.Create(brandRequest);

            //create a product
            ProductRequest productRequest = new ProductRequest
            {
                CreatedBy          = "temporal product request",
                Identifier         = testData.ProductExtId,
                Cost               = 11,
                DisplayProductCode = "temporal-sku",
                IsOcm              = false,
                IsPurchaseable     = true,
                Name               = "product test name",
                ProductCode        = "temporal-sku",
                Prop65Message      = new ProductProp65Message
                {
                    MessageBody = "This product has been created through a test automation tool"
                },
                SearchKeywords = "test,seed",
                Shipping       = new ProductShippingAttributes
                {
                    FreightClass      = 179,
                    IsFreeShip        = false,
                    IsFreightOnly     = false,
                    IsQuickShip       = false,
                    WeightActual      = 6.72m,
                    WeightDimensional = 20.62m,
                    Height            = 9.61m,
                    Width             = 16.48m,
                    Length            = 9.60m
                },
                Specs = new List <ProductSpecification>
                {
                    new ProductSpecification
                    {
                        Name  = "name of spec",
                        Value = "value of spec"
                    }
                },
                OemRelationships = new List <ProductOem>
                {
                    new ProductOem
                    {
                        OemName = "oem name 01",
                        Type    = 1,
                        OemSku  = "FakeOemSku"
                    }
                },
                ProductLeadType        = 1,
                BrandSku               = "fake",
                PrimaryBrandIdentifier = testData.BrandExtId
            };
            await Client.Products.Create(productRequest);

            OfferingRequest request = new OfferingRequest
            {
                Identifier   = externalIdentifier,
                CatalogId    = testData.CatalogExtId,
                ProductId    = testData.ProductExtId,
                HomeCategory = testData.CategoryExtId,
                CategoryIds  = new List <string>(),
                Description  = "Description for this offering p:",
                FullName     = offeringFullName,
                HtmlPage     = new HtmlPage
                {
                    H1    = $"H1 {offeringFullName}",
                    Title = $"Title {offeringFullName}",
                    Meta  = $"Meta {offeringFullName}",
                    Url   = $"{offeringFullName.Replace(" ", "-")}"
                },
                IsPublishAble = true,
                IsPreviewAble = true,
                Links         = new List <OfferingLink>(),
                CreatedBy     = "post offering request"
            };

            HttpResponseExtended <OfferingResponse> response = await Client.Offerings.Create(request);

            Assert.IsNotNull(response, $"{nameof(response)} cannot be null");
            Assert.AreEqual(200, response.StatusCode);
            Assert.IsTrue(response.Success, $"Response status is not successful");
            Assert.IsNotNull(response.Result, $"{nameof(response.Result)} is null");

            //test scenario clean up
            await TestScenarioCleanUp(testData);
        }
Exemplo n.º 8
0
        public override async Task TestScenarioSetUp(ProductTestData testData)
        {
            PostBrandRequest brandRequest = new PostBrandRequest
            {
                ExternalIdentifier = testData.BrandExtId,
                CreatedBy          = "temporal test",
                CreatedUtc         = DateTime.UtcNow.ToString(),
                Favorability       = 1,
                FullName           = "sample full name",
                Identifier         = Guid.NewGuid(),
                PlatformIdentifier = new Guid(ServiceConstants.AllPointsPlatformId),
                ShortName          = "sample short name",
                UrlSegment         = "sample-brand/",
                HtmlPage           = new HtmlPage
                {
                    H1    = "H1 temporal heading",
                    Meta  = "Meta temporal ",
                    Title = "Title temporal",
                    Url   = "sample-url/"
                },
                UpdatedUtc = DateTime.UtcNow.ToString()
            };
            ProductRequest productRequest = new ProductRequest
            {
                PrimaryBrandIdentifier = testData.BrandExtId,
                BrandSku           = "fake",
                Cost               = 100,
                CreatedBy          = "sample test helper",
                DisplayProductCode = "makukkos",
                Identifier         = testData.ExternalIdentifier,
                ProductCode        = "makukkos",
                Name               = "product fake",
                IsOcm              = false,
                IsPurchaseable     = false,
                ProductLeadType    = 2,
                SearchKeywords     = "makukkos",
                Specs              = new List <ProductSpecification>
                {
                    new ProductSpecification
                    {
                        Name  = "spec name",
                        Value = "spec value"
                    }
                },
                Shipping = new ProductShippingAttributes
                {
                    FreightClass      = 12,
                    Width             = 120,
                    Length            = 12,
                    Height            = 120,
                    IsFreeShip        = true,
                    IsFreightOnly     = false,
                    IsQuickShip       = true,
                    WeightActual      = 125,
                    WeightDimensional = 300
                }
            };

            await Client.Brands.Create(brandRequest);

            await Client.Products.Create(productRequest);
        }
Exemplo n.º 9
0
        public async Task POST_Product_Success()
        {
            string externalIdentifier = "postProductExternalId01";

            //test scenario setup
            ProductTestData testData = new ProductTestData
            {
                ExternalIdentifier = externalIdentifier,
                BrandExtId         = "postProductBrandExternalId01"
            };

            //create brand
            PostBrandRequest brandRequest = new PostBrandRequest
            {
                CreatedBy          = "temporal request",
                CreatedUtc         = DateTime.UtcNow.ToString(),
                UpdatedUtc         = DateTime.UtcNow.ToString(),
                UrlSegment         = "temporal/",
                FullName           = "temporal brand",
                ExternalIdentifier = testData.BrandExtId,
                Favorability       = 1,
                HtmlPage           = new HtmlPage
                {
                    H1    = "H1 temporal heading",
                    Meta  = "Meta temporal",
                    Title = "Title temporal",
                    Url   = "test-brand/"
                },
                Identifier         = Guid.NewGuid(),
                PlatformIdentifier = new Guid(ServiceConstants.AllPointsPlatformId),
                ShortName          = "temporal brand"
            };
            await Client.Brands.Create(brandRequest);

            ProductRequest request = new ProductRequest
            {
                CreatedBy          = "postRequest success",
                Identifier         = externalIdentifier,
                Cost               = 11,
                DisplayProductCode = "postsku01",
                IsOcm              = false,
                IsPurchaseable     = true,
                Name               = "product test name",
                ProductCode        = "postsku01",
                Prop65Message      = new ProductProp65Message
                {
                    MessageBody = "This product has been created through a test automation tool"
                },
                SearchKeywords = "test,seed",
                Shipping       = new ProductShippingAttributes
                {
                    FreightClass      = 179,
                    IsFreeShip        = false,
                    IsFreightOnly     = false,
                    IsQuickShip       = false,
                    WeightActual      = 6.72m,
                    WeightDimensional = 20.62m,
                    Height            = 9.61m,
                    Width             = 16.48m,
                    Length            = 9.60m
                },
                Specs = new List <ProductSpecification>
                {
                    new ProductSpecification
                    {
                        Name  = "name of spec",
                        Value = "value of spec"
                    }
                },
                OemRelationships = new List <ProductOem>
                {
                    new ProductOem
                    {
                        OemName = "oem name 01",
                        Type    = 1,
                        OemSku  = "FakeOemSku"
                    }
                },
                ProductLeadType        = 1,
                BrandSku               = "fake",
                PrimaryBrandIdentifier = testData.BrandExtId
            };
            HttpResponseExtended <ProductResponse> response = await Client.Products.Create(request);

            Assert.IsNotNull(response, $"{nameof(response)} is null");
            Assert.AreEqual(200, response.StatusCode);
            Assert.IsTrue(response.Success, $"Status code is {response.StatusCode}");

            //post specific validations
            Assert.AreEqual(request.Identifier, response.Result.ExternalIdentifier);
            Assert.AreEqual(request.CreatedBy, response.Result.CreatedBy);

            //test scenario clean up
            await TestScenarioCleanUp(testData);
        }