mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
Add test
This commit is contained in:
parent
fd74ea280b
commit
ac7d0d0af3
@ -41,13 +41,13 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
_internalConfigCreator = new Mock<IInternalConfigurationCreator>();
|
_internalConfigCreator = new Mock<IInternalConfigurationCreator>();
|
||||||
_internalConfigCreator.Setup(x => x.Create(It.IsAny<FileConfiguration>())).ReturnsAsync(new OkResponse<IInternalConfiguration>(_internalConfig));
|
_internalConfigCreator.Setup(x => x.Create(It.IsAny<FileConfiguration>())).ReturnsAsync(new OkResponse<IInternalConfiguration>(_internalConfig));
|
||||||
_poller = new FileConfigurationPoller(_factory.Object, _repo.Object, _config.Object, _internalConfigRepo.Object, _internalConfigCreator.Object);
|
_poller = new FileConfigurationPoller(_factory.Object, _repo.Object, _config.Object, _internalConfigRepo.Object, _internalConfigCreator.Object);
|
||||||
_poller.StartAsync(new CancellationToken());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_start()
|
public void should_start()
|
||||||
{
|
{
|
||||||
this.Given(x => ThenTheSetterIsCalled(_fileConfig, 1))
|
this.Given(x => GivenPollerHasStarted())
|
||||||
|
.Given(x => ThenTheSetterIsCalled(_fileConfig, 1))
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +71,8 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => WhenTheConfigIsChanged(newConfig, 0))
|
this.Given(x => GivenPollerHasStarted())
|
||||||
|
.Given(x => WhenTheConfigIsChanged(newConfig, 0))
|
||||||
.Then(x => ThenTheSetterIsCalledAtLeast(newConfig, 1))
|
.Then(x => ThenTheSetterIsCalledAtLeast(newConfig, 1))
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
@ -96,7 +97,8 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => WhenTheConfigIsChanged(newConfig, 10))
|
this.Given(x => GivenPollerHasStarted())
|
||||||
|
.Given(x => WhenTheConfigIsChanged(newConfig, 10))
|
||||||
.Then(x => ThenTheSetterIsCalled(newConfig, 1))
|
.Then(x => ThenTheSetterIsCalled(newConfig, 1))
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
@ -121,11 +123,24 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.Given(x => WhenProviderErrors())
|
this.Given(x => GivenPollerHasStarted())
|
||||||
|
.Given(x => WhenProviderErrors())
|
||||||
.Then(x => ThenTheSetterIsCalled(newConfig, 0))
|
.Then(x => ThenTheSetterIsCalled(newConfig, 0))
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void should_dispose_cleanly_without_starting()
|
||||||
|
{
|
||||||
|
this.When(x => WhenPollerIsDisposed())
|
||||||
|
.BDDfy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GivenPollerHasStarted()
|
||||||
|
{
|
||||||
|
_poller.StartAsync(CancellationToken.None);
|
||||||
|
}
|
||||||
|
|
||||||
private void WhenProviderErrors()
|
private void WhenProviderErrors()
|
||||||
{
|
{
|
||||||
_repo
|
_repo
|
||||||
@ -141,6 +156,11 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
.ReturnsAsync(new OkResponse<FileConfiguration>(newConfig));
|
.ReturnsAsync(new OkResponse<FileConfiguration>(newConfig));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void WhenPollerIsDisposed()
|
||||||
|
{
|
||||||
|
_poller.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private void ThenTheSetterIsCalled(FileConfiguration fileConfig, int times)
|
private void ThenTheSetterIsCalled(FileConfiguration fileConfig, int times)
|
||||||
{
|
{
|
||||||
var result = WaitFor(4000).Until(() =>
|
var result = WaitFor(4000).Until(() =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user