-
Notifications
You must be signed in to change notification settings - Fork 5.1k
/
NewsServiceTests.cs
65 lines (55 loc) · 1.75 KB
/
NewsServiceTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using AutoMapper;
using SimpleFeedReader.Services;
using SimpleFeedReader.ViewModels;
using Xunit;
namespace SimpleFeedReader.Tests.Services
{
#nullable enable
public class NewsServiceTests
{
private readonly NewsService _newsService;
public NewsServiceTests()
{
var mockMapper = new MapperConfiguration(cfg => cfg.AddProfile<NewsStoryProfile>());
mockMapper.AssertConfigurationIsValid();
IMapper mapper = mockMapper.CreateMapper();
_newsService = new NewsService(mapper);
}
[Fact]
public async Task Returns_News_Stories_Given_Valid_Uri()
{
// Arrange
var feedUrl = "https://azure.microsoft.com/en-us/blog/feed/";
// <SnippetFixTestSignature>
// Act
IEnumerable<NewsStoryViewModel> result =
await _newsService.GetNews(feedUrl);
// Assert
Assert.True(result.Any());
// </SnippetFixTestSignature>
}
[Fact]
public void Throws_UriFormatException_Given_Malformed_Uri()
{
// Arrange
var feedUrl = "invalid_url";
// Act & Assert
Assert.ThrowsAsync<UriFormatException>(async () =>
await _newsService.GetNews(feedUrl));
}
[Fact]
public void Throws_WebException_Given_Unknown_Host_Uri()
{
// Arrange
var feedUrl = "https://fail/test.rss";
// Act & Assert
Assert.ThrowsAsync<WebException>(async () =>
await _newsService.GetNews(feedUrl));
}
}
}