コード例 #1
0
        public void Create_WhenContextIsNull_Throws()
        {
            const JObject context = null;

            var exception = Assert.Throws <ArgumentNullException>(() => CatalogCommitItem.Create(context, _commitItem));

            Assert.Equal("context", exception.ParamName);
        }
コード例 #2
0
        public void CompareTo_WhenObjIsNotCatalogCommit_Throws()
        {
            var commitItem = CatalogCommitItem.Create(_context, _commitItem);

            var exception = Assert.Throws <ArgumentException>(() => commitItem.CompareTo(new object()));

            Assert.Equal("obj", exception.ParamName);
        }
コード例 #3
0
        private static CatalogCommitItem CreatePackage(string id, string version)
        {
            var context         = TestUtility.CreateCatalogContextJObject();
            var packageIdentity = new PackageIdentity(id, new NuGetVersion(version));
            var commitItem      = TestUtility.CreateCatalogCommitItemJObject(DateTime.UtcNow, packageIdentity);

            return(CatalogCommitItem.Create(context, commitItem));
        }
コード例 #4
0
        public void Create_WhenTypeIsEmpty_Throws()
        {
            _commitItem[CatalogConstants.TypeKeyword] = new JArray();

            var exception = Assert.Throws <ArgumentException>(() => CatalogCommitItem.Create(_context, _commitItem));

            Assert.Equal("commitItem", exception.ParamName);
            Assert.StartsWith($"The value of property '{CatalogConstants.TypeKeyword}' must be non-null and non-empty.", exception.Message);
        }
コード例 #5
0
        public static CatalogCommitItem CreateCatalogCommitItem(
            DateTime commitTimeStamp,
            PackageIdentity packageIdentity,
            string commitId = null)
        {
            var context    = CreateCatalogContextJObject();
            var commitItem = CreateCatalogCommitItemJObject(commitTimeStamp, packageIdentity, commitId);

            return(CatalogCommitItem.Create(context, commitItem));
        }
コード例 #6
0
        public void Create_WhenArgumentsAreValid_ReturnsInstance()
        {
            var commitItem = CatalogCommitItem.Create(_context, _commitItem);

            Assert.Equal($"https://nuget.test/{_packageIdentity.Id}", commitItem.Uri.AbsoluteUri);
            Assert.Equal(_now, commitItem.CommitTimeStamp.ToUniversalTime());
            Assert.True(Guid.TryParse(commitItem.CommitId, out var commitId));
            Assert.Equal(_packageIdentity, commitItem.PackageIdentity);
            Assert.Equal(CatalogConstants.NuGetPackageDetails, commitItem.Types.Single());
            Assert.Equal(Schema.DataTypes.PackageDetails.AbsoluteUri, commitItem.TypeUris.Single().AbsoluteUri);
        }
コード例 #7
0
        public void Create_WhenArgumentIsValid_ReturnsInstance()
        {
            var contextJObject    = TestUtility.CreateCatalogContextJObject();
            var commitItemJObject = TestUtility.CreateCatalogCommitItemJObject(_commitTimeStamp, _packageIdentity);
            var commitItem        = CatalogCommitItem.Create(contextJObject, commitItemJObject);

            var entry = CatalogIndexEntry.Create(commitItem);

            Assert.Equal(_uri.AbsoluteUri, entry.Uri.AbsoluteUri);
            Assert.Equal(CatalogConstants.NuGetPackageDetails, entry.Types.Single());
            Assert.Equal(commitItemJObject[CatalogConstants.CommitId].ToString(), entry.CommitId);
            Assert.Equal(_commitTimeStamp, entry.CommitTimeStamp.ToUniversalTime());
            Assert.Equal(_packageId, entry.Id);
            Assert.Equal(_packageVersion, entry.Version);
        }
コード例 #8
0
        public void CreateCommitItemBatches_WhenMultipleCommitItemsShareCommitTimeStampButNotCommitId_Throws()
        {
            var commitTimeStamp = DateTime.UtcNow;
            var context         = TestUtility.CreateCatalogContextJObject();
            var commitItem0     = CatalogCommitItem.Create(
                context,
                TestUtility.CreateCatalogCommitItemJObject(commitTimeStamp, _packageIdentitya));
            var commitItem1 = CatalogCommitItem.Create(
                context,
                TestUtility.CreateCatalogCommitItemJObject(commitTimeStamp, _packageIdentityb));
            var commitItems = new[] { commitItem0, commitItem1 };

            var exception = Assert.Throws <ArgumentException>(
                () => CatalogCommitUtilities.CreateCommitItemBatches(
                    commitItems,
                    CatalogCommitUtilities.GetPackageIdKey));

            Assert.Equal("catalogItems", exception.ParamName);
            Assert.StartsWith("Multiple commits exist with the same commit timestamp but different commit ID's:  " +
                              $"{{ CommitId = {commitItem0.CommitId}, CommitTimeStamp = {commitItem0.CommitTimeStamp.ToString("O")} }}, " +
                              $"{{ CommitId = {commitItem1.CommitId}, CommitTimeStamp = {commitItem1.CommitTimeStamp.ToString("O")} }}.",
                              exception.Message);
        }
コード例 #9
0
        public void CreateCommitItemBatches_WhenMultipleCommitItemsShareCommitTimeStampButNotCommitIdAndLaterCommitExists_DoesNotThrow()
        {
            var commitTimeStamp0 = DateTime.UtcNow;
            var commitTimeStamp1 = commitTimeStamp0.AddMinutes(1);
            var context          = TestUtility.CreateCatalogContextJObject();
            var commitItem0      = CatalogCommitItem.Create(
                context,
                TestUtility.CreateCatalogCommitItemJObject(commitTimeStamp0, _packageIdentitya));
            var commitItem1 = CatalogCommitItem.Create(
                context,
                TestUtility.CreateCatalogCommitItemJObject(commitTimeStamp0, _packageIdentityb));
            var commitItem2 = CatalogCommitItem.Create(
                context,
                TestUtility.CreateCatalogCommitItemJObject(commitTimeStamp1, _packageIdentitya));
            var commitItems = new[] { commitItem0, commitItem1, commitItem2 };

            var batches = CatalogCommitUtilities.CreateCommitItemBatches(
                commitItems,
                CatalogCommitUtilities.GetPackageIdKey);

            Assert.Collection(
                batches,
                batch =>
            {
                Assert.Equal(commitTimeStamp1, batch.CommitTimeStamp.ToUniversalTime());
                Assert.Collection(
                    batch.Items,
                    commit => Assert.True(ReferenceEquals(commit, commitItem2)));
            },
                batch =>
            {
                Assert.Equal(commitTimeStamp0, batch.CommitTimeStamp.ToUniversalTime());
                Assert.Collection(
                    batch.Items,
                    commit => Assert.True(ReferenceEquals(commit, commitItem1)));
            });
        }
コード例 #10
0
        public void Create_WhenCommitItemIsNull_Throws()
        {
            var exception = Assert.Throws <ArgumentNullException>(() => CatalogCommitItem.Create(_context, commitItem: null));

            Assert.Equal("commitItem", exception.ParamName);
        }