public void DifferentVersionNotEqual()
        {
            var a1 = new ODataPackage(new DataServicePackage { Id = "a", Version = "1.0" });
            var a2 = new ODataPackage(new DataServicePackage { Id = "a", Version = "2.0" });

            Assert.That(a1, Is.Not.EqualTo(a2));
        }
示例#2
0
        public static Stream CreatePackageStream(string baseAddress, ODataPackage package)
        {
            var writerSettings = new ODataMessageWriterSettings()
            {
                Indent          = true, // pretty printing
                CheckCharacters = false,
                BaseUri         = new Uri("http://localhost:12345"),
                Version         = ODataVersion.V3
            };

            writerSettings.SetContentType(ODataFormat.Atom);

            var responseMessage = new MemoryResponseMessage();
            var writer          = new ODataMessageWriter(responseMessage, writerSettings);

            var feedWriter = writer.CreateODataEntryWriter();

            feedWriter.WriteStart(MapPackageToEntry(baseAddress, package));
            feedWriter.WriteEnd();
            feedWriter.Flush();

            var stream = responseMessage.GetStream();

            stream.Seek(0, SeekOrigin.Begin);

            return(stream);
        }
        public void EqualsIgnoresOtherProperties()
        {
            var a1 = new ODataPackage(new DataServicePackage { Id = "a", Version = "1.0", Description = "ignore me" });
            var a2 = new ODataPackage(new DataServicePackage { Id = "a", Version = "1.0", Description = "ignore me and me too" });

            Assert.That(a1, Is.EqualTo(a2));
        }
        public void Equals()
        {
            var a1 = new ODataPackage(new DataServicePackage { Id = "a", Version = "1.0" });
            var a2 = new ODataPackage(new DataServicePackage { Id = "a", Version = "1.0" });

            Assert.That(a1, Is.EqualTo(a2));
        }
示例#5
0
 private static XElement GetProperties(ODataPackage package)
 {
     return(new XElement(
                XmlElements.m_properties,
                new XElement(XmlElements.d_Id, package.Id),
                new XElement(XmlElements.d_Title, package.Title),
                new XElement(XmlElements.d_Version, package.Version),
                new XElement(XmlElements.d_NormalizedVersion, package.NormalizedVersion),
                new XElement(XmlElements.d_Authors, package.Authors),
                new XElement(XmlElements.d_Copyright, package.Copyright),
                new XElement(XmlElements.d_Dependencies, package.Dependencies),
                new XElement(XmlElements.d_Description, package.Description),
                new XElement(XmlElements.d_DownloadCount, package.DownloadCount),          //TODO m:type="Edm.Int32"
                new XElement(XmlElements.d_LastEdited, package.LastUpdated),
                new XElement(XmlElements.d_Published, package.Published),
                new XElement(XmlElements.d_PackageHash, package.PackageHash),
                new XElement(XmlElements.d_PackageHashAlgorithm, package.PackageHashAlgorithm),
                new XElement(XmlElements.d_PackageSize, package.PackageSize),
                new XElement(XmlElements.d_ProjectUrl, package.ProjectUrl),
                new XElement(XmlElements.d_IconUrl, package.IconUrl),
                new XElement(XmlElements.d_LicenseUrl, package.LicenseUrl),
                //new XElement(XmlElements.d_ReportAbuseUrl, package.ReportAbuseUrl),
                new XElement(XmlElements.d_Tags, package.Tags),
                new XElement(XmlElements.d_RequireLicenseAcceptance, package.RequireLicenseAcceptance)
                ));
 }
示例#6
0
        public void SetsNormalizedVersionFromDataServicePackage()
        {
            var package = new ODataPackage(new DataServicePackage {
                Id = "a", Version = "1.0.0.0"
            });

            Assert.That(package.NormalizedVersion, Is.EqualTo("1.0.0"));
        }
示例#7
0
        private Uri BuildLinkForStreamProperty(ODataPackage package, EntityInstanceContext context)
        {
            var segments = GetPackagePathSegments(package);

            segments.Add(new ActionPathSegment("Download"));
            var downloadUrl = context.Url.CreateODataLink(segments);

            return(new Uri(downloadUrl));
        }
示例#8
0
        public void Equals()
        {
            var a1 = new ODataPackage(new DataServicePackage {
                Id = "a", Version = "1.0"
            });
            var a2 = new ODataPackage(new DataServicePackage {
                Id = "a", Version = "1.0"
            });

            Assert.That(a1, Is.EqualTo(a2));
        }
示例#9
0
        public void EqualsIgnoresOtherProperties()
        {
            var a1 = new ODataPackage(new DataServicePackage {
                Id = "a", Version = "1.0", Description = "ignore me"
            });
            var a2 = new ODataPackage(new DataServicePackage {
                Id = "a", Version = "1.0", Description = "ignore me and me too"
            });

            Assert.That(a1, Is.EqualTo(a2));
        }
示例#10
0
        public void DifferentVersionNotEqual()
        {
            var a1 = new ODataPackage(new DataServicePackage {
                Id = "a", Version = "1.0"
            });
            var a2 = new ODataPackage(new DataServicePackage {
                Id = "a", Version = "2.0"
            });

            Assert.That(a1, Is.Not.EqualTo(a2));
        }
示例#11
0
        private static List <ODataPathSegment> GetPackagePathSegments(ODataPackage package)
        {
            var keyValue = "Id='" + package.Id + "',Version='" + SemanticVersion.Parse(package.Version).ToNormalizedString() + "'";

            var segments = new List <ODataPathSegment>
            {
                new EntitySetPathSegment("Packages"),
                new KeyValuePathSegment(keyValue)
            };

            return(segments);
        }
示例#12
0
        private static List <ODataPathSegment> GetPackagePathSegments(ODataPackage package)
        {
            var keyValue = "Id='" + package.Id + "',Version='" + RemoveVersionMetadata(package.Version) + "'";

            var segments = new List <ODataPathSegment>
            {
                new EntitySetPathSegment("Packages"),
                new KeyValuePathSegment(keyValue)
            };

            return(segments);
        }
 private bool ArePackagesEqual(FeedPackageDetails feedPackage, ODataPackage oDataPackage)
 {
     return
         (feedPackage.PackageId == oDataPackage.Id &&
          feedPackage.PackageVersion == oDataPackage.Version &&
          feedPackage.ContentUri.ToString() == $"{_baseUri}/package/{oDataPackage.Id}/{NuGetVersion.Parse(oDataPackage.Version).ToNormalizedString()}" &&
          feedPackage.CreatedDate.Ticks == oDataPackage.Created.Ticks &&
          feedPackage.LastEditedDate.Ticks == oDataPackage.LastEdited.Value.Ticks &&
          feedPackage.PublishedDate.Ticks == oDataPackage.Published.Ticks &&
          feedPackage.LicenseNames == oDataPackage.LicenseNames &&
          feedPackage.LicenseReportUrl == oDataPackage.LicenseReportUrl);
 }
示例#14
0
        public void EqualsIgnoresOtherProperties()
        {
            var a1 = new ODataPackage()
            {
                Id = "a", Version = "1.0", Description = "ignore me"
            };
            var a2 = new ODataPackage()
            {
                Id = "a", Version = "1.0", Description = "ignore me and me too"
            };

            Assert.Equal(a1, a2);
        }
示例#15
0
        public void DifferentVersionNotEqual()
        {
            var a1 = new ODataPackage()
            {
                Id = "a", Version = "1.0"
            };
            var a2 = new ODataPackage()
            {
                Id = "a", Version = "2.0"
            };

            Assert.NotEqual(a1, a2);
        }
示例#16
0
        public void PackageEquals()
        {
            var a1 = new ODataPackage()
            {
                Id = "a", Version = "1.0"
            };
            var a2 = new ODataPackage()
            {
                Id = "a", Version = "1.0"
            };

            Assert.Equal(a1, a2);
        }
示例#17
0
        public void SerializesMinimalPackage()
        {
            var pkg = new ODataPackage()
            {
                Id      = "Minimal",
                Version = "1.0.0"
            };

            serializer.Serialize(outputStream, pkg, serviceUrl, resourceUrl, packageContentUrl);
            var feed  = XmlFeedHelper.ParsePage(readDocument());
            var entry = Assert.Single(feed);

            Assert.Equal("Minimal", entry.Id);
            Assert.Equal(NuGetVersion.Parse("1.0.0"), entry.Version);
        }
示例#18
0
        public static string GetPackageDownloadUrl(ODataPackage package)
        {
            var routesValues = new RouteValueDictionary {
                { "packageId", package.Id },
                { "version", package.Version }
            };

            var context = HttpContext.Current;

            var route = RouteTable.Routes["DownloadPackage"];

            VirtualPathData vpd = route == null ? null : route.GetVirtualPath(context.Request.RequestContext, routesValues);

            var applicationPath = Helpers.EnsureTrailingSlash(context.Request.ApplicationPath);

            return(applicationPath + (vpd?.VirtualPath ?? ""));
        }
示例#19
0
        internal static ODataEntry MapPackageToEntry(string baseAddress, ODataPackage package)
        {
            var entryId = "Packages(Id='" + package.Id + "',Version='" + package.Version + "')";

            var oDataEntry = new ODataEntry()
            {
                EditLink      = new Uri(baseAddress + entryId, UriKind.Absolute),
                Id            = baseAddress + entryId,
                TypeName      = "Package",
                MediaResource = new ODataStreamReferenceValue()
                {
                    ContentType = "application/zip",
                    ReadLink    = new Uri(baseAddress + "package/" + package.Id + "/" + package.Version),
                },
                Properties = GetProperties(package)
            };

            return(oDataEntry);
        }
示例#20
0
        public void Serialize(Stream outputStream, ODataPackage package, string serviceBaseUrl, string resourceIdUrl, string packageContentUrl)
        {
            var doc = new XElement(XmlElements.entry,
                                   new XAttribute(XmlElements.baze, XNamespace.Get(serviceBaseUrl)),
                                   new XAttribute(XmlElements.m, XmlNamespaces.m),
                                   new XAttribute(XmlElements.d, XmlNamespaces.d),
                                   new XAttribute(XmlElements.georss, XmlNamespaces.georss),
                                   new XAttribute(XmlElements.gml, XmlNamespaces.gml),
                                   new XElement(XmlElements.id, resourceIdUrl),
                                   new XElement(XmlElements.title, package.Title),
                                   new XElement(XmlElements.author, new XElement(XmlElements.name, package.Authors)),
                                   new XElement(
                                       XmlElements.content,
                                       new XAttribute("type", "application/zip"),
                                       new XAttribute("src", packageContentUrl)
                                       ),
                                   GetProperties(package)
                                   );
            var writer = XmlWriter.Create(outputStream);

            doc.WriteTo(writer);
            writer.Flush();
        }
示例#21
0
 // TODO accessor to nupkg, and anything else that web service may need
 public HostedPackage(ODataPackage packageInfo)
 {
     _packageInfo = packageInfo;
 }
示例#22
0
        private string BuildId(ODataPackage package, EntityInstanceContext context)
        {
            var segments = GetPackagePathSegments(package);

            return(context.Url.CreateODataLink(segments));
        }
        public void SetsNormalizedVersionFromDataServicePackage()
        {
            var package = new ODataPackage(new DataServicePackage { Id = "a", Version = "1.0.0.0" });

            Assert.That(package.NormalizedVersion, Is.EqualTo("1.0.0"));
        }
示例#24
0
 public PackageWithUrls(ODataPackage pkg, string resourceIdUrl, string packageContentUrl)
 {
     this.pkg               = pkg;
     this.resourceIdUrl     = resourceIdUrl;
     this.packageContentUrl = packageContentUrl;
 }