Пример #1
0
 public void Should_create_a_repository_with_default_constructor()
 {
     //Arrange
     //Act
     var repo = new BookPersistence();
     //Assert
     Assert.IsNotNull(repo);
 }
Пример #2
0
        // GET: api/Book/5
        /// <summary>
        ///  Retrieve the book with a specified item_id
        /// </summary>
        /// <param name="item_id">ID generated by database upon its creation</param>
        public Book Get(int item_id)
        {
            BookPersistence bookp = new BookPersistence();

            bookp.addCallField("item_id", item_id, SqlDbType.Int, 4);

            return((Book)bookp.Get());
        }
Пример #3
0
        // GET: api/Book
        /// <summary>
        ///  Retrieve a list of book items that match your criteria (All fields are optional. If no fields are given all items will be retrieved)
        /// </summary>
        /// <param name="isbn10">A unique code that specifies a book</param>
        /// <param name="isbn13">Another unique code that specifies a book</param>
        /// <param name="category">sci-fi, fantasy, non-fiction, etc.</param>
        /// <param name="publication_year">the year a book was published</param>
        public ArrayList Get(string isbn10 = null, string isbn13 = null, string category = null, int?publication_year = null)
        {
            BookPersistence bookp = new BookPersistence();

            bookp.addCallField("isbn_10", isbn10, SqlDbType.VarChar, 50);
            bookp.addCallField("isbn_13", isbn13, SqlDbType.VarChar, 50);
            bookp.addCallField("category", category, SqlDbType.VarChar, 50);
            bookp.addCallField("publication_year", publication_year, SqlDbType.Int, 4);

            return(bookp.GetAll());
        }
Пример #4
0
 public void Should_properly_dispose_of_sessions()
 {
     //Arrange
     ISession s;
     //Act
     using (var repo = new BookPersistence())
     {
         s = repo.CurrentSession;
     }
     //Assert
     Assert.IsFalse(s.IsConnected);
 }
Пример #5
0
        // POST: api/Book
        /// <summary>
        ///  Create a new book item
        /// </summary>
        public HttpResponseMessage Post([FromBody] Book value)
        {
            BookPersistence bookp = new BookPersistence();
            int             id    = bookp.Save(value, "item_id");

            if (id != -1)
            {
                value.item_id = id;
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);
                response.Headers.Location = new Uri(Request.RequestUri, String.Format("book?item_id={0}", id));
                return(response);
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
Пример #6
0
        // DELETE: api/Book/5
        /// <summary>
        ///  Delete the book with a specified item_id
        /// </summary>
        /// <param name="item_id">ID generated by database upon its creation</param>
        public HttpResponseMessage Delete(int item_id)
        {
            BookPersistence bookp = new BookPersistence();

            bookp.addCallField("item_id", item_id, SqlDbType.Int, 4);

            HttpResponseMessage ret;

            if (bookp.Delete())
            {
                ret = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                ret = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(ret);
        }
Пример #7
0
        // PUT: api/Book/5
        /// <summary>
        ///  Update an existing book with the specified item_id
        /// </summary>
        /// <param name="item_id">ID generated by database upon its creation</param>
        public HttpResponseMessage Put(int item_id, [FromBody] Book value)
        {
            BookPersistence bookp = new BookPersistence();

            bookp.addCallField("item_id", item_id, SqlDbType.Int, 4);

            bool recordExisted = bookp.Update(value);

            HttpResponseMessage response;

            if (recordExisted)
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(response);
        }
Пример #8
0
 public static void TestSetup(TestContext context)
 {
     Utilities.CreateSchema();
     _repo = new BookPersistence();
     _repo.Create(new Book { Title = "The Hobbit", Condition = 1, BookGuid = new Guid("11111111-1111-1111-1111-111111111111") });
     _repo.Create(new Book { Title = "Fellowship of the Ring", Condition = 2 });
     _repo.Create(new Book { Title = "The Two Towers", Condition = 1, BookGuid = new Guid("22222222-2222-2222-2222-222222222222") });
     _repo.Create(new Book { Title = "Return of the King", Condition = null, BookGuid = new Guid("33333333-3333-3333-3333-333333333333") });
 }