-
Notifications
You must be signed in to change notification settings - Fork 2
/
RuntimeFakerUsingCustomFakerTests.cs
65 lines (54 loc) · 1.87 KB
/
RuntimeFakerUsingCustomFakerTests.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 DotNet.Core.Faker.Runtime.WebApi.Sample;
using DotNet.Core.Runtime.Faker.WebApi.Sample;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using NUnit.Framework;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using DotNet.Core.Runtime.Faker;
namespace DotNet.Core.Faker.Runtime.Integration.Tests
{
public class RuntimeFakerUsingCustomFakerTests
{
protected static DateTime changedValue;
private WebApplicationFactory<Startup> factory;
private IServiceProvider serviceProvider;
private HttpClient cliente;
[OneTimeSetUp]
public void OneTimeSetUp()
{
changedValue = new Bogus.Faker().Date.Past();
factory = new WebApplicationFactory<Startup>().WithWebHostBuilder(builder =>
builder.ConfigureTestServices(services =>
{
services.AddServiceWithFaker(() => new Clock());
}));
serviceProvider = factory.Services;
}
[OneTimeTearDown]
public void OneTimeTearDown() => factory.Dispose();
[SetUp]
public void Setup() => cliente = factory.CreateClient();
[TearDown]
public void TearDown()
{
cliente.Dispose();
serviceProvider.ResetAllFakeChanges();
}
[Test]
public async Task ShouldChangeClockImplementation()
{
serviceProvider.ChangeFake<Clock>(new MyClock());
var result = await cliente.GetAsync("time");
result.StatusCode.Should().Be(200);
var content = await result.Content.ReadAsStringAsync();
content.Should().Be($"{changedValue:yyyy-MM-ddThh:mm:ss}");
}
public class MyClock : Clock
{
public override DateTime Now() => changedValue;
}
}
}