-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathReadAdTest.cs
41 lines (34 loc) · 1.07 KB
/
ReadAdTest.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
using System.Threading.Tasks;
using ContosoAds.Web.Commands;
using ContosoAds.Web.Model;
using static ContosoAds.Web.UnitTests.TestSupport;
namespace ContosoAds.Web.UnitTests;
public class ReadAdTest
{
[Fact]
public async Task It_Finds_Ad()
{
// Arrange
const int adId = 1;
var dbContext = await CreateTestDbContext(
nameof(ReadAdTest),
true,
new Ad {Id = adId, Title = "Test Ad", Phone = "425-555-1212", Price = 42});
// Act
var command = new ReadAd(dbContext);
var foundAd = await command.ExecuteAsync(adId);
// Assert
Assert.Equal(adId, foundAd?.Id);
}
[Fact]
public async Task It_Returns_Null_If_Ad_Does_Not_Exist()
{
// Arrange
var dbContext = await CreateTestDbContext(nameof(ReadAdTest), true, new Ad {Id = 1, Title = "Test Ad", Phone = "425-555-1212", Price = 42});
// Act
var command = new ReadAd(dbContext);
var foundAd = await command.ExecuteAsync(2);
// Assert
Assert.Null(foundAd);
}
}