Ejemplo n.º 1
0
        public void FiltersGalleryTemplatesUsingComplexQuery()
        {
            string             filterString = "Publisher eq 'Microsoft' and CategoryIds/any(c: c eq 'awesome')";
            ItemListParameters actual       = new ItemListParameters();

            galleryClientMock.Setup(f => f.Items.ListAsync(It.IsAny <ItemListParameters>(), new CancellationToken()))
            .Returns(Task.Factory.StartNew(() => new ItemListResult
            {
                Items = new List <GalleryItem>()
                {
                    new GalleryItem()
                    {
                        Name      = "Template1",
                        Publisher = "Microsoft"
                    },
                    new GalleryItem()
                    {
                        Name      = "Template2",
                        Publisher = "Microsoft"
                    }
                }
            }))
            .Callback((ItemListParameters p, CancellationToken c) => actual = p);

            FilterGalleryTemplatesOptions options = new FilterGalleryTemplatesOptions()
            {
                Publisher = "Microsoft",
                Category  = "awesome"
            };

            List <PSGalleryItem> result = galleryTemplatesClient.FilterGalleryTemplates(options);

            Assert.Equal(2, result.Count);
            Assert.Equal(filterString, actual.Filter);
        }
Ejemplo n.º 2
0
        public void FiltersGalleryTemplates()
        {
            string             filterString = FilterString.Generate <ItemListFilter>(f => f.Publisher == "Microsoft");
            ItemListParameters actual       = new ItemListParameters();

            galleryClientMock.Setup(f => f.Items.ListAsync(It.IsAny <ItemListParameters>(), new CancellationToken()))
            .Returns(Task.Factory.StartNew(() => new ItemListResult
            {
                Items = new List <GalleryItem>()
                {
                    new GalleryItem()
                    {
                        Name      = "Template1",
                        Publisher = "Microsoft"
                    },
                    new GalleryItem()
                    {
                        Name      = "Template2",
                        Publisher = "Microsoft"
                    }
                }
            }))
            .Callback((ItemListParameters p, CancellationToken c) => actual = p);

            FilterGalleryTemplatesOptions options = new FilterGalleryTemplatesOptions()
            {
                Publisher = "Microsoft"
            };

            List <PSGalleryItem> result = galleryTemplatesClient.FilterGalleryTemplates(options);

            Assert.Equal(2, result.Count);
            Assert.True(result.All(g => g.Publisher == "Microsoft"));
            Assert.Equal(filterString, actual.Filter);
        }
        public override void ExecuteCmdlet()
        {
            FilterGalleryTemplatesOptions options = new FilterGalleryTemplatesOptions()
            {
                Category  = Category,
                Identity  = Identity,
                Publisher = Publisher
            };

            List <PSGalleryItem> galleryItems = GalleryTemplatesClient.FilterGalleryTemplates(options);

            if (galleryItems != null)
            {
                if (galleryItems.Count == 1 && !string.IsNullOrEmpty(Identity))
                {
                    WriteObject(galleryItems[0]);
                }
                else
                {
                    List <PSObject> output = new List <PSObject>();
                    galleryItems.Where(gi => !gi.Identity.EndsWith("-placeholder"))
                    .OrderBy(gi => gi.Identity)
                    .ToList()
                    .ForEach(gi => output.Add(base.ConstructPSObject(
                                                  null,
                                                  "Publisher", gi.Publisher,
                                                  "Identity", gi.Identity)));
                    WriteObject(output, true);
                }
            }
        }
Ejemplo n.º 4
0
        public void FiltersGalleryTemplatesLatestVersion()
        {
            string             filterString = FilterString.Generate <ItemListFilter>(f => f.Publisher == "Microsoft");
            ItemListParameters actual       = new ItemListParameters();

            galleryClientMock.Setup(f => f.Items.ListAsync(It.IsAny <ItemListParameters>(), new CancellationToken()))
            .Returns(Task.Factory.StartNew(() => new ItemListResult
            {
                Items = new List <GalleryItem>()
                {
                    new GalleryItem()
                    {
                        Name      = "Template0",
                        Publisher = "Microsoft",
                        Version   = "0.0.0.0"
                    },
                    new GalleryItem()
                    {
                        Name      = "Template0",
                        Publisher = "Microsoft",
                        Version   = "0.0.0.1"
                    },
                    new GalleryItem()
                    {
                        Name      = "Template0",
                        Publisher = "Microsoft",
                        Version   = "0.0.0.2"
                    }
                }
            }))
            .Callback((ItemListParameters p, CancellationToken c) => actual = p);

            FilterGalleryTemplatesOptions options = new FilterGalleryTemplatesOptions()
            {
                ApplicationName = "Template0"
            };

            List <PSGalleryItem> result = galleryTemplatesClient.FilterGalleryTemplates(options);

            Assert.Equal(1, result.Count);
            Assert.Equal("Template0", result[0].Name);
            Assert.Equal("0.0.0.2", result[0].Version);
        }
        public override void ExecuteCmdlet()
        {
            WriteWarning("This cmdlet is being deprecated and will be removed in a future release.");
            FilterGalleryTemplatesOptions options = new FilterGalleryTemplatesOptions()
            {
                Category        = Category,
                Identity        = Identity,
                Publisher       = Publisher,
                ApplicationName = ApplicationName,
                AllVersions     = AllVersions
            };

            if (Category == null && Identity == null && Publisher == null && ApplicationName == null)
            {
                // if there are no filter parameters, return everything
                options.AllVersions = true;
            }

            List <PSGalleryItem> galleryItems = GalleryTemplatesClient.FilterGalleryTemplates(options);

            if (galleryItems != null)
            {
                if (galleryItems.Count == 1 && !string.IsNullOrEmpty(Identity))
                {
                    WriteObject(galleryItems[0]);
                }
                else
                {
                    List <PSObject> output = new List <PSObject>();
                    galleryItems.Where(gi => !gi.Identity.EndsWith("-placeholder"))
                    .OrderBy(gi => gi.Identity)
                    .ToList()
                    .ForEach(gi => output.Add(base.ConstructPSObject(
                                                  null,
                                                  "Publisher", gi.Publisher,
                                                  "Identity", gi.Identity)));
                    WriteObject(output, true);
                }
            }
        }
Ejemplo n.º 6
0
        public void GetsGalleryTemplates()
        {
            FilterGalleryTemplatesOptions options = new FilterGalleryTemplatesOptions()
            {
                Category  = "category",
                Identity  = "hobba",
                Publisher = "Microsoft"
            };
            FilterGalleryTemplatesOptions actual = new FilterGalleryTemplatesOptions();
            List <PSGalleryItem>          result = new List <PSGalleryItem>()
            {
                new PSGalleryItem()
                {
                    Publisher = "Microsoft",
                    Identity  = "T1"
                },
                new PSGalleryItem()
                {
                    Publisher = "Microsoft",
                    Identity  = "T2"
                },
            };

            galleryTemplatesClientMock.Setup(f => f.FilterGalleryTemplates(It.IsAny <FilterGalleryTemplatesOptions>()))
            .Returns(result)
            .Callback((FilterGalleryTemplatesOptions o) => actual = o);

            cmdlet.Category  = options.Category;
            cmdlet.Identity  = options.Identity;
            cmdlet.Publisher = options.Publisher;

            cmdlet.ExecuteCmdlet();

            Assert.Equal(2, result.Count);
            Assert.True(result.All(g => g.Publisher == "Microsoft"));

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <List <PSObject> >(), true), Times.Once());
        }