Esempio n. 1
0
        public async Task DeleteBookSuccess()
        {
            //Arrange
            var book = new Book {
                Id = 1, Title = "Testowy Title"
            };

            var fileServiceMock = new Mock <IBookService>();

            fileServiceMock.Setup(m => m.DeleteBookAsync(It.IsAny <string>(), It.IsAny <int>()))
            .Returns(Task.FromResult(book));
            var storageMock    = new Mock <IStorageService>();
            var fileController = new BookController(_mapper, fileServiceMock.Object, _logger, storageMock.Object);

            //Act
            IActionResult actionResult = await fileController.DeleteBook("ID1", 1);

            //Assert
            actionResult.ShouldNotBeNull();

            OkObjectResult result = actionResult as OkObjectResult;

            result.ShouldNotBeNull();
            result.StatusCode.ShouldEqual(200);

            BookDeleteDto resultValue = result.Value as BookDeleteDto;

            ;
            resultValue.ShouldNotBeNull();
            resultValue.Id.ShouldEqual(1);
        }
Esempio n. 2
0
        public async Task BookUnShelve(BookDeleteDto dto)
        {
            var wxUser = await _wxUserRepository.GetAll().FirstOrDefaultAsync(c => c.LoginStatus == dto.LoginStatus);

            var book = await _wxBookRepository.FirstOrDefaultAsync(c => c.UserWxId == wxUser.OpenId && c.Id == dto.Id);

            if (book != null)
            {
                Logger.Warn($"删除的书籍信息:{book.Isbn},{book.Name},{book.Id},{book.UserWxId}");
                await _wxBookRepository.DeleteAsync(book);
            }
        }
Esempio n. 3
0
        public async Task ModifyName(BookDeleteDto dto)
        {
            using (var client = new HttpClient())
            {
                var wxbook = await _wxBookRepository.FirstOrDefaultAsync(c => c.Id == dto.Id);

                var book = await _bookRepository.GetAll().FirstOrDefaultAsync(c => c.Isbn == wxbook.Isbn);

                var name = await GetTitleFromAmazon(client, book.Isbn);

                book.Name = name;

                Logger.Warn($"{book.Isbn}--从亚马逊获取到的名称:{name}");

                await _bookRepository.UpdateAsync(book);
            }
        }