Esempio n. 1
0
        public async Task ShouldNotFind()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new AuthServiceFactory().Create(context);

                FluentActions.Invoking(async() => await service.Authenticate(new Guid()))
                .Should().Throw <UserNotFoundException>();
            }
        }
        public async Task ShouldNotFindUser()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new AuthServiceFactory().Create(context);

                FluentActions.Invoking(async() => await service.UpdatePassword(Guid.Empty, "wrong"))
                .Should().Throw <UserNotFoundException>();
            }
        }
Esempio n. 3
0
        public async Task ShouldNotFind()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new AuthServiceFactory().Create(context);

                FluentActions.Invoking(async() => await service.Login("*****@*****.**", "Wrong", false))
                .Should().Throw <UserNotFoundException>();
            }
        }
Esempio n. 4
0
        public async Task PasswordShouldBeIncorrect()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new AuthServiceFactory().Create(context);

                FluentActions.Invoking(async() => await service.Login("*****@*****.**", "Wrong", false))
                .Should().Throw <IncorrectPasswordException>();
            }
        }
Esempio n. 5
0
        public async Task ShouldLogin()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new AuthServiceFactory().Create(context);

                var result = await service.Authenticate(new Guid("046E876E-D413-45AF-AC2A-552D7AA46C5C"));

                result.Should().NotBeNull();
            }
        }
Esempio n. 6
0
        public async Task ShouldLogin()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new AuthServiceFactory().Create(context);

                var result = await service.Login("*****@*****.**", "Password", false);

                result.Should().NotBeNull();
            }
        }
Esempio n. 7
0
        public async Task ShouldReturn1DayToken()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new AuthServiceFactory().Create(context);

                var result = await service.Login("*****@*****.**", "Password", false);

                var      handler   = new JwtSecurityTokenHandler();
                var      token     = handler.ReadJwtToken(result.Token);
                DateTime validFrom = token.ValidFrom;
                DateTime validTo   = token.ValidTo;
                validTo.Should().Be(validFrom.AddDays(1));
            }
        }
        public async Task ShouldUpdatePassword()
        {
            await using (var context = new DbContextFactory().CreateContext())
            {
                var service = new AuthServiceFactory().Create(context);

                Guid id = new Guid("046E876E-D413-45AF-AC2A-552D7AA46C5C");

                var user = await context.Users.FirstOrDefaultAsync(x => x.Id == id);

                var prevPassword = user.Password;

                await service.UpdatePassword(id, "NewPassword");

                user.Password.Should().NotBe(prevPassword);
            }
        }