예제 #1
0
    public void Filter_On_Permissions()
    {
        var list = new List <ContentItemBasic>();

        for (var i = 0; i < 10; i++)
        {
            list.Add(new ContentItemBasic {
                Id = i, Name = "Test" + i, ParentId = -1
            });
        }

        var ids = list.Select(x => (int)x.Id).ToArray();

        var user = CreateUser(9, 0);

        var userServiceMock = new Mock <IUserService>();

        // We're only assigning 3 nodes browse permissions so that is what we expect as a result
        var permissions = new EntityPermissionCollection
        {
            new(9876, 1, new[] { ActionBrowse.ActionLetter.ToString() }),
            new(9876, 2, new[] { ActionBrowse.ActionLetter.ToString() }),
            new(9876, 3, new[] { ActionBrowse.ActionLetter.ToString() }),
            new(9876, 4, new[] { ActionUpdate.ActionLetter.ToString() }),
        };

        userServiceMock.Setup(x => x.GetPermissions(user, ids)).Returns(permissions);
        var userService = userServiceMock.Object;

        var att = new FilterAllowedOutgoingContentFilter(
            list.GetType(),
            null,
            ActionBrowse.ActionLetter,
            userService,
            Mock.Of <IEntityService>(),
            AppCaches.Disabled,
            Mock.Of <IBackOfficeSecurityAccessor>());

        att.FilterBasedOnPermissions(list, user);

        Assert.AreEqual(3, list.Count);
        Assert.AreEqual(1, list.ElementAt(0).Id);
        Assert.AreEqual(2, list.ElementAt(1).Id);
        Assert.AreEqual(3, list.ElementAt(2).Id);
    }
예제 #2
0
    public void GetValueFromResponse_Already_EnumerableContent()
    {
        var expected = new List <ContentItemBasic> {
            new()
        };

        var att = new FilterAllowedOutgoingContentFilter(
            expected.GetType(),
            null,
            ActionBrowse.ActionLetter,
            Mock.Of <IUserService>(),
            Mock.Of <IEntityService>(),
            AppCaches.Disabled,
            Mock.Of <IBackOfficeSecurityAccessor>());

        var result = att.GetValueFromResponse(new ObjectResult(expected));

        Assert.AreEqual(expected, result);
    }
예제 #3
0
    public void Filter_On_Start_Node()
    {
        var user              = CreateUser(9, 5);
        var userServiceMock   = new Mock <IUserService>();
        var userService       = userServiceMock.Object;
        var entityServiceMock = new Mock <IEntityService>();

        entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny <UmbracoObjectTypes>(), It.IsAny <int[]>()))
        .Returns(new[] { Mock.Of <TreeEntityPath>(entity => entity.Id == 5 && entity.Path == "-1,5") });
        var entityService = entityServiceMock.Object;

        var list = new List <ContentItemBasic>();
        var att  = new FilterAllowedOutgoingContentFilter(
            list.GetType(),
            null,
            ActionBrowse.ActionLetter,
            userService,
            entityService,
            AppCaches.Disabled,
            Mock.Of <IBackOfficeSecurityAccessor>());

        var path = string.Empty;

        for (var i = 0; i < 10; i++)
        {
            if (i > 0 && path.EndsWith(",") == false)
            {
                path += ",";
            }

            path += i.ToInvariantString();
            list.Add(new ContentItemBasic {
                Id = i, Name = "Test" + i, ParentId = i, Path = path
            });
        }

        att.FilterBasedOnStartNode(list, user);

        Assert.AreEqual(5, list.Count);
    }
예제 #4
0
    public void GetValueFromResponse_Returns_Null_Not_Found_Property()
    {
        var expected = new List <ContentItemBasic> {
            new()
        };
        var container = new MyTestClass {
            MyList = expected
        };

        var att = new FilterAllowedOutgoingContentFilter(
            expected.GetType(),
            "DontFind",
            ActionBrowse.ActionLetter,
            Mock.Of <IUserService>(),
            Mock.Of <IEntityService>(),
            AppCaches.Disabled,
            Mock.Of <IBackOfficeSecurityAccessor>());

        var actual = att.GetValueFromResponse(new ObjectResult(container));

        Assert.IsNull(actual);
    }
예제 #5
0
    public void GetValueFromResponse_From_Property()
    {
        var expected = new List <ContentItemBasic> {
            new()
        };
        var container = new MyTestClass {
            MyList = expected
        };

        var att = new FilterAllowedOutgoingContentFilter(
            expected.GetType(),
            nameof(MyTestClass.MyList),
            ActionBrowse.ActionLetter,
            Mock.Of <IUserService>(),
            Mock.Of <IEntityService>(),
            AppCaches.Disabled,
            Mock.Of <IBackOfficeSecurityAccessor>());

        var result = att.GetValueFromResponse(new ObjectResult(container));

        Assert.AreEqual(expected, result);
    }