Beispiel #1
0
        public void WhenRouteToBookServicePut_DispatchReturnsSuccess()
        {
            var request = new PutBookDispatcherRequest
            {
                UserId      = 1, No = 5, Name = "aaa", Tag = "tag", ShelfId = 1, AuthorId = "id", SkinType = 1
                , LibraryId = "id", PublisherId = 1, PublisherDate = Convert.ToDateTime("01.01.2019"), Id = 1
            };

            _bookServiceEndPointsMock.Setup(t => t.Value)
            .Returns(() => new BookServiceEndPointConstants {
                Put = "https://{userid}"
            });

            _dispatcherMock.Setup(t =>
                                  t.Dispatch <object, object>(It.IsAny <object>(), "https://1", null
                                                              , HttpRequestCode.PUT, null, null))
            .Verifiable();

            _bookDispatchService = new BookServiceDispatcher(_bookServiceEndPointsMock.Object, _dispatcherMock.Object);

            _bookDispatchService.RouteToBookServicePut(request);

            _dispatcherMock.Verify(
                t => t.Dispatch <object, object>(It.IsAny <object>(), "https://1", null, HttpRequestCode.PUT, null, null),
                Times.Once);
        }
        public void WhenRouteToBookServiceGetById_ReturnsResult()
        {
            _bookServiceEndPointsMock.Setup(t => t.Value)
            .Returns(() => new BookServiceEndPointConstants {
                Get = "addr"
            });

            var queryParameters = new Dictionary <string, object>
            {
                { "id", 1 }
            };

            _dispatcherMock.Setup(t => t.Dispatch <object, BookDispatcherResponse>(null,
                                                                                   _bookServiceEndPointsMock.Object.Value
                                                                                   .Get, null, HttpRequestCode.GET
                                                                                   , queryParameters, null))
            .Returns(() => new BookDispatcherResponse
            {
                Books = new List <BookModel>
                {
                    new BookModel()
                }
                , Total = 1
            });

            _bookDispatchService = new BookServiceDispatcher(_bookServiceEndPointsMock.Object, _dispatcherMock.Object);

            var actual = _bookDispatchService.RouteToBookServiceGet(1, 1);

            Assert.Equal(1, actual.Total);
        }
        public void WhenRouteToBookServiceGet_ReturnsResult()
        {
            _bookServiceEndPointsMock.Setup(t => t.Value)
            .Returns(() => new BookServiceEndPointConstants {
                Get = "addr"
            });

            var queryParameters = new Dictionary <string, object>
            {
                { "offset", 1 }, { "limit", 10 }
            };

            _dispatcherMock.Setup(t => t.Dispatch <object, BookDispatcherResponse>(null,
                                                                                   _bookServiceEndPointsMock.Object.Value
                                                                                   .Get, null, HttpRequestCode.GET
                                                                                   , queryParameters, null))
            .Returns(() => new BookDispatcherResponse
            {
                Books = new List <BookModel>
                {
                    new BookModel()
                    {
                        Id          = 1,
                        No          = 1,
                        Tag         = "tag",
                        Name        = "name",
                        ShelfId     = 1,
                        AuthorId    = "id",
                        SkinType    = 1,
                        LibraryId   = "id",
                        PublishDate = Convert.ToDateTime("01.01.2019"),
                        PublisherId = 1
                    }
                }
                , Total = 1
            });

            _bookDispatchService = new BookServiceDispatcher(_bookServiceEndPointsMock.Object, _dispatcherMock.Object);

            var actual = _bookDispatchService.RouteToBookServiceGet(new BookDispatcherRequest
            {
                UserId = 1, Limit = 10, Offset = 1
            });

            var bookModel = actual.Books.FirstOrDefault();

            Assert.Equal(1, actual.Total);

            Assert.Equal(1, bookModel.Id);
            Assert.Equal(1, bookModel.No);
            Assert.Equal("tag", bookModel.Tag);
            Assert.Equal("name", bookModel.Name);
            Assert.Equal(1, bookModel.ShelfId);
            Assert.Equal("id", bookModel.AuthorId);
            Assert.Equal(1, bookModel.SkinType);
            Assert.Equal("id", bookModel.LibraryId);
            Assert.Equal(Convert.ToDateTime("01.01.2019"), bookModel.PublishDate);
            Assert.Equal(1, bookModel.PublisherId);
        }
Beispiel #4
0
        public void WhenRouteToBookServiceDelete_ThrowsInvalidOperationException()
        {
            _bookServiceEndPointsMock.Setup(t => t.Value)
            .Returns(() => new BookServiceEndPointConstants {
                Delete = string.Empty
            });

            _bookDispatchService = new BookServiceDispatcher(_bookServiceEndPointsMock.Object, _dispatcherMock.Object);

            Assert.Throws <InvalidOperationException>(() =>
                                                      _bookDispatchService.RouteToBookServiceDelete(1, 5));
        }
Beispiel #5
0
        public void WhenRouteToBookServiceDelete_DispatchReturnsSuccess()
        {
            _bookServiceEndPointsMock.Setup(t => t.Value).Returns(() => new BookServiceEndPointConstants
            {
                Delete = "https://{userid}"
            });

            _bookDispatchService = new BookServiceDispatcher(_bookServiceEndPointsMock.Object, _dispatcherMock.Object);

            _bookDispatchService.RouteToBookServiceDelete(1, 5);

            _dispatcherMock.Verify(
                t => t.Dispatch <object, object>(null, It.IsAny <string>(), null, HttpRequestCode.DELETE, null, null),
                Times.Once);
        }
        public void WhenUrlIsNotNull_ThrowException()
        {
            _bookServiceEndPointsMock.Setup(t => t.Value).Returns(() => new BookServiceEndPointConstants {
                Get = ""
            });

            _bookDispatchService = new BookServiceDispatcher(_bookServiceEndPointsMock.Object, _dispatcherMock.Object);

            Assert.Throws <InvalidOperationException>(() =>
                                                      _bookDispatchService.RouteToBookServiceGet(
                                                          new BookDispatcherRequest
            {
                UserId   = It.IsAny <int>(), Limit = It.IsAny <int>()
                , Offset = It.IsAny <int>()
            }));
        }