public async Task GetRandomTracks_SuccessAsync() { // Arrange // set request header _request.Setup(req => req.Headers).Returns(new HeaderDictionary(new Dictionary <string, StringValues>() { ["token"] = UserToken })); // set music api return value var musicService = new Mock <IMusicService>(); musicService.Setup(service => service.SearchAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(Task.FromResult(Tuple.Create(HttpStatusCode.OK, ExampleOutput))); // set search term var searchTermProvider = new Mock <ISearchTermProvider>(); searchTermProvider.Setup(provider => provider.GetRandomSearchTerm(_context.Object)).Returns(It.IsAny <string>()); // Act var result = await GetRandomTracks.RunAsync(_request.Object, _context.Object, _logger.Object, musicService.Object, searchTermProvider.Object) as OkObjectResult; // Assert Assert.AreEqual(ExampleOutput, result.Value); }
public async Task GetRandomTracks_CountOnlyPositiveIntegers() { // Arrange // set request header _request.Setup(req => req.Headers).Returns(new HeaderDictionary(new Dictionary <string, StringValues>() { ["token"] = UserToken })); // Set query string parameter _request.Setup(req => req.Query).Returns(new QueryCollection(new Dictionary <string, StringValues>() { ["count"] = "-1" })); // set music api return value var musicService = new Mock <IMusicService>(); musicService.Setup(service => service.SearchAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(Task.FromResult(Tuple.Create(HttpStatusCode.OK, ExampleOutput))); // set search term var searchTermProvider = new Mock <ISearchTermProvider>(); searchTermProvider.Setup(provider => provider.GetRandomSearchTerm(_context.Object)).Returns(It.IsAny <string>()); // Act var result = await GetRandomTracks.RunAsync(_request.Object, _context.Object, _logger.Object, musicService.Object, searchTermProvider.Object) as BadRequestObjectResult; // Assert Assert.AreEqual("Please enter a valid count.", result.Value); }
public async Task GetRandomTracks_NoTokenReturnsBadRequest_Async() { // Arrange // set music api return value var musicService = new Mock <IMusicService>(); musicService.Setup(service => service.SearchAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())) .Returns(Task.FromResult(Tuple.Create(HttpStatusCode.OK, "test"))); // set search term var searchTermProvider = new Mock <ISearchTermProvider>(); searchTermProvider.Setup(provider => provider.GetRandomSearchTerm(_context.Object)).Returns(It.IsAny <string>()); // Act var result = await GetRandomTracks.RunAsync(_request.Object, _context.Object, _logger.Object, musicService.Object, searchTermProvider.Object); // Assert Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); }