public async Task SignInUserAsync_GivenUserDoesNotExist_ExpectException()
        {
            var httpContextAccessor = new Mock <IHttpContextAccessor>();
            var userQueries         = new Mock <IUserQueries>();

            userQueries.Setup(x => x.GetSystemProfileByUserId(It.IsAny <Guid>()))
            .ReturnsAsync(() => Maybe <SystemProfileModel> .Nothing);

            var authenticationService =
                new AuthenticationService(
                    httpContextAccessor.Object, userQueries.Object);

            await Assert.ThrowsAsync <InvalidOperationException>(() => authenticationService.SignInUserAsync(Guid.Empty));
        }
        public async Task SignInUserAsync_GivenUserExists_ExpectIdentityToBeSet()
        {
            var userId              = Guid.NewGuid();
            var authServiceMock     = new Mock <IAuthenticationService>();
            var serviceProviderMock = new Mock <IServiceProvider>();

            serviceProviderMock
            .Setup(_ => _.GetService(typeof(IAuthenticationService)))
            .Returns(authServiceMock.Object);

            var httpContext = new DefaultHttpContext
            {
                RequestServices = serviceProviderMock.Object,
            };

            var httpContextAccessor = new Mock <IHttpContextAccessor>();

            httpContextAccessor.Setup(x => x.HttpContext).Returns(httpContext);
            var userQueries = new Mock <IUserQueries>();

            userQueries.Setup(x => x.GetSystemProfileByUserId(It.IsAny <Guid>()))
            .ReturnsAsync(
                () => Maybe.From(new SystemProfileModel(
                                     new string('*', 5),
                                     new string('*', 5),
                                     new string('*', 5),
                                     true,
                                     new List <string>())));
            var authenticationService =
                new AuthenticationService(
                    httpContextAccessor.Object, userQueries.Object);

            await authenticationService.SignInUserAsync(userId);

            authServiceMock.Verify(
                x => x.SignInAsync(
                    It.IsAny <HttpContext>(),
                    CookieAuthenticationDefaults.AuthenticationScheme,
                    It.Is <ClaimsPrincipal>(x =>
                                            x.HasClaim(c => c.Type == ClaimTypes.Upn && c.Value == userId.ToString()) &&
                                            x.HasClaim(c => c.Type == ClaimTypes.UserData)),
                    It.IsAny <AuthenticationProperties>()), Times.Once);
        }