public void GetBookByIsbnAsync_Test_NotFound() { // arrange var fakeIsbnApiClient = A.Fake <IIsbnApiClient>(); var fakeAuthorApiClient = A.Fake <IAuthorApiClient>(); var fakeIsbnHttpResponse = A.Fake <HttpResponseWrapper>(); A.CallTo(() => fakeIsbnHttpResponse.StatusCode).Returns(System.Net.HttpStatusCode.NotFound); A.CallTo(() => fakeIsbnApiClient.GetResponse("0123456789")).Returns(fakeIsbnHttpResponse); BookApiService service = new BookApiService(fakeIsbnApiClient, fakeAuthorApiClient); // act/assert Assert.ThrowsAsync <BookNotFoundException>(() => service.GetBookByIsbnAsync("0123456789")); }
public HomeController(IBookService bookService, BookApiService bookApiService) { _bookService = bookService; _bookApiService = bookApiService; }
public async Task GetBookByIsbnAsync_Test_Success() { // arrange string bookJson = "{\r\n" + "\"publishers\": [\r\n" + " \"some_publisher\"\r\n" + " ],\r\n" + " \"source_records\": [\r\n" + " \"amazon:0123456789\"," + "\r\n" + " \"bwb:0123456789012\"" + "\r\n" + "],\r\n" + "\"publish_places\": [" + "\r\n" + " \"somewhere\"\r\n" + "],\r\n" + "\"title\": \"Test book: this book is a test\"," + "\r\n" + "\"number_of_pages\": 100," + "\r\n" + "\"covers\": [" + "\r\n" + " 8403152" + "\r\n" + "],\r\n" + "\"isbn_13\": [" + "\r\n" + " \"0123456789012\"" + "\r\n" + "],\r\n" + "\"isbn_10\": [" + "\r\n" + " \"0-123-45678-9\"" + "\r\n" + "],\r\n" + "\"publish_date\": \"Oct 28, 2017\"," + "\r\n" + "\"key\": \"/books/OL00000000M\"," + "\r\n" + "\"authors\": [" + "\r\n" + " {\r\n" + " \"key\": \"/authors/OL0000001A\"" + "\r\n" + " },\r\n" + " {\r\n" + " \"key\": \"/authors/OL0000002A\"" + "\r\n" + " }\r\n" + "],\r\n" + "\"works\": [" + "\r\n" + " {\r\n" + " \"key\": \"/works/OL00000000W\"" + "\r\n" + " }\r\n" + "],\r\n" + "\"type\": {" + "\r\n" + " \"key\": \"/type/edition\"" + "\r\n" + "}," + "\r\n" + "\"lc_classifications\": [" + "\r\n" + " \"QA76.00.C000\"" + "\r\n" + "],\r\n" + "\"latest_revision\": 3," + "\r\n" + "\"revision\": 3," + "\r\n" + "\"created\": {" + "\r\n" + " \"type\": \"/type/datetime\"," + "\r\n" + " \"value\": \"2019-04-05T03:55:17.228685\"" + "\r\n" + "}," + "\r\n" + "\"last_modified\": {" + "\r\n" + " \"type\": \"/type/datetime\"," + "\r\n" + " \"value\": \"2021-10-03T19:54:17.544188\"" + "\r\n" + "}\r\n" + "\r\n" + "}"; var fakeIsbnApiClient = A.Fake <IIsbnApiClient>(); var fakeIsbnHttpResponse = A.Fake <HttpResponseWrapper>(); A.CallTo(() => fakeIsbnHttpResponse.StatusCode).Returns(System.Net.HttpStatusCode.OK); A.CallTo(() => fakeIsbnHttpResponse.ReadAsStringAsync()).Returns(bookJson); A.CallTo(() => fakeIsbnApiClient.GetResponse("0123456789")).Returns(fakeIsbnHttpResponse); string author1Json = "{\r\n" + "\"name\": \"John Smith\"," + "\r\n" + "\"last_modified\": {" + "\r\n" + " \"type\": \"/type/datetime\"," + "\r\n" + " \"value\": \"2008-04-29 13:35:46.87638\"" + "\r\n" + "}," + "\r\n" + "\"key\": \"/authors/OL0000001A\"," + "\r\n" + "\"type\": {" + "\r\n" + " \"key\": \"/type/author\"" + "\r\n" + "}," + "\r\n" + "\"id\": 00000001," + "\r\n" + "\"revision\": 1" + "\r\n" + "}"; string author2Json = "{\r\n" + "\"name\": \"Jane Doe\"," + "\r\n" + "\"last_modified\": {" + "\r\n" + " \"type\": \"/type/datetime\"," + "\r\n" + " \"value\": \"2008-04-29 13:35:46.87638\"" + "\r\n" + "}," + "\r\n" + "\"key\": \"/authors/OL0000002A\"," + "\r\n" + "\"type\": {" + "\r\n" + " \"key\": \"/type/author\"" + "\r\n" + "}," + "\r\n" + "\"id\": 00000002," + "\r\n" + "\"revision\": 1" + "\r\n" + "}"; var fakeAuthorApiClient = A.Fake <IAuthorApiClient>(); var fakeAuthor1HttpResponse = A.Fake <HttpResponseWrapper>(); A.CallTo(() => fakeAuthor1HttpResponse.ReadAsStringAsync()).Returns(author1Json); A.CallTo(() => fakeAuthor1HttpResponse.StatusCode).Returns(System.Net.HttpStatusCode.OK); A.CallTo(() => fakeAuthorApiClient.GetResponse("/authors/OL0000001A")).Returns(fakeAuthor1HttpResponse); var fakeAuthor2HttpResponse = A.Fake <HttpResponseWrapper>(); A.CallTo(() => fakeAuthor2HttpResponse.ReadAsStringAsync()).Returns(author2Json); A.CallTo(() => fakeAuthor2HttpResponse.StatusCode).Returns(System.Net.HttpStatusCode.OK); A.CallTo(() => fakeAuthorApiClient.GetResponse("/authors/OL0000002A")).Returns(fakeAuthor2HttpResponse); BookApiService service = new BookApiService(fakeIsbnApiClient, fakeAuthorApiClient); // act Book result = await service.GetBookByIsbnAsync("0123456789"); // assert // title Assert.AreEqual("Test book: this book is a test", result.Title); // ISBNs Assert.AreEqual("0123456789", result.Isbn); Assert.AreEqual("0123456789012", result.Isbn13); // number of pages Assert.AreEqual(100, result.Pages); // publication details Assert.AreEqual("some_publisher", result.Publisher.Name); Assert.AreEqual("Oct 28, 2017", result.DatePublished); Assert.AreEqual("somewhere", result.PlaceOfPublication); // authors Assert.IsTrue(result.Authors.Count == 2); Assert.IsTrue(result.Authors.Any(a => a.FirstName.Equals("John") && a.LastName.Equals("Smith"))); Assert.IsTrue(result.Authors.Any(a => a.FirstName.Equals("Jane") && a.LastName.Equals("Doe"))); }
public TicketController(BookApiService bookApiService, IMapper mapper) { _mapper = mapper; _bookApiService = bookApiService; }
public BookController(BookApiService bookApiService) { _bookApiService = bookApiService; }
public BookApiController(BookApiService bookService, /*VideoService videoService,*/ PlayApiService playService, UserManager <ApplicationUser> userManager) : base(userManager) { //m_VideoService = videoService ?? throw new ArgumentNullException(nameof(videoService)); m_BookService = bookService ?? throw new ArgumentNullException(nameof(bookService)); m_PlayService = playService ?? throw new ArgumentNullException(nameof(playService)); }
private static async Task Main() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); var bookApiService = new BookApiService(new HttpClient(), configuration); TypeTip(); var command = Console.ReadLine().Trim(); while (command != "finish") { if (command.StartsWith("-get")) { var parameters = command.Split(' '); int bookId; if (int.TryParse(parameters[1], out bookId)) { Console.WriteLine(JObject.Parse(await bookApiService.GetBookByIdInStringFormat(bookId))); } else { TypeTip(); } } else if (command.StartsWith("-title")) { var parameters = command.Split(' '); if (parameters.Length == 4) { Console.WriteLine(JsonConvert.SerializeObject(await bookApiService.CreateBookInStringFormat(new Book { Title = parameters[1], Author = parameters[3] }), Formatting.Indented)); } else { TypeTip(); } } else if (command.StartsWith("-edit")) { var parameters = command.Split(' '); int bookId; if (parameters.Length == 6 && int.TryParse(parameters[1], out bookId)) { var response = await bookApiService.GetBookById(bookId); if (response.Errors == null || response.Errors.Count == 0) { response.Content.Title = parameters[3]; response.Content.Author = parameters[4]; var result = await bookApiService.EditBook(response.Content); Console.WriteLine(JsonConvert.SerializeObject(result.Content, Formatting.Indented)); } Console.WriteLine("Book with this id was not found"); } else { TypeTip(); } } else if (command.StartsWith("-delete")) { var parameters = command.Split(' '); int bookId; if (int.TryParse(parameters[1], out bookId)) { string response = await bookApiService.DeleteBookByIdInStringFormat(bookId); if (response == "true") { Console.WriteLine($"Book was deleted"); } else { Console.WriteLine(JArray.Parse(response)); } } else { TypeTip(); } } else { Console.WriteLine(JsonConvert.SerializeObject(await bookApiService.GetBooksInStringFormat(), Formatting.Indented)); } command = Console.ReadLine().Trim(); } Console.ReadLine(); }