Exemplo n.º 1
0
        public async Task GetDeviceInfoForCurrentUser_GivenNoDataIsFound_ExpectMaybeWithNothing()
        {
            var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>();

            currentAuthenticatedUserProvider.Setup(x => x.CurrentAuthenticatedUser).Returns(
                Maybe.From(
                    new AuthenticatedUser(Guid.NewGuid(), string.Empty, string.Empty, string.Empty) as ISystemUser));
            var connection = new Mock <IDbConnection>();

            connection.SetupDapperAsync(c => c.QueryAsync <DeviceInfoDto>(
                                            It.IsAny <string>(),
                                            It.IsAny <DynamicParameters>(),
                                            null, null, It.IsAny <CommandType>()))
            .ReturnsAsync(() => new List <DeviceInfoDto>());

            var dbConnectionProvider = new Mock <IConnectionProvider>();

            dbConnectionProvider.Setup(x => x.GetConnection())
            .Returns(() => connection.Object);

            var userQueries = new UserQueries(currentAuthenticatedUserProvider.Object, dbConnectionProvider.Object);
            var result      = await userQueries.GetDeviceInfoForCurrentUser();

            Assert.True(result.HasNoValue);
        }
Exemplo n.º 2
0
        public async Task GetDeviceInfoForCurrentUser_GivenNoUserIsAuthenticated_ExpectMaybeWithNothing()
        {
            var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>();

            currentAuthenticatedUserProvider.Setup(x => x.CurrentAuthenticatedUser).Returns(Maybe <ISystemUser> .Nothing);

            var dbConnectionProvider = new Mock <IConnectionProvider>();

            var userQueries = new UserQueries(currentAuthenticatedUserProvider.Object, dbConnectionProvider.Object);
            var result      = await userQueries.GetDeviceInfoForCurrentUser();

            Assert.True(result.HasNoValue);
        }
Exemplo n.º 3
0
        public async Task GetDeviceInfoForCurrentUser_GivenDataIsFound_ExpectMaybeWithMappedData()
        {
            var currentAuthenticatedUserProvider = new Mock <ICurrentAuthenticatedUserProvider>();

            currentAuthenticatedUserProvider.Setup(x => x.CurrentAuthenticatedUser).Returns(
                Maybe.From(
                    new AuthenticatedUser(Guid.NewGuid(), string.Empty, string.Empty, string.Empty) as ISystemUser));
            var connection = new Mock <IDbConnection>();

            connection.SetupDapperAsync(c => c.QueryAsync <DeviceInfoDto>(
                                            It.IsAny <string>(),
                                            It.IsAny <DynamicParameters>(),
                                            null, null, It.IsAny <CommandType>()))
            .ReturnsAsync(() => new List <DeviceInfoDto>
            {
                new DeviceInfoDto
                {
                    Id           = TestVariables.AuthenticatorDeviceId,
                    Name         = "name",
                    WhenEnrolled = TestVariables.Now,
                    WhenLastUsed = TestVariables.Now.AddHours(1),
                },
            });

            var dbConnectionProvider = new Mock <IConnectionProvider>();

            dbConnectionProvider.Setup(x => x.GetConnection())
            .Returns(() => connection.Object);

            var userQueries = new UserQueries(currentAuthenticatedUserProvider.Object, dbConnectionProvider.Object);
            var result      = await userQueries.GetDeviceInfoForCurrentUser();

            Assert.True(result.HasValue);
            Assert.Single(result.Value);
            Assert.Equal("name", result.Value.First().Name);
            Assert.Equal(TestVariables.AuthenticatorDeviceId, result.Value.First().Id);
            Assert.Equal(TestVariables.Now, result.Value.First().WhenEnrolled);
            Assert.Equal(TestVariables.Now.AddHours(1), result.Value.First().WhenLastUsed);
        }