<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Moq;
using NUnit.Framework;
using NUnit.Framework.Constraints;

namespace CG.Web.MegaApiClient.Tests
{
    public abstract class NodeOperations : TestsBase
    {
        private const string DefaultNodeName = "NodeName";

        protected NodeOperations(Options options)
            : base(options)
        {
        }

        [TestCase(NodeType.Root)]
        [TestCase(NodeType.Inbox)]
        [TestCase(NodeType.Trash)]
        public void Validate_DefaultNodes_Succeeds(NodeType nodeType)
        {
            var nodes = this.Client.GetNodes().ToArray();

            Assert.That(nodes, Has.Length.EqualTo(this.SystemNodesCount + this.PermanentNodesCount));
            Assert.That(nodes, Has.Exactly(1)
                .Matches<INode>(x => x.Type == nodeType)
                .And.Property<INode>(x => x.ParentId).Empty
                .And.Property<INode>(x => x.Name).Null
                .And.Property<INode>(x => x.Size).EqualTo(0));
        }

        [TestCase(NodeType.Root)]
        [TestCase(NodeType.Inbox)]
        [TestCase(NodeType.Trash)]
        public void CreateFolder_Succeeds(NodeType parentNodeType)
        {
            var parentNode = this.GetNode(parentNodeType);
            var createdNode = this.CreateFolderNode(parentNode);

            Assert.That(createdNode, Is.Not.Null
                .And.Property<INode>(x => x.Name).EqualTo(DefaultNodeName)
                .And.Property<INode>(x => x.Type).EqualTo(NodeType.Directory)
                .And.Property<INode>(x => x.Size).EqualTo(0)
                .And.Property<INode>(x => x.ParentId).Not.Null
                .And.Property<INode>(x => x.ParentId).EqualTo(parentNode.Id));

            var nodes = this.Client.GetNodes();
            Assert.That(nodes, Has.Exactly(1)
                .Matches<INode>(x => x.Name == DefaultNodeName));
        }

        [TestCaseSource("GetInvalidCreateFolderParameters")]
        public void CreateFolder_InvalidParameters_Throws(string name, INode parentNode, IResolveConstraint constraint)
        {
            Assert.That(
                () => this.Client.CreateFolder(name, parentNode),
                constraint);
        }

        [TestCase("name", "name")]
        [TestCase("name", "NAME")]
        public void CreateFolder_SameName_Succeeds(string nodeName1, string nodeName2)
        {
            var parentNode = this.GetNode(NodeType.Root);
            var node1 = this.CreateFolderNode(parentNode, name: nodeName1);

            INode node2 = null;
            Assert.That(
                () => node2 = this.CreateFolderNode(parentNode, name: nodeName2),
                Throws.Nothing);

            Assert.That(node1, Is.Not.EqualTo(node2));
        }

        [Test]
        public void GetNodes_Succeeds()
        {
            var parentNode = this.GetNode(NodeType.Root);
            var createdNode = this.CreateFolderNode(parentNode);

            Assert.That(
                this.Client.GetNodes(),
                Has.Length.EqualTo(this.SystemNodesCount + this.PermanentNodesCount + 1));

            Assert.That(
                this.Client.GetNodes(parentNode).ToArray(), 
                Has.Length.EqualTo(this.PermanentFoldersRootNodesCount + 1)
                .And.Exactly(1).EqualTo(createdNode));
        }

        [Test]
        public void GetNodes_NullParentNode_Throws()
        {
            Assert.That(
                () => this.Client.GetNodes(null),
                Throws.TypeOf<ArgumentNullException>()
                .With.Property<ArgumentNullException>(x => x.ParamName).EqualTo("parent"));
        }

        [TestCase(null)]
        [TestCase(false)]
        [TestCase(true)]
        public void Delete_Succeeds(bool? moveToTrash)
        {
            var parentNode = this.GetNode(NodeType.Root);
            var trashNode = this.GetNode(NodeType.Trash);<commit_msg>Fixed broken UT related to 847eb41e1fd48977cb57e119cae10f462bfaf427<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Moq;
using NUnit.Framework;
using NUnit.Framework.Constraints;

namespace CG.Web.MegaApiClient.Tests
{
    public abstract class NodeOperations : TestsBase
    {
        private const string DefaultNodeName = "NodeName";

        protected NodeOperations(Options options)
            : base(options)
        {
        }

        [TestCase(NodeType.Root)]
        [TestCase(NodeType.Inbox)]
        [TestCase(NodeType.Trash)]
        public void Validate_DefaultNodes_Succeeds(NodeType nodeType)
        {
            var nodes = this.Client.GetNodes().ToArray();

            Assert.That(nodes, Has.Length.EqualTo(this.SystemNodesCount + this.PermanentNodesCount));
            Assert.That(nodes, Has.Exactly(1)
                .Matches<INode>(x => x.Type == nodeType)
                .And.Property<INode>(x => x.ParentId).Empty
                .And.Property<INode>(x => x.Name).Null
                .And.Property<INode>(x => x.Size).EqualTo(0));
        }

        [TestCase(NodeType.Root)]
        [TestCase(NodeType.Inbox)]
        [TestCase(NodeType.Trash)]
        public void CreateFolder_Succeeds(NodeType parentNodeType)
        {
            var parentNode = this.GetNode(parentNodeType);
            var createdNode = this.CreateFolderNode(parentNode);

            Assert.That(createdNode, Is.Not.Null
                .And.Property<INode>(x => x.Name).EqualTo(DefaultNodeName)
                .And.Property<INode>(x => x.Type).EqualTo(NodeType.Directory)
                .And.Property<INode>(x => x.Size).EqualTo(0)
                .And.Property<INode>(x => x.ParentId).Not.Null
                .And.Property<INode>(x => x.ParentId).EqualTo(parentNode.Id));

            var nodes = this.Client.GetNodes();
            Assert.That(nodes, Has.Exactly(1)
                .Matches<INode>(x => x.Name == DefaultNodeName));
        }

        [TestCaseSource("GetInvalidCreateFolderParameters")]
        public void CreateFolder_InvalidParameters_Throws(string name, INode parentNode, IResolveConstraint constraint)
        {
            Assert.That(
                () => this.Client.CreateFolder(name, parentNode),
                constraint);
        }

        [TestCase("name", "name")]
        [TestCase("name", "NAME")]
        public void CreateFolder_SameName_Succeeds(string nodeName1, string nodeName2)
        {
            var parentNode = this.GetNode(NodeType.Root);
            var node1 = this.CreateFolderNode(parentNode, name: nodeName1);

            INode node2 = null;
            Assert.That(
                () => node2 = this.CreateFolderNode(parentNode, name: nodeName2),
                Throws.Nothing);

            Assert.That(node1, Is.Not.EqualTo(node2));
        }

        [Test]
        public void GetNodes_Succeeds()
        {
            var parentNode = this.GetNode(NodeType.Root);
            var createdNode = this.CreateFolderNode(parentNode);

            Assert.That(
                this.Client.GetNodes().ToArray(),
                Has.Length.EqualTo(this.SystemNodesCount + this.PermanentNodesCount + 1));

            Assert.That(
                this.Client.GetNodes(parentNode).ToArray(), 
                Has.Length.EqualTo(this.PermanentFoldersRootNodesCount + 1)
                .And.Exactly(1).EqualTo(createdNode));
        }

        [Test]
        public void GetNodes_NullParentNode_Throws()
        {
            Assert.That(
                () => this.Client.GetNodes(null),
                Throws.TypeOf<ArgumentNullException>()
                .With.Property<ArgumentNullException>(x => x.ParamName).EqualTo("parent"));
        }

        [TestCase(null)]
        [TestCase(false)]
        [TestCase(true)]
        public void Delete_Succeeds(bool? moveToTrash)
        {
            var parentNode = this.GetNode(NodeType.Root);
            var trashNode = this.GetNode(NodeType.Trash);
{'fraction_non_alphanumeric': 0.11551030668677728, 'fraction_numerical': 0.007038712921065862, 'mean_word_length': 2.087698874660458, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1993326', 'n_tokens_mistral': 2266, 'n_tokens_neox': 2202, 'n_words': 342}