Example #1
0
 protected VersionId InitVersionId(int id, byte[] timestamp)
 {
     VersionId vid = new VersionId();
     vid.Id = id;
     vid.Timestamp = timestamp;
     return vid;
 }
Example #2
0
        public void RunProductTests()
        {
            int i = 0;
            ArrayList delProducts = new ArrayList();
            foreach(string category in new string[]{"CatA", "CatB", "CatC", "DeleteCat"})
            {
                Product[] products = m_service.GetProductsByCategory(category);
                if(products != null)
                    delProducts.AddRange(products);
            }
            ChangeProducts deletes = new ChangeProducts();
            deletes.DeleteProducts = new VersionId[delProducts.Count];
            foreach(Product p in delProducts)
            {
                VersionId versionId = new VersionId();
                versionId.Id = p.Id;
                versionId.Timestamp = p.Timestamp;
                deletes.DeleteProducts[i++] = versionId;
            }
            m_service.ChangeProducts(deletes);

            ChangeProducts changeProducts = new ChangeProducts();
            i = -1;
            changeProducts.InsertProducts = InitProducts(
                InitProduct(i--, "ProdA_A", 10, 10.0, "CatA", null),
                InitProduct(i--, "ProdB_A", 10, 10.0, "CatA", null),
                InitProduct(i--, "ProdC_A", 10, 10.0, "CatA", null),
                InitProduct(i--, "ProdD_A", 10, 10.0, "CatA", null),
                InitProduct(i--, "ProdA_B", 10, 10.0, "CatB", null),
                InitProduct(i--, "ProdB_B", 10, 10.0, "CatB", null),
                InitProduct(i--, "ProdC_B", 10, 10.0, "CatB", null),
                InitProduct(i--, "ProdD_B", 10, 10.0, "CatB", null),
                InitProduct(i--, "ProdA_C", 10, 10.0, "CatC", null),
                InitProduct(i--, "ProdB_C", 10, 10.0, "CatC", null),
                InitProduct(i--, "ProdC_C", 10, 10.0, "CatC", null),
                InitProduct(i--, "ProdD_C", 10, 10.0, "CatC", null),
                InitProduct(i--, "ToDelete1", 10, 10.0, "DeleteCat", null),
                InitProduct(i--, "ToDelete2", 10, 10.0, "DeleteCat", null),
                InitProduct(i--, "ToDelete3", 10, 10.0, "DeleteCat", null),
                InitProduct(i--, "ToDelete4", 10, 10.0, "DeleteCat", null));
            IdentResult[] results = m_service.ChangeProducts(changeProducts);

            ChangeProducts changeTwo = new ChangeProducts();
            changeTwo.DeleteProducts = new VersionId[4];
            changeTwo.UpdateProducts = new Product[12];
            i = 0;
            foreach(IdentResult result in results)
            {
                Product p = changeProducts.InsertProducts[i];
                Debug.Assert(p.Id == result.InputId);

                if(p.Category.Equals("DeleteCat"))
                {
                    VersionId versionId = new VersionId();
                    versionId.Id = result.ResultId;
                    versionId.Timestamp = result.Timestamp;
                    changeTwo.DeleteProducts[i++ - 12] = versionId;
                }
                else
                {
                    changeTwo.UpdateProducts[i++] =
                        InitProduct(result.ResultId, p.Name + "_d", p.QuantityPerUnit * 3, p.UnitPrice * 2, p.Category + "_d", result.Timestamp);
                }
            }
            m_service.ChangeProducts(changeTwo);
        }