public void Given_UnAuthorizedUser_Then_NotAuthorizedExceptionIsThrown() { var request = new GetServerList(); _serverRepositoryMock.Setup(m => m.Get()).ThrowsAsync(DomainExceptions.NotAuthorized); _whenGetServerList = new WhenGetServerList(_serverRepositoryMock.Object, _localServerRepositoryMock.Object); Assert.That(async() => await _whenGetServerList.ThenAsync(request), Throws.Exception.TypeOf <DomainException>()); _serverRepositoryMock.Verify(m => m.Get(), Times.Once); _localServerRepositoryMock.Verify(m => m.Save(It.IsAny <IEnumerable <Server> >()), Times.Never); }
public async Task Given_AuthorizedUser_Then_ServerListIsReturned() { var request = new GetServerList(); _whenGetServerList = new WhenGetServerList(_serverRepositoryMock.Object, _localServerRepositoryMock.Object); var result = await _whenGetServerList.ThenAsync(request); Assert.That(result, Is.Not.Null); Assert.That(result.Items, Is.Not.Null); Assert.That(result.Count, Is.EqualTo(result.Items.Count)); _serverRepositoryMock.Verify(m => m.Get(), Times.Once); _localServerRepositoryMock.Verify(m => m.Save(It.IsAny <IEnumerable <Server> >()), Times.Once); }
public async Task Handle(ServerListOptions options) { ServerList servers = new ServerList(); if (options.Local == false) { var request = new GetServerList(); servers = await _whenGetServerList.ThenAsync(request).ConfigureAwait(false); } if (options.Local) { var request = new GetLocalServerList(); servers = await _whenGetLocalServerList.ThenAsync(request).ConfigureAwait(false); } ResultsPrinter.Print(servers); }