public async Task TestCollectionsApiDeleteAsync()
        {
            // Find out how many collections there are

            // Arrange
            int actualCollectionCount = 0;

            // Act
            IHttpActionResult collectionResult = controller.Get();
            var message = await collectionResult.ExecuteAsync(new System.Threading.CancellationToken());

            var collections = await message.Content.ReadAsAsync <IEnumerable <Collection> >();

            foreach (var u in collections)
            {
                actualCollectionCount++;
            }

            ///////////////////////////////////////////////////////////////

            // Arrange
            Guid wrongGuid   = new Guid("11111111-4444-4444-4444-aaaaaaaaaaaa");
            Guid recipesGuid = new Guid("bbbbbbbb-4444-4444-4444-222222222222");

            // Act
            collectionResult = controller.Delete(wrongGuid);
            message          = await collectionResult.ExecuteAsync(new System.Threading.CancellationToken());

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, message.StatusCode);

            // Act
            collectionResult = controller.Delete(recipesGuid);
            message          = await collectionResult.ExecuteAsync(new System.Threading.CancellationToken());

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, message.StatusCode);

            ///////////////////////////////////////////////////////////////

            // Check that there is one less collection

            // Arrange
            int expectedCollectionCount = actualCollectionCount - 1;

            actualCollectionCount = 0;

            // Act
            collectionResult = controller.Get();
            message          = await collectionResult.ExecuteAsync(new System.Threading.CancellationToken());

            collections = await message.Content.ReadAsAsync <IEnumerable <Collection> >();

            foreach (var u in collections)
            {
                actualCollectionCount++;
            }

            Assert.AreEqual(expectedCollectionCount, actualCollectionCount);
        }
Пример #2
0
 private void ItemDelete_Click(object sender, EventArgs e)
 {
     if (selectedItem != null)
     {
         if (controller.Delete(selectedItem))
         {
             Common.Functions.ShowMessgeInfo("Delete Success");
             Btn_Search_Click(null, null);
             selectedItem = null;
         }
         else
         {
             Common.Functions.ShowMessgeInfo("Delete Fail");
         }
     }
 }
        private void btn_apply_Click(object sender, EventArgs e)
        {
            if (tb_name.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"name\"");
                return;
            }
            if (tb_title.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"title\"");
                return;
            }
            if (rtb_description.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"description\"");
                return;
            }
            if (rtb_content.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"content\"");
                return;
            }
            if (FeatureImage.Equals(null))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"Feature Image\"");
                return;
            }
            if (chlb_catogary.CheckedItems.Count == 0)
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"catogary\"");
                return;
            }

            string CollectionLink = string.Empty;

            if (Obj == null)
            {
                CollectionLink = CheckExistCollectionLink(Common.Functions.getWebNameValid(tb_name.Text));
                if (CollectionLink.Equals(string.Empty))
                {
                    Common.Functions.ShowMessgeError("Không có kết nối đến máy chủ");
                    return;
                }
            }
            else
            {
                CollectionLink = Obj.name;
            }



            var lstImage = pn_imageattach.GetImageAttachList();
            var DeletedImageAttachList = pn_imageattach.DeletedImageAttachList;

            Web_Collections_Model obj = new Web_Collections_Model()
            {
                id           = (Obj == null) ? -1 : Obj.id,
                name         = CollectionLink,
                title        = tb_title.Text,
                content      = rtb_content.Text,
                featureimage = FeatureImage.Link,
                description  = rtb_description.Text,
                relatedmenu  = (int)(chlb_catogary.CheckedItems[0] as Web_Menu_Model).id,
                isdraft      = (Obj == null) ? true: Obj.isdraft
            };

            long id = -1;

            if (controller.Save(obj, ref id))
            {
                obj.id = id;
                if (SendImage(ref obj, ref lstImage, ref DeletedImageAttachList))
                {
                    controller.Update(obj);
                    pn_imageattach.ClearDeletedImageAttachList();
                    //pn_imageattach.StoreImageAttachList(lstImage);
                    Obj = obj;
                    Common.Functions.ShowMessgeInfo("Success");
                    //TODO preview
                    System.Diagnostics.Process.Start(AppConfig.WebUrl + "/other/collectionPreview.php?id=" + obj.id);
                }
                else
                {
                    controller.Delete(obj);
                    Common.Functions.ShowMessgeInfo("Fail");
                }
            }
            else
            {
                Common.Functions.ShowMessgeInfo("Fail");
            }
        }