Esempio n. 1
0
        public void NodeIdentifier_Create()
        {
            var services = new ServiceCollection()
                           .AddSingleton <DataProvider>(new InMemoryDataProvider())
                           .AddSingleton(NullLoggerFactory.Instance.CreateLogger <DataStore>())
                           .AddSingleton <IDataStore, DataStore>()
                           .AddSingleton(NullLoggerFactory.Instance.CreateLogger <TreeLock>())
                           .AddSingleton <ITreeLockController, TreeLockController>()
                           .BuildServiceProvider();

            Providers.Instance = new Providers(services);

            var identifier = NodeIdentifier.Get(123);

            Assert.AreEqual(123, identifier.Id, "#1 identifier is incorrect.");
            Assert.IsNull(identifier.Path, "#2 identifier is incorrect.");

            identifier = NodeIdentifier.Get("/Root/P1");
            Assert.AreEqual("/Root/P1", identifier.Path, "#3 identifier is incorrect.");
            Assert.AreEqual(0, identifier.Id, "#4 identifier is incorrect.");

            identifier = NodeIdentifier.Get("123");
            Assert.AreEqual(123, identifier.Id, "#5 identifier is incorrect.");
            Assert.IsNull(identifier.Path, "#6 identifier is incorrect.");

            short shortId = 123;

            identifier = NodeIdentifier.Get(shortId);
            Assert.AreEqual(shortId, identifier.Id, "#7 identifier is incorrect.");
            Assert.IsNull(identifier.Path, "#8 identifier is incorrect.");
        }
Esempio n. 2
0
 public void NodeIdentifier_Valid()
 {
     Test(() =>
     {
         NodeIdentifier.Get(User.Administrator);
     });
 }
Esempio n. 3
0
        public void NodeIdentifier_Create()
        {
            var identifier = NodeIdentifier.Get(123);

            Assert.AreEqual(123, identifier.Id, "#1 identifier is incorrect.");
            Assert.IsNull(identifier.Path, "#2 identifier is incorrect.");

            identifier = NodeIdentifier.Get("/Root/P1");
            Assert.AreEqual("/Root/P1", identifier.Path, "#3 identifier is incorrect.");
            Assert.AreEqual(0, identifier.Id, "#4 identifier is incorrect.");

            identifier = NodeIdentifier.Get("123");
            Assert.AreEqual(123, identifier.Id, "#5 identifier is incorrect.");
            Assert.IsNull(identifier.Path, "#6 identifier is incorrect.");

            short shortId = 123;

            identifier = NodeIdentifier.Get(shortId);
            Assert.AreEqual(shortId, identifier.Id, "#7 identifier is incorrect.");
            Assert.IsNull(identifier.Path, "#8 identifier is incorrect.");
        }
Esempio n. 4
0
        public void NodeIdentifier_Create()
        {
            Providers.Instance.DataProvider = new InMemoryDataProvider();
            Providers.Instance.InitializeDataStore();

            var identifier = NodeIdentifier.Get(123);

            Assert.AreEqual(123, identifier.Id, "#1 identifier is incorrect.");
            Assert.IsNull(identifier.Path, "#2 identifier is incorrect.");

            identifier = NodeIdentifier.Get("/Root/P1");
            Assert.AreEqual("/Root/P1", identifier.Path, "#3 identifier is incorrect.");
            Assert.AreEqual(0, identifier.Id, "#4 identifier is incorrect.");

            identifier = NodeIdentifier.Get("123");
            Assert.AreEqual(123, identifier.Id, "#5 identifier is incorrect.");
            Assert.IsNull(identifier.Path, "#6 identifier is incorrect.");

            short shortId = 123;

            identifier = NodeIdentifier.Get(shortId);
            Assert.AreEqual(shortId, identifier.Id, "#7 identifier is incorrect.");
            Assert.IsNull(identifier.Path, "#8 identifier is incorrect.");
        }
Esempio n. 5
0
        public static BatchActionResponse MoveBatch(Content content, string targetPath, object[] paths)
        {
            var targetNode = Node.LoadNode(targetPath);

            if (targetNode == null)
            {
                throw new ContentNotFoundException(targetPath);
            }

            var results          = new List <object>();
            var errors           = new List <ErrorContent>();
            var identifiers      = paths.Select(NodeIdentifier.Get).ToList();
            var foundIdentifiers = new List <NodeIdentifier>();
            var nodes            = Node.LoadNodes(identifiers);

            foreach (var node in nodes)
            {
                try
                {
                    // Collect already found identifiers in a separate list otherwise the error list
                    // would contain multiple errors for the same content.
                    foundIdentifiers.Add(NodeIdentifier.Get(node));

                    node.MoveTo(targetNode);
                    results.Add(new { node.Id, node.Path, node.Name });
                }
                catch (Exception e)
                {
                    //TODO: we should log only relevant exceptions here and skip
                    // business logic-related errors, e.g. lack of permissions or
                    // existing target content path.
                    SnLog.WriteException(e);

                    errors.Add(new ErrorContent
                    {
                        Content = new { node?.Id, node?.Path, node?.Name },
                        Error   = new Error
                        {
                            Code          = "NotSpecified",
                            ExceptionType = e.GetType().FullName,
                            InnerError    = new StackInfo {
                                Trace = e.StackTrace
                            },
                            Message = new ErrorMessage
                            {
                                Lang  = System.Globalization.CultureInfo.CurrentUICulture.Name.ToLower(),
                                Value = e.Message
                            }
                        }
                    });
                }
            }

            // iterating through the missing identifiers and making error items for them
            errors.AddRange(identifiers.Where(id => !foundIdentifiers.Exists(f => f.Id == id.Id || f.Path == id.Path))
                            .Select(missing => new ErrorContent
            {
                Content = new { missing?.Id, missing?.Path },
                Error   = new Error
                {
                    Code          = "ResourceNotFound",
                    ExceptionType = "ContentNotFoundException",
                    InnerError    = null,
                    Message       = new ErrorMessage
                    {
                        Lang  = System.Globalization.CultureInfo.CurrentUICulture.Name.ToLower(),
                        Value = string.Format(SNSR.GetString(SNSR.Exceptions.OData.ErrorContentNotFound),
                                              missing?.Path)
                    }
                }
            }));

            return(BatchActionResponse.Create(results, errors, results.Count + errors.Count));
        }
Esempio n. 6
0
 public void NodeIdentifier_Invalid_3()
 {
     NodeIdentifier.Get(new byte[] { 1, 2, 3 });
 }
Esempio n. 7
0
 public void NodeIdentifier_Invalid_2()
 {
     NodeIdentifier.Get(true);
 }
Esempio n. 8
0
 public void NodeIdentifier_Invalid_1()
 {
     NodeIdentifier.Get(12.34);
 }
Esempio n. 9
0
 public void NodeIdentifier_Invalid_4()
 {
     NodeIdentifier.Get(new object());
 }
 public void NodeIdentifier_Invalid_4()
 {
     NodeIdentifier.Get(NodeHead.Get(1));
 }