public async Task Handle_SeveralEmailsGivenWithOneMatch_MatchingUserReturned() { //Arrange var fakeManagementApiClientFactory = Substitute.For <IManagementApiClientFactory>(); var fakeManagementApiClient = await fakeManagementApiClientFactory.CreateAsync(); fakeManagementApiClient .GetUsersByEmailAsync("*****@*****.**") .Returns(new List <User>() { new User() { UserName = "******" } }); var handler = new GetAuth0UserFromEmailsQueryHandler(fakeManagementApiClientFactory); //Act var user = await handler.Handle( new GetAuth0UserFromEmailsQuery(new [] { "*****@*****.**", "*****@*****.**", "*****@*****.**" }), default); //Assert Assert.IsNotNull(user); Assert.AreEqual("matching", user.UserName); }
public async Task Handle_NoEmailsProvided_ThrowsException() { //Arrange var fakeManagementApiClientFactory = Substitute.For <IManagementApiClientFactory>(); var handler = new GetAuth0UserFromEmailsQueryHandler(fakeManagementApiClientFactory); //Act var exception = await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await handler.Handle( new GetAuth0UserFromEmailsQuery(Array.Empty <string>()), default)); //Assert Assert.IsNotNull(exception); }
public async Task Handle_SeveralEmailsGivenWithNoMatch_ReturnsNull() { //Arrange var fakeManagementApiClientFactory = Substitute.For <IManagementApiClientFactory>(); var handler = new GetAuth0UserFromEmailsQueryHandler(fakeManagementApiClientFactory); //Act var user = await handler.Handle( new GetAuth0UserFromEmailsQuery(new[] { "*****@*****.**", "*****@*****.**" }), default); //Assert Assert.IsNull(user); }
public async Task Handle_ValidConditions_DisposesClient() { //Arrange var fakeManagementApiClientFactory = Substitute.For <IManagementApiClientFactory>(); var fakeManagementApiClient = await fakeManagementApiClientFactory.CreateAsync(); var handler = new GetAuth0UserFromEmailsQueryHandler(fakeManagementApiClientFactory); //Act await handler.Handle( new GetAuth0UserFromEmailsQuery(new[] { "*****@*****.**", "*****@*****.**" }), default); //Assert fakeManagementApiClient .Received(1) .Dispose(); }