public void DownloadCountOnPublishedPackageShouldBeMappedToAggregateDownloadCountWhenItExists() { PackageDataAggregate existingAggregate = new PackageDataAggregate { PackageId = Guid.NewGuid().ToString(), DownloadCount = 45 }; MockedPackageDataAggregateRepository.SetupGet(pdar => pdar.Collection).Returns(new[] { existingAggregate }.AsQueryable()); PublishedPackage publishedPackage = Mapper.Map<Package, PublishedPackage>(new Package { Id = existingAggregate.PackageId }); Assert.AreEqual(existingAggregate.DownloadCount, publishedPackage.DownloadCount, "DownloadCount should have been mapped to aggregate rating."); }
public void ShouldNotCreateNewAggregateWhenOneWithGivenPackageIdExists() { var packageDataAggregate = new PackageDataAggregate { PackageId = Guid.NewGuid().ToString() }; MockedPackageDataAggregateRepository.SetupGet(pdar => pdar.Collection).Returns(new[] { packageDataAggregate }.AsQueryable()); Updater.IncrementDownloadForPackage(packageDataAggregate.PackageId); MockedPackageDataAggregateRepository.Verify(pdar => pdar.Create(It.IsAny<PackageDataAggregate>()), Times.Never(), "Create should not have been invoked."); }
public void ShouldIncrementPackageDownloadCountByOne() { const int originalDownloadCount = 5; var packageDataAggregate = new PackageDataAggregate { PackageId = Guid.NewGuid().ToString(), DownloadCount = originalDownloadCount}; MockedPackageDataAggregateRepository.SetupGet(pdar => pdar.Collection).Returns(new[] { packageDataAggregate }.AsQueryable()); Updater.IncrementDownloadForPackage(packageDataAggregate.PackageId); Assert.AreEqual(originalDownloadCount + 1, packageDataAggregate.DownloadCount, "Download count was not incremented."); }
public void ShouldUpdateDownloadCountOfPackageDataAggregate() { const string packageId = "PackageId"; const int expectedDownloadCount = 8; PackageDataAggregate aggregateToUpdate = new PackageDataAggregate { PackageId = packageId, DownloadCount = 45 }; MockedPackageRepository.SetupGet(pr => pr.Collection).Returns(new[] { GetPackage(packageId), GetPackage(packageId) }.AsQueryable()); MockedPackageDataAggregateRepository.SetupGet(pdar => pdar.Collection).Returns(new[] {aggregateToUpdate}.AsQueryable()); Updater.RecalculateTotalDownloadCount(packageId); Assert.AreEqual(expectedDownloadCount, aggregateToUpdate.DownloadCount, "DownloadCount on PackageDataAggregate was not updated."); }
public void ShouldUpdateAggregate() { string packageId = Guid.NewGuid().ToString(); var aggregateToUpdate = new PackageDataAggregate {PackageId = packageId}; MockedPackageDataAggregateRepository.SetupGet(pdar => pdar.Collection).Returns(new[] { aggregateToUpdate }.AsQueryable()); Updater.IncrementDownloadForPackage(packageId); MockedPackageDataAggregateRepository.Verify(pdar => pdar.Update(aggregateToUpdate), Times.Once(), "Aggregate was not updated."); }
public void ShouldUpdateDownloadCountOfMatchingPublishedPackage() { PublishedPackage publishedPackageToUpdate = new PublishedPackage { Id = Guid.NewGuid().ToString(), DownloadCount = 38}; IQueryable<PublishedPackage> publishedPackages = new[] { publishedPackageToUpdate, new PublishedPackage()}.AsQueryable(); var aggregate = new PackageDataAggregate { PackageId = publishedPackageToUpdate.Id, DownloadCount = 5 }; int expectedDownloadCount = aggregate.DownloadCount + 1; MockedPackageDataAggregateRepository.SetupGet(pdar => pdar.Collection).Returns(new[] { aggregate }.AsQueryable()); MockedPublishedPackageRepository.SetupGet(ppr => ppr.Collection).Returns(publishedPackages); Updater.IncrementDownloadForPackage(publishedPackageToUpdate.Id); Assert.AreEqual(expectedDownloadCount, publishedPackageToUpdate.DownloadCount, "DownloadCount for PublishedPackage was not updated."); }