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 RouteToBookServicePut(PutBookDispatcherRequest request)
        {
            var url = _bookServiceEndPoints.Value.Put;

            if (string.IsNullOrEmpty(url))
            {
                throw new InvalidOperationException(ErrorResources.EndpointIsNotValidOrEmpty);
            }

#pragma warning disable S1854 // Dead stores should be removed
            url = url.Replace("{userid}", request.UserId.ToString());
            url = url.Replace("{id}", request.Id.ToString());
#pragma warning restore S1854 // Dead stores should be removed

            var restRequest = new
            {
                name       = request.Name, authorId = request.AuthorId, publisherId = request.PublisherId
                , tag      = request.Tag, no = request.No, publisherDate = request.PublisherDate
                , skinType = request.SkinType, libraryId = request.LibraryId
            };


            _dispatcher.Dispatch <object, object>(restRequest, url, null, HttpRequestCode.PUT, null);
        }