Beispiel #1
0
        public void FindBook_Success_ValidObject()
        {
            // Arrange
            var srv = new OpenLibraryService();

            // Act
            var book = srv.SearchByLibraryId("OL30777581M");

            // Assert
            book.Title.Should().Be("Tödliche Absicht");
        }
Beispiel #2
0
        public void FindBook_ByIsbn_BookFound()
        {
            // Arrange
            var srv = new OpenLibraryService();

            // Act
            var book = srv.FindBook("9783442362851");

            // Assert
            book.Title.Should().Be("Tödliche Absicht");
        }
Beispiel #3
0
        public void FindId_Success_ValidId()
        {
            // Arrange
            var srv = new OpenLibraryService();

            // Act
            var result = srv.GetLiraryId("9783442362851");

            // Assert
            result.Should().Be("OL30777581M");
        }
Beispiel #4
0
        public async Task <IActionResult> Put([FromServices] OpenLibraryService openLibraryService, [FromServices] IPostService postService, [FromBody] PostModel postModel)
        {
            try
            {
                AuthUserModel authUser = (AuthUserModel)this.HttpContext.Items["authUserModel"];
                var           post     = await postService.CreatePost(authUser, postModel, openLibraryService);

                return(Ok(post));
            }
            catch (ArgumentException e) {
                return(BadRequest(new { ISBN = e.Message }));
            }
        }
Beispiel #5
0
        public void Init()
        {
            DbContextOptions <Context> options = new DbContextOptionsBuilder <Context>()
                                                 .UseInMemoryDatabase("bookish")
                                                 .Options;

            context            = new Context(options);
            commentService     = new CommentService(context, new MessageService(context));
            postService        = new PostService(context, commentService);
            openLibraryService = new OpenLibraryService(new System.Net.Http.HttpClient());
            authUser           = new AuthUserModel
            {
                Id       = 1,
                Username = "******"
            };
            context.Users.Add(new User {
                Id       = authUser.Id,
                Username = authUser.Username
            });
        }
Beispiel #6
0
        public async Task Init()
        {
            DbContextOptions <Context> options = new DbContextOptionsBuilder <Context>()
                                                 .UseInMemoryDatabase("bookish")
                                                 .Options;

            context            = new Context(options);
            commentService     = new CommentService(context, new MessageService(context));
            postService        = new PostService(context, commentService);
            ratingService      = new RatingService(context);
            openLibraryService = new OpenLibraryService(new System.Net.Http.HttpClient());
            authUser           = new AuthUserModel
            {
                Id       = 1,
                Username = "******"
            };
            context.Users.Add(new User {
                Id       = authUser.Id,
                Username = authUser.Username
            });

            postModel = new PostModel
            {
                Title     = "This is a new book",
                Body      = "The body of the post",
                Posted_At = DateTime.Now,
                ISBN      = "9780553573404",
                Posted_By = authUser.Username
            };

            postModel = await postService.CreatePost(authUser, postModel, openLibraryService);

            commentModel = new CommentModel
            {
                Post_Id = postModel.Id,
                Body    = "This is a comment on a post"
            };

            commentModel = commentService.CreateComment(authUser, commentModel);
        }
Beispiel #7
0
 public OpenLibraryServiceTests()
 {
     mockHttpClientWrapper = new Mock <IHttpClientWrapper>();
     openLibraryService    = new OpenLibraryService(mockHttpClientWrapper.Object);
 }