예제 #1
0
        public async Task <IActionResult> AddBookBorrow([FromBody] BookBorrowDto borrow)
        {
            RollbarLocator.RollbarInstance.Error(new Exception("Błąd z Rollbar"));
            var res = await _bookBorrowRepository.AddBookBorrow(borrow);

            return(CreatedAtRoute(nameof(AddBookBorrow), res));
        }
예제 #2
0
        public async Task <IActionResult> AddBookBorrow([FromBody] BookBorrowDto borrow)
        {
            RollbarLocator.RollbarInstance.Error(new Exception("Błąd z Rollbar add bookborrow"));
            _logger.LogError("Wystąpił błąd przy dodaniu bookborrowsa");
            var res = await _bookBorrowRepository.AddBookBorrow(borrow);

            return(CreatedAtRoute(nameof(AddBookBorrow), res));
        }
        public async Task <BookBorrow> AddBookBorrow(BookBorrowDto borrow)
        {
            var res = await _context.BookBorrow.AddAsync(new BookBorrow
            {
                IdUser     = borrow.IdUser,
                IdBook     = borrow.IdBook,
                BorrowDate = DateTime.Now,
                Comments   = borrow.Comment
            });

            await _context.SaveChangesAsync();

            return(res.Entity);
        }
예제 #4
0
        public async Task PostBookBorrow_201Created()
        {
            var newBookBorrow = new BookBorrowDto
            {
                IdBook  = 2,
                IdUser  = 1,
                Comment = "Wypozyczenie ksiazeczki"
            };

            string payload      = JsonConvert.SerializeObject(newBookBorrow);
            var    content      = new StringContent(payload, Encoding.UTF8, "application/json");
            var    httpResponse = await _client.PostAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows", content);

            var responseContent = await httpResponse.Content.ReadAsStringAsync();

            var addedBookBorrow = JsonConvert.DeserializeObject <BookBorrow>(responseContent);

            Assert.True(newBookBorrow.IdBook == addedBookBorrow.IdBook);
            Assert.True(addedBookBorrow.IdUser == 1);
            Assert.True(addedBookBorrow.IdBookBorrow == 2);
        }
예제 #5
0
        public async Task PostBookBorrows_200Ok()
        {
            var bookBorrow = new BookBorrowDto
            {
                IdBook  = 1,
                IdUser  = 1,
                Comment = "comment here"
            };
            string json        = JsonConvert.SerializeObject(bookBorrow);
            var    buffer      = System.Text.Encoding.UTF8.GetBytes(json);
            var    byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var httpResponse = await _client.PostAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/", byteContent);

            httpResponse.EnsureSuccessStatusCode();
            var content = await httpResponse.Content.ReadAsStringAsync();

            var bookBorrowl = JsonConvert.DeserializeObject <IEnumerable <BookBorrow> >(content);

            Assert.True(bookBorrowl.ElementAt(0).IdBookBorrow == 1);
        }
예제 #6
0
        public async Task AddBookBorrow_201Created()
        {
            var newBook = new BookBorrowDto
            {
                IdUser  = 1,
                IdBook  = 1,
                Comment = "sample text"
            };

            var serialized = JsonConvert.SerializeObject(newBook);
            var content    = new StringContent(serialized, Encoding.UTF8, "application/json");


            var httpResponse = await _client.PostAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows", content);

            httpResponse.EnsureSuccessStatusCode();
            var result = await httpResponse.Content.ReadAsStringAsync();

            var response = JsonConvert.DeserializeObject <BookBorrow>(result);

            Assert.True(response.IdUser == 1);
            Assert.True(response.IdBook == 1);
        }
        public async Task <IActionResult> AddBookBorrow([FromBody] BookBorrowDto borrow)
        {
            var res = await _bookBorrowRepository.AddBookBorrow(borrow);

            return(CreatedAtRoute(nameof(AddBookBorrow), res));
        }