예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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();
        }