Пример #1
0
    public void CombineStartNodes(string groupSn, string userSn, string expected)
    {
        // 1
        //  3
        //   5
        // 2
        //  4
        // bin
        //  6
        //  7
        //   8
        var paths = new Dictionary <int, string>
        {
            { 1, "-1,1" },
            { 2, "-1,2" },
            { 3, "-1,1,3" },
            { 4, "-1,2,4" },
            { 5, "-1,1,3,5" },
            { 6, "-1,-20,6" },
            { 7, "-1,-20,7" },
            { 8, "-1,-20,7,8" },
        };

        var esmock = new Mock <IEntityService>();

        esmock
        .Setup(x => x.GetAllPaths(It.IsAny <UmbracoObjectTypes>(), It.IsAny <int[]>()))
        .Returns <UmbracoObjectTypes, int[]>((type, ids) =>
                                             paths.Where(x => ids.Contains(x.Key)).Select(x => new TreeEntityPath {
            Id = x.Key, Path = x.Value
        }));

        var comma = new[] { ',' };

        var groupSnA = groupSn.Split(comma, StringSplitOptions.RemoveEmptyEntries)
                       .Select(x => int.Parse(x, CultureInfo.InvariantCulture)).ToArray();
        var userSnA = userSn.Split(comma, StringSplitOptions.RemoveEmptyEntries)
                      .Select(x => int.Parse(x, CultureInfo.InvariantCulture)).ToArray();
        var combinedA = UserExtensions.CombineStartNodes(UmbracoObjectTypes.Document, groupSnA, userSnA, esmock.Object)
                        .OrderBy(x => x).ToArray();
        var expectedA = expected.Split(comma, StringSplitOptions.RemoveEmptyEntries)
                        .Select(x => int.Parse(x, CultureInfo.InvariantCulture)).OrderBy(x => x).ToArray();

        var ok = combinedA.Length == expectedA.Length;

        if (ok)
        {
            ok = expectedA.Where((t, i) => t != combinedA[i]).Any() == false;
        }

        if (ok == false)
        {
            Assert.Fail("Expected \"" + string.Join(",", expectedA) + "\" but got \"" + string.Join(",", combinedA) +
                        "\".");
        }
    }