Example #1
0
        public async Task ShouldReturnSpecificBook()
        {
            // Arrange
            var book = new Book {
                Name = "Half Girlfriend", AuthorName = "Chetan Bhagat", Cost = 900, PublishedOn = DateTime.Now.AddYears(-6), WrittenIn = "English", Description = "Lorum Ipsum is dummy data"
            };

            _context.Books.Add(book);
            _context.SaveChanges();

            // Act
            var response = await _client.GetAsync($"api/book/{book.Id}/[email protected]");

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var stringResponse = await response.Content.ReadAsStringAsync();

            var receivedBook = JsonConvert.DeserializeObject <GetSpecificBookViewModel>(stringResponse);

            receivedBook.Should().NotBeNull();

            //Removing Added Book
            _context.Books.Remove(book);
            _context.SaveChanges();
        }
Example #2
0
        public async Task UserShouldGetTokenWithCorrectEmailAndPassword()
        {
            // Arrange
            var user = new User
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            _context.Users.Add(user);
            _context.SaveChanges();

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

            // Act
            var response = await _client.PostAsync("api/user/token", content);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var stringResponse = await response.Content.ReadAsStringAsync();

            var returnedUser = JsonConvert.DeserializeObject <VerifyUserModel>(stringResponse);

            returnedUser.Email.Should().Be(user.Email);
            returnedUser.Token.Should().NotBeEmpty();
            returnedUser.Token.Should().NotBeEmpty();

            // Removing Added Data
            _context.Users.Remove(user);
            _context.SaveChanges();
        }
        public async Task UserCanPurchaseBook_GetNotContent()
        {
            // Arrange
            var book = new Book {
                Name = "Half Girlfriend", AuthorName = "Chetan Bhagat", Cost = 900, PublishedOn = DateTime.Now.AddYears(-6), WrittenIn = "English", Description = "Lorum Ipsum is dummy data"
            };
            var user = new User
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            _context.Books.Add(book);
            _context.Users.Add(user);
            _context.SaveChanges();

            var content = new StringContent(JsonConvert.SerializeObject(new { BookId = book.Id }), Encoding.UTF8, "application/json");

            // Act
            var response = await _client.PostAsync($"api/PurchaseBook?{ClaimTypes.Email}={user.Email}", content);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.NoContent);

            // Removing Added Data
            _context.Users.Remove(user);
            _context.Books.Remove(book);
            _context.SaveChanges();
        }