public async Task Can_Get_Author_By_Id() { // arrange var context = GetService <AppDbContext>(); var author = AuthorFactory.Get(); context.Authors.Add(author); context.SaveChanges(); var content = new { operations = new[] { new Dictionary <string, object> { { "op", "get" }, { "ref", new { type = "authors", id = author.StringId } } } } }; // act var result = await PatchAsync <OperationsDocument>("api/bulk", content); // assert Assert.NotNull(result.response); Assert.NotNull(result.data); Assert.Equal(HttpStatusCode.OK, result.response.StatusCode); Assert.Equal(1, result.data.Operations.Count); Assert.Equal(author.Id.ToString(), result.data.Operations.Single().DataObject.Id); }
public void SetUp() { _restClient = new RestClient(); _restClient.BaseUrl = new Uri("https://libraryjuly.azurewebsites.net"); _author = AuthorFactory.CreateAuthorWithId(); _book = BookFactory.CreateBook(); _postNewAuthor = PostNewAuthor(_author, _restClient); _postedAuthor = Author.FromJson(_postNewAuthor.Content); _postNewBook = PostBookForAuthor(_postedAuthor, _book, _restClient); _postedBook = Book.FromJson(_postNewBook.Content); }
public IActionResult NewAuthor(Author author) { if (ModelState.IsValid) { AuthorFactory.NewAuthor(author); return(RedirectToAction("Index")); } else { return(View("Index")); } }
public string CreateAuthor() { var newAuthor = AuthorFactory.CreateAuthor(); var request = new RestRequest($"/api/authors"); request.AddJsonBody(newAuthor.ToJson(), "application/json"); var response = _httpClient.Post(request); var createdAuthor = Author.FromJson(response.Content); return(createdAuthor.Id.ToString()); }
public async Task PostAuthor() { //Arange var author = AuthorFactory.CreateAuthor(); var requestAuthorJSON = author.ToJson(); //Act var requestBody = new StringContent(requestAuthorJSON, Encoding.UTF8, "application/json"); var responsePost = await Client.PostAsync("/api/authors", requestBody); var statusCode = responsePost.StatusCode; //Assert Assert.AreEqual(HttpStatusCode.Created, statusCode); }
//loading books from data.csv file private List <Book> LoadBooks() { BookFactory bookFactory = new BookFactory(); AuthorFactory authorFactory = new AuthorFactory(); List <Book> books = new List <Book>(); string[] dataLines = File.ReadAllLines("../../data.csv"); foreach (var line in dataLines) { Book bookToAdd = ParseBook(line); books.Add(bookToAdd); } return(books); }