public async Task HandleWithValidUpdateRequestCallUpdateAsExpectedResult()
        {
            // Arrange          
            var watchListEntity = new WatchList { MovieId = 299536, Comments = "Avengers: Infinity War is good" };
            var watchListModel = new WatchListModel { MovieId = 299536, Comments = "Avengers: Infinity is good" };

            var config = new MapperConfiguration(m => { m.CreateMap<WatchList, WatchListModel>(); });
            var mapper = new Mapper(config);

            repository = new Mock<IRepository>();
            repository.Setup(m => m.Get<WatchList>(It.IsAny<int>()))
              .Returns(watchListEntity);

            updateWatchList = new UpdateWatchList(repository.Object, mapper);
            updateWatchListRequest = new UpdateWatchListRequest(watchListModel);

            // Act
            CancellationToken cancellationToken;
            var result = await updateWatchList.Handle(updateWatchListRequest, cancellationToken);

            // Assert  
            Assert.NotNull(result);
            Assert.Equal(watchListModel.Comments, result.Comments);
            Assert.Equal(watchListModel.MovieId, result.MovieId);
        }
예제 #2
0
        /// <summary>
        /// Updates watch list object from Alpaca REST API endpoint by watch list identifier.
        /// </summary>
        /// <param name="request">Update watch list request parameters.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>Updated watch list object with proper <paramref name="request.WatchListId"/> value.</returns>
        public async Task <IWatchList> UpdateWatchListByIdAsync(
            UpdateWatchListRequest request,
            CancellationToken cancellationToken = default)
        {
            request.EnsureNotNull(nameof(request)).Validate();

            await _alpacaRestApiThrottler.WaitToProceed(cancellationToken).ConfigureAwait(false);

            using var content  = toStringContent(request.Name, request.Assets);
            using var response = await _httpClient.PutAsync(
                      new Uri ($"watchlists/{request.WatchListId:D}", UriKind.RelativeOrAbsolute), content, cancellationToken)
                                 .ConfigureAwait(false);

            return(await response.DeserializeAsync <IWatchList, JsonWatchList>()
                   .ConfigureAwait(false));
        }
        public async Task HandleWithNullUpdateRequestCallUpdateAsExpectedResult()
        {
            // Arrange                    
            repository = new Mock<IRepository>();
            var config = new MapperConfiguration(m => { m.CreateMap<WatchList, WatchListModel>(); });
            var mapper = new Mapper(config);

            updateWatchList = new UpdateWatchList(repository.Object, mapper);
            updateWatchListRequest = null;

            // Act
            CancellationToken cancellationToken;
            var result = await updateWatchList.Handle(updateWatchListRequest, cancellationToken);

            // Assert  
            Assert.Null(result);
        }