示例#1
0
 public RestoreException(RestoreResultType resultType, string contentPath)
     : this(resultType, contentPath, null)
 {
 }
示例#2
0
 public RestoreException(RestoreResultType resultType, string contentPath, Exception inner)
     : base(string.Empty, inner)
 {
     ResultType  = resultType;
     ContentPath = contentPath;
 }
示例#3
0
        //============================================================================== Constructors

        public RestoreException(RestoreResultType resultType)
            : this(resultType, string.Empty)
        {
        }
示例#4
0
        private static void RestoreFromTrash(int id, string encodedTargetPath, bool addNewName, RestoreResultType expectedRestoreResult)
        {
            var trashbin = LoadTrash();

            var tb = trashbin.Children.OfType<TrashBag>().SingleOrDefault(p => p.DeletedContent.Id == id);

            if(tb == null)
                throw new Exception("TrashBag missing.");

            var decodedTargetPath = (encodedTargetPath != null) ? DecodePath(encodedTargetPath) : tb.OriginalPath;
            var originalContentName = tb.DeletedContent.Name;
            
            
            var trashResult = RestoreResultType.Success;
            
            try
            {
                TrashBin.Restore(tb, decodedTargetPath, addNewName);
            }
            catch (RestoreException rex)
            {
                trashResult = rex.ResultType;
            }

            Assert.IsTrue(trashResult == expectedRestoreResult, String.Format("The return value of the restore method should match the expected value. The returned value of restore was: {0}", trashResult));
            
            var itemInTargetLocation = LoadNode(String.Concat(decodedTargetPath,"/",originalContentName));

            AccessProvider.Current.SetCurrentUser(User.Administrator);
            
            switch (expectedRestoreResult)
                {
                    case RestoreResultType.Success:
                        if (addNewName)
                        {
                            var restoredItemWithNewName = Node.LoadNode(id);

                            Assert.IsTrue(decodedTargetPath == restoredItemWithNewName.ParentPath,
                                          "Renamed content should be in its target directory");
                            Assert.IsTrue(itemInTargetLocation.Id != id,
                                          "The id of the content in the target location should not be identical to the id of the restored content.");
                        }
                        else
                        {
                            Assert.IsNotNull(itemInTargetLocation,
                                         "Restored item should be exist in the target location.");
                            Assert.IsTrue(itemInTargetLocation.Id == id,
                                          "The id of the content in the target location should be identical to the id of the restored content.");
                        }

                        Assert.IsFalse(CheckContentInTrash(id), "This content should get out of trash.");
                        break;

                    case RestoreResultType.ExistingName:
                        Assert.IsNotNull(itemInTargetLocation,
                                         "There must be an item in the target location.");
                        Assert.IsTrue(itemInTargetLocation.Id != id,
                                      "There must be an item in the target location with the same name as the one to be restored.");
                        Assert.IsTrue(CheckContentInTrash(id), "This content should stay at trash.");
                        break;
                    case RestoreResultType.NoParent:
                        var parentInTargetLocation = Node.LoadNode(decodedTargetPath);
                        Assert.IsNull(parentInTargetLocation,
                                      "Content parent should not exist in the original location.");
                        Assert.IsTrue(CheckContentInTrash(id), "This content should stay at trash.");
                        break;
                    case RestoreResultType.Nonedefined:
                    case RestoreResultType.PermissionError:
                    case RestoreResultType.UnknownError:
                        Assert.IsNull(itemInTargetLocation, "Restored item should not exist in the original location.");
                        Assert.IsTrue(CheckContentInTrash(id), "This content should stay at trash.");
                        break;
                    //TODO: atnezni
                    case RestoreResultType.ForbiddenContentType:
                        var parent = Node.LoadNode(decodedTargetPath);
                        var tbContentType = ((GenericContent)parent).GetAllowedChildTypes().Where(ct => ct.Name == tb.NodeType.Name);
                        
                        Assert.IsTrue(!(parent is IFolder) || (tbContentType.Count() == 0) ,
                                      "Content parent should not exist in the original location or it is not a folder.");
                        Assert.IsTrue(CheckContentInTrash(id), "This content should stay at trash.");
                        break;
                    default:
                        throw new NotImplementedException();
                        
                }
            
        }
示例#5
0
 public RestoreException(RestoreResultType resultType, string contentPath, Exception inner)
     : base(string.Empty, inner)
 {
     ResultType = resultType;
     ContentPath = contentPath;
 }
示例#6
0
 public RestoreException(RestoreResultType resultType, string contentPath)
     : this(resultType, contentPath, null)
 {
 }
示例#7
0
        //============================================================================== Constructors

        public RestoreException(RestoreResultType resultType)
            : this(resultType, string.Empty)
        {
        }