public void TestSaveItem()
        {
            var context = new Mock <IContext>();

            context.Setup(c => c.Environment).Returns("LOCAL");

            var db     = new ReviewTable(_dbClient, context.Object);
            var review = new Review
            {
                Id       = Guid.NewGuid(),
                Category = Category.Books,
                Author   = "Some guy on the internet",
                Text     = "The first of William Gibson\'s usually futuristic novels to be set in the present, Pattern Recognition is a masterful snapshot of modern consumer culture and hipster esoterica. Set in London, Tokyo, and Moscow, Pattern Recognition takes the reader on a tour of a global village inhabited by power-hungry marketeers, industrial saboteurs, high-end hackers, Russian mob bosses, Internet fan-boys, techno archeologists, washed-out spies, cultural documentarians, and our heroine Cayce Pollard--a soothsaying \"cool hunter\" with an allergy to brand names.",
                Book     = new Book()
                {
                    Author = "William Gibson",
                    Title  = "Pattern Recognition",
                    Genre  = "Science-Fiction",
                    Url    = "http://amazon.com",
                },
                Tags = new List <string>()
                {
                    "Science-Ficton", "Branding"
                }
            };

            db.SaveReview(review);
        }
示例#2
0
        public HttpResponseMessage Post(string category, Review review)
        {
            // check if the category exists,
            // use that category, even if the category in the review is a different one? we overwrite it? NOPE, return a error: you cannot post app reviews to the books endpoint etc...
            // check if an id is present,
            // if the id exists we refuse the creation? Nope, it's a post, we create a new review with a new Id

            var theCategory = ParseCategory(category);

            if (theCategory.IsSpecified())
            {
                // we do want to accept unspecified categories of course
                if (review.Category != theCategory && review.Category.IsSpecified())
                {
                    return(CreateValidationErrorResponse());
                }
                review.Category = theCategory;
                review.Id       = Guid.NewGuid();
                _reviewTable.SaveReview(review);
                return(Request.CreateResponse(HttpStatusCode.OK, review));
            }
            return(new HttpResponseMessage(HttpStatusCode.NotFound));
        }