Ejemplo n.º 1
0
        public void should_copy_book()
        {
            FakeBook book1 = new FakeBook();
            var      book  = new Book(book1);

            Assert.True(
                new object[] {
                book1.Author,
                book1.Description,
                book1.Image,
                book1.ISBN10,
                book1.Pages,
                book1.Price,
                book1.Rating,
                book1.Title,
                book1.Votes
            }.SequenceEqual(
                    new object[] {
                book.Author,
                book.Description,
                book.Image,
                book.ISBN10,
                book.Pages,
                book.Price,
                book.Rating,
                book.Title,
                book.Votes
            })
                );
        }
Ejemplo n.º 2
0
        public async Task CanGetDashboardContents()
        {
            // The endpoint or route of the controller action.
            HttpResponseMessage httpResponse;
            FakeBook            value = new FakeBook();

            httpResponse = await _client.Value.PostAsJsonAsync("/api/books", value);

            await Log(httpResponse);

            httpResponse.EnsureSuccessStatusCode();

            await _client.Value.PostAsJsonAsync <string>(
                string.Format("/api/dashboard?item={0}&quantity={1}", value.Id, 5), null
                );

            httpResponse.EnsureSuccessStatusCode();

            await Log(httpResponse);

            httpResponse = await _client.Value.GetAsync("/api/dashboard");

            // Must be successful.
            httpResponse.EnsureSuccessStatusCode();

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

            var books = JsonConvert.DeserializeObject <IEnumerable <Book> >(stringResponse);

            Assert.NotNull(books);
        }
Ejemplo n.º 3
0
        public async Task CanDeleteBook()
        {
            // The endpoint or route of the controller action.
            FakeBook value = new FakeBook();
            await _client.Value.PostAsJsonAsync("/api/books", value);

            HttpResponseMessage deleteResponse = await _client.Value.DeleteAsync("/api/books/" + value.Id.ToString());

            await Log(deleteResponse);

            deleteResponse.EnsureSuccessStatusCode();
        }
Ejemplo n.º 4
0
        public void BookRepositoryDeleteTest()
        {
            var bookToRemove = FakeBook.First();

            _mockSet.Remove(bookToRemove).Returns(callInfo =>
            {
                FakeBook.Remove(bookToRemove);
                return(bookToRemove);
            }
                                                  );

            _repository.Delete(bookToRemove);
            var result = FakeBook.Count;

            Assert.AreEqual(1, result);
        }
Ejemplo n.º 5
0
        public void BookRepositoryInsertTest()
        {
            var bookToAdd = new Book()
            {
                Id    = 3,
                Title = "The Hobbit"
            };

            _mockSet.Add(bookToAdd).Returns(callInfo =>
            {
                FakeBook.Add(bookToAdd);
                return(bookToAdd);
            }
                                            );

            _repository.Insert(bookToAdd);
            var result = FakeBook.Count;

            Assert.AreEqual(3, result);
        }
Ejemplo n.º 6
0
        public void BookRepositoryGetByIdTest()
        {
            _mockSet.Find(Arg.Any <int>()).Returns(
                callInfo =>
            {
                var m       = callInfo.Args().ToList();
                Int32?value = 0;
                foreach (var n in m)
                {
                    var k = n as object[];
                    var i = k[0];
                    value = i as Nullable <Int32>;
                }


                return(FakeBook.FirstOrDefault(x => x.Id == value));
            });

            var result = _repository.GetById(1);

            Assert.AreEqual(1, (result as Book).Id);
        }