public async void DownloadPublicationByBookId_DownloadSuccess_NoNeedInstall() { container.Arrange <IConnectionMonitor>(connectionMonitor => connectionMonitor.PingService(null, source.Token)).IgnoreArguments().Returns(pingTaskSuccess); dlBook.DlStatus = (short)DlStatusEnum.NotDownloaded; dlBook.LastUpdatedDate = new DateTime(2015, 1, 1); dlBook.CurrentVersion = 3; container.Arrange <IPublicationAccess>(publicationService => publicationService.GetDlBookByBookId(Arg.AnyInt, null)).IgnoreArguments().Returns(dlBook); container.Arrange <INetwork>(networkService => networkService.GetNetworkType()).Returns(NetworkTypeEnum.None); container.Arrange <IDeliveryService>(deliveryService => deliveryService.DlFileDownload(dlBook, source.Token, null)).IgnoreArguments().Returns(pingTaskSuccess); container.Arrange <IDeliveryService>(deliveryService => deliveryService.DlFileStatusUpdate(null, default(CancellationToken))).IgnoreArguments().Returns(pingTaskSuccess); validateResult.Result.IsSuccess = true; container.Arrange <IDeliveryService>(deliveryService => deliveryService.DlVersionChangeHistory(null)).IgnoreArguments().Returns(validateResult); validateResult.Result.IsSuccess = true; validateResult.Result.Content = JsonConvert.SerializeObject(dlBook); container.Arrange <IDeliveryService>(deliveryService => deliveryService.DlFileDetailByDlId(null, null, 0, default(CancellationToken))).IgnoreArguments().Returns(validateResult); var dlMetadata = new DlMetadataDetails { SubCategory = "SubCategory", PracticeArea = "PracticeArea" }; var metadataResult = new Task <HttpResponse>(() => { return(new HttpResponse { IsSuccess = true, Content = JsonConvert.SerializeObject(dlMetadata) }); }); metadataResult.Start(); container.Arrange <IDeliveryService>(deliveryService => deliveryService.DlMetadata(null)).IgnoreArguments().Returns(metadataResult); var downloadResult = await container.Instance.DownloadPublicationByBookId(1, source.Token, (t, downloadSize) => { }, false); var returnPublication = downloadResult.Publication; Assert.IsTrue(returnPublication.PublicationStatus == PublicationStatusEnum.Downloaded); Assert.IsTrue(returnPublication.LastDownloadedVersion == dlBook.CurrentVersion); Assert.IsTrue(returnPublication.InstalledDate.Value.Date == DateTime.Now.Date); Assert.IsTrue(returnPublication.CurrencyDate == dlBook.LastUpdatedDate); Assert.IsTrue(returnPublication.LocalSize == dlBook.Size); Assert.IsTrue(returnPublication.SubCategory == dlMetadata.SubCategory); Assert.IsTrue(returnPublication.PracticeArea == dlMetadata.PracticeArea); Assert.IsTrue(downloadResult.DownloadStatus == DownLoadEnum.Success); }
private async Task <DlMetadataDetails> SetDlBookMetaData(int bookId, UserCredential userCredential, string deviceId) { DlMetadata dlMetaData = new DlMetadata() { Email = userCredential.Email, DeviceId = deviceId, DlId = bookId }; DlMetadataDetails dlMetaDataDetails = null; //before call this function,program has ensured network available. var result = await deliveryService.DlMetadata(dlMetaData); if (result.IsSuccess) { dlMetaDataDetails = JsonConvert.DeserializeObject <DlMetadataDetails>(result.Content); if (dlMetaDataDetails != null) { var metadata = publicationAccess.GetDlBookMetedata(bookId, userCredential); if (metadata == null)//insert metadata { BookMetadata entity = new BookMetadata { BookId = bookId, ServiceCode = userCredential.ServiceCode, Email = userCredential.Email, IncludedGuideCard = JsonConvert.SerializeObject(dlMetaDataDetails.GuideCard) }; publicationAccess.InsertMetadata(entity); } else//update metadata { metadata.IncludedGuideCard = JsonConvert.SerializeObject(dlMetaDataDetails.GuideCard); publicationAccess.Update(metadata); } } } return(dlMetaDataDetails); }