public void ExplorerItemFactory_CreateExplorerItemWithType_Authorisation_ExpectFirstGenChildrenWithPermissions()
        {
            //------------Setup for test--------------------------
            var catalogue = new Mock <IResourceCatalog>();
            var directory = new Mock <IDirectory>();
            var auth      = new Mock <IAuthorizationService>();
            var resources = MoqUtil.GenerateMockEnumerable <IResource>(4).ToList();
            var guid      = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };

            for (int i = 0; i < resources.Count; i++)
            {
                var resource = resources[i];
                resource.Setup(a => a.GetResourcePath(It.IsAny <Guid>())).Returns("" + i);
                resource.Setup(a => a.ResourceName).Returns(i.ToString);
                resource.Setup(a => a.ResourceID).Returns(guid[i]);
            }
            resources[0].Setup(a => a.ResourceType).Returns("EmailSource");
            auth.Setup(a => a.GetResourcePermissions(guid[0])).Returns(Permissions.Contribute);
            auth.Setup(a => a.GetResourcePermissions(guid[1])).Returns(Permissions.Administrator);
            auth.Setup(a => a.GetResourcePermissions(guid[2])).Returns(Permissions.DeployFrom);
            auth.Setup(a => a.GetResourcePermissions(guid[3])).Returns(Permissions.DeployTo);
            catalogue.Setup(a => a.GetResourceList(It.IsAny <Guid>())).Returns(MoqUtil.ProxiesFromMockEnumerable(resources).ToList());
            var explorerItemFactory = new ExplorerItemFactory(catalogue.Object, directory.Object, auth.Object);

            //------------Execute Test---------------------------
            var item = explorerItemFactory.CreateRootExplorerItem(@"b:\bob", Guid.NewGuid());

            //------------Assert Results-------------------------
            Assert.AreEqual(Environment.MachineName, item.DisplayName);
            Assert.AreEqual(4, item.Children.Count);
            Assert.AreEqual(item.Children[0].Permissions, Permissions.Contribute);
            Assert.AreEqual(item.Children[1].Permissions, Permissions.Administrator);
            Assert.AreEqual(item.Children[2].Permissions, Permissions.DeployFrom);
            Assert.AreEqual(item.Children[3].Permissions, Permissions.DeployTo);
        }
        public void ExplorerItemFactory_CreateExplorerItemWithType_Folders_ExpectTwoChildren()
        {
            //------------Setup for test--------------------------
            var catalogue = new Mock <IResourceCatalog>();
            var directory = new Mock <IDirectory>();
            var resources = MoqUtil.GenerateMockEnumerable <IResource>(4).ToList();
            var auth      = new Mock <IAuthorizationService>();

            auth.Setup(c => c.GetResourcePermissions(It.IsAny <Guid>())).Returns(Permissions.Contribute);
            for (int i = 0; i < resources.Count; i++)
            {
                var resource = resources[i];
                resource.Setup(a => a.GetResourcePath(It.IsAny <Guid>())).Returns("1");
                resource.Setup(a => a.ResourceName).Returns(i.ToString);
                resource.Setup(a => a.ResourceID).Returns(Guid.NewGuid);
                resource.Setup(a => a.ResourceType).Returns("EmailSource");
            }
            directory.Setup(a => a.GetDirectories(@"b:\bob")).Returns(new[] { @"b:\bob\1", @"b:\bob\2" });
            catalogue.Setup(a => a.GetResourceList(It.IsAny <Guid>())).Returns(MoqUtil.ProxiesFromMockEnumerable(resources).ToList());
            var explorerItemFactory = new ExplorerItemFactory(catalogue.Object, directory.Object, auth.Object);

            //------------Execute Test---------------------------
            var item = explorerItemFactory.CreateRootExplorerItem("Folder", @"b:\bob", Guid.NewGuid());

            //------------Assert Results-------------------------
            Assert.AreEqual(Environment.MachineName, item.DisplayName);
            Assert.AreEqual(2, item.Children.Count);
            Assert.IsTrue(item.Children.All(a => a.Permissions == Permissions.Contribute));
            Assert.IsTrue(item.Permissions == Permissions.Contribute);
        }
        public void ExplorerItemFactory_CreateExplorerItemWithType_MultipleGenerations_ExpectSecondAndFirstGenChildren()
        {
            //------------Setup for test--------------------------
            var catalogue = new Mock <IResourceCatalog>();
            var directory = new Mock <IDirectory>();
            var auth      = new Mock <IAuthorizationService>();
            var resources = MoqUtil.GenerateMockEnumerable <IResource>(5).ToList();

            for (int i = 0; i < resources.Count; i++)
            {
                var resource = resources[i];
                resource.Setup(a => a.GetResourcePath(It.IsAny <Guid>())).Returns(i % 2 == 0 ? "" + i : "1\\" + i);
                resource.Setup(a => a.ResourceName).Returns(i.ToString);
                resource.Setup(a => a.ResourceID).Returns(Guid.NewGuid);
                resource.Setup(a => a.ResourceType).Returns(i % 2 == 0 ? "EmailSource" : "DbSource");
            }
            resources[3].Setup(a => a.ResourceType).Returns("EmailSource");
            directory.Setup(a => a.GetDirectories(@"b:\bob")).Returns(new[] { @"b:\bob\1" });
            catalogue.Setup(a => a.GetResourceList(It.IsAny <Guid>())).Returns(MoqUtil.ProxiesFromMockEnumerable(resources).ToList());
            var explorerItemFactory = new ExplorerItemFactory(catalogue.Object, directory.Object, auth.Object);

            //------------Execute Test---------------------------
            var item = explorerItemFactory.CreateRootExplorerItem("EmailSource", @"b:\bob", Guid.NewGuid());

            //------------Assert Results-------------------------
            Assert.AreEqual(Environment.MachineName, item.DisplayName);
            Assert.AreEqual(4, item.Children.Count);
            Assert.AreEqual(1, item.Children[0].Children.Count);
        }
        public void ExplorerItemFactory_CreateExplorerItem_SecondtGen_ExpectSecondGenChildren()
        {
            //------------Setup for test--------------------------
            var catalogue = new Mock <IResourceCatalog>();
            var directory = new Mock <IDirectory>();
            var auth      = new Mock <IAuthorizationService>();
            var resources = MoqUtil.GenerateMockEnumerable <IResource>(4).ToList();

            for (int i = 0; i < resources.Count; i++)
            {
                var resource = resources[i];
                resource.Setup(a => a.GetResourcePath(It.IsAny <Guid>())).Returns("1\\" + i);
                resource.Setup(a => a.ResourceName).Returns(i.ToString);
                resource.Setup(a => a.ResourceID).Returns(Guid.NewGuid);
                resource.Setup(a => a.IsService).Returns(true);
            }
            directory.Setup(a => a.GetDirectories(@"b:\bob")).Returns(new[] { @"b:\bob\1" });
            catalogue.Setup(a => a.GetResourceList(It.IsAny <Guid>())).Returns(MoqUtil.ProxiesFromMockEnumerable(resources).ToList());
            var explorerItemFactory = new ExplorerItemFactory(catalogue.Object, directory.Object, auth.Object);

            //------------Execute Test---------------------------
            var item = explorerItemFactory.CreateRootExplorerItem(@"b:\bob", Guid.NewGuid());

            //------------Assert Results-------------------------
            Assert.AreEqual(Environment.MachineName, item.DisplayName);
            Assert.IsTrue(item.IsServer);
            Assert.AreEqual(1, item.Children.Count);
            Assert.IsTrue(item.Children[0].IsFolder);
            Assert.AreEqual(4, item.Children[0].Children.Count);
            Assert.IsTrue(item.Children[0].Children.All(explorerItem => explorerItem.IsService));
        }
        public void ExplorerItemFactory_CreateExplorerItem_NoResources_ExpectARoot()
        {
            //------------Setup for test--------------------------
            var catalogue = new Mock <IResourceCatalog>();
            var directory = new Mock <IDirectory>();
            var auth      = new Mock <IAuthorizationService>();

            catalogue.Setup(a => a.GetResourceList(It.IsAny <Guid>())).Returns(new List <IResource>());

            var explorerItemFactory = new ExplorerItemFactory(catalogue.Object, directory.Object, auth.Object);

            //------------Execute Test---------------------------
            var item = explorerItemFactory.CreateRootExplorerItem(@"b:\bob", Guid.NewGuid());

            //------------Assert Results-------------------------
            Assert.AreEqual(Environment.MachineName, item.DisplayName);
            Assert.AreEqual(0, item.Children.Count);
        }
        public void ExplorerItemFactory_CreateExplorerItemWithType_ReservedServicesNotReturned_SecondtGen_ExpectSecondGenChildren()
        {
            //------------Setup for test--------------------------
            var auth      = new Mock <IAuthorizationService>();
            var catalogue = new Mock <IResourceCatalog>();
            var directory = new Mock <IDirectory>();
            var resources = MoqUtil.GenerateMockEnumerable <IResource>(4).ToList();

            for (int i = 0; i < resources.Count; i++)
            {
                var resource = resources[i];
                resource.Setup(a => a.GetResourcePath(It.IsAny <Guid>())).Returns("1\\" + i);
                resource.Setup(a => a.ResourceName).Returns(i.ToString);
                resource.Setup(a => a.ResourceID).Returns(Guid.NewGuid);
                resource.Setup(a => a.ResourceType).Returns("EmailSource");
            }
            var mockReserverService = new Mock <IResource>();

            mockReserverService.Setup(a => a.GetResourcePath(It.IsAny <Guid>())).Returns("1");
            mockReserverService.Setup(a => a.ResourceName).Returns("TestReservedService");
            mockReserverService.Setup(a => a.ResourceID).Returns(Guid.NewGuid);
            mockReserverService.Setup(a => a.ResourceType).Returns("ReservedService");
            resources.Add(mockReserverService);
            directory.Setup(a => a.GetDirectories(@"b:\bob")).Returns(new[] { @"b:\bob\1" });
            catalogue.Setup(a => a.GetResourceList(It.IsAny <Guid>())).Returns(MoqUtil.ProxiesFromMockEnumerable(resources).ToList());
            var explorerItemFactory = new ExplorerItemFactory(catalogue.Object, directory.Object, auth.Object);

            //------------Execute Test---------------------------
            var item = explorerItemFactory.CreateRootExplorerItem(@"b:\bob", Guid.NewGuid());

            //------------Assert Results-------------------------
            Assert.AreEqual(1, item.Children.Count);
            Assert.AreEqual(4, item.Children[0].Children.Count);
            var found = item.Children[0].Children.FirstOrDefault(explorerItem => explorerItem.DisplayName == "TestReservedService");

            Assert.IsNull(found);
        }