Exemplo n.º 1
0
        public int AddAuthor(IAuthorCreateModel model, string userId)
        {
            var author = AuthorFactory.CreateAuthor(model.Name, userId);

            _authorRepo.Add(author);
            _authorRepo.SaveChanges();

            return(author.Id);
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        private Book ParseBook(string input)
        {
            string[] inputArgs     = input.Split(new char[] { ',' });
            long     isbn          = long.Parse(inputArgs[0].Trim());
            string   bookType      = inputArgs[1].Trim();
            string   bookGenre     = inputArgs[2].Trim();
            string   title         = inputArgs[3].Trim();
            string   authorName    = inputArgs[4].Trim();
            DateTime authorBday    = DateTime.ParseExact(inputArgs[5].Trim(), "yyyy/mm/dd", CultureInfo.InvariantCulture);
            int      yearPublished = int.Parse(inputArgs[6].Trim());
            int      length        = int.Parse(inputArgs[7].Trim());

            Author author = authorFactory.CreateAuthor(authorName, authorBday);
            Book   book   = bookFactory.CreateBook(isbn, bookType, bookGenre, title, author, yearPublished, length);

            return(book);
        }
Exemplo n.º 5
0
        private async Task <Guid?> GetExpectedAutorId()
        {
            var author            = AuthorFactory.CreateAuthor();
            var requestAuthorJSON = author.ToJson();

            var requestBody = new StringContent(requestAuthorJSON, Encoding.UTF8, "application/json");

            var responsePost = await Client.PostAsync("/api/authors", requestBody);

            var statusCode = responsePost.StatusCode;

            var responseAsStringPost = await responsePost.Content.ReadAsStringAsync();

            var responseAuthor = JsonConvert.DeserializeObject <Author>(responseAsStringPost);

            var expectedId = responseAuthor.Id;

            return(expectedId);
        }