示例#1
0
        public void should_get_object_children_with_source_files_folder()
        {
            // given
            var api = new Mock <IServerApi>();

            Setup(api);
            var meta       = new DMetadata();
            var parentType = TestTools.RandomMType(15);

            meta.Types.Add(TestTools.RandomMType(23));
            meta.Types.Add(parentType);
            api.Setup(a => a.GetMetadata(0)).Returns(meta);

            var parentId = Guid.NewGuid();
            var parent   = TestTools.RandomDObject(parentId);
            var childId1 = Guid.NewGuid();
            var childId2 = Guid.NewGuid();

            parent.TypeId = 15;
            parent.Children.Add(new DChild {
                ObjectId = childId1, TypeId = 23
            });
            parent.Children.Add(new DChild {
                ObjectId = childId2, TypeId = 23
            });

            var dbInfo        = new DDatabaseInfo();
            var searchFactory = new Mock <ISearchServiceFactory>();
            var backend       = new Mock <IBackend>();
            var service       = new ServerApiService(api.Object, dbInfo, searchFactory.Object, backend.Object);

            api.Setup(a => a.GetObjects(new[] { parentId })).Returns(new List <DObject> {
                parent
            });

            var children = new List <DObject>()
            {
                TestTools.RandomDObject(childId1, 23),
                TestTools.RandomDObject(childId2, 23)
            };

            api.Setup(a => a.GetObjects(new[] { childId1, childId2 })).Returns(children);

            // when
            parentType.IsMountable = true;
            var actual = service.GetObjectChildren(parentId, ChildrenType.ListView).ToArray();

            // then
            Assert.AreEqual(3, actual.Length);
            Assert.AreEqual(parentId, actual[0].Id);
            Assert.AreEqual(childId1, actual[1].Id);
            Assert.AreEqual(childId2, actual[2].Id);
        }
示例#2
0
        public void should_throw_exception_if_parent_not_found()
        {
            // given
            var api = new Mock <IServerApi>();

            Setup(api);
            var meta       = new DMetadata();
            var parentType = TestTools.RandomMType(15);

            meta.Types.Add(TestTools.RandomMType(23));
            meta.Types.Add(parentType);
            api.Setup(a => a.GetMetadata(0)).Returns(meta);

            var parentId      = Guid.NewGuid();
            var dbInfo        = new DDatabaseInfo();
            var searchFactory = new Mock <ISearchServiceFactory>();
            var backend       = new Mock <IBackend>();
            var service       = new ServerApiService(api.Object, dbInfo, searchFactory.Object, backend.Object);

            api.Setup(a => a.GetObjects(new[] { parentId })).Returns(new List <DObject>());

            // when
            Assert.Throws <Exception>(() => service.GetObjectChildren(parentId, ChildrenType.ListView));
        }