Ejemplo n.º 1
0
        public void IsValidModelSignUp()
        {
            SqlLiteDatabaseTest(options =>
            {
                var authService   = _server.Host.Services.GetService(typeof(IAuthService)) as IAuthService;
                var inviteService = _server.Host.Services.GetService(typeof(IInviteService)) as IInviteService;

                using (var context = new PlayCatDbContext(options))
                {
                    authService.SetDbContext(context);

                    SignUpInResult result = authService.SignUp(new SignUpRequest()
                    {
                        FirstName        = "vlad",
                        LastName         = "Kuz",
                        Password         = "******",
                        ConfirmPassword  = "******",
                        Email            = "*****@*****.**",
                        VerificationCode = inviteService.GenerateInvite(),
                    });

                    Assert.NotNull(result);
                    Assert.True(result.Ok);
                    Assert.NotNull(result.User);
                    Assert.NotNull(result.AuthToken);
                    Assert.Null(result.Errors);
                    Assert.Null(result.Info);
                }
            });
        }
Ejemplo n.º 2
0
        public void IsUserNotFoundSignIn()
        {
            SqlLiteDatabaseTest(options =>
            {
                var authService   = _server.Host.Services.GetService(typeof(IAuthService)) as IAuthService;
                var inviteService = _server.Host.Services.GetService(typeof(IInviteService)) as IInviteService;

                using (var context = new PlayCatDbContext(options))
                {
                    authService.SetDbContext(context);
                    SignUpInResult resultSignIn = authService.SignIn(new SignInRequest()
                    {
                        Email    = "*****@*****.**",
                        Password = "******",
                    });

                    Assert.NotNull(resultSignIn);
                    Assert.False(resultSignIn.Ok);
                    Assert.Null(resultSignIn.User);
                    Assert.Null(resultSignIn.AuthToken);
                    Assert.Null(resultSignIn.Errors);
                    Assert.Equal("Email or password is incorrect", resultSignIn.Info);
                    Assert.True(resultSignIn.ShowInfo);
                }
            });
        }
Ejemplo n.º 3
0
        public void IsUpdateTokenSignIn()
        {
            SqlLiteDatabaseTest(options =>
            {
                var authService   = _server.Host.Services.GetService(typeof(IAuthService)) as IAuthService;
                var inviteService = _server.Host.Services.GetService(typeof(IInviteService)) as IInviteService;

                using (var context = new PlayCatDbContext(options))
                {
                    authService.SetDbContext(context);

                    string password = "******";
                    string email    = "*****@*****.**";

                    string salt        = Crypto.GenerateSalt();
                    string passwordHah = Crypto.HashPassword(password + salt);

                    var user = context.Users.Add(new DataModel.User()
                    {
                        Id               = Guid.NewGuid(),
                        Email            = email,
                        FirstName        = "test",
                        LastName         = "test",
                        PasswordHash     = passwordHah,
                        PasswordSalt     = salt,
                        RegisterDate     = DateTime.Now,
                        VerificationCode = inviteService.GenerateInvite(),
                    });

                    var authToken = context.AuthTokens.Add(new DataModel.AuthToken()
                    {
                        Id          = Guid.NewGuid(),
                        DateExpired = DateTime.Now.AddDays(-1),
                        IsActive    = false,
                        UserId      = user.Entity.Id,
                    });

                    context.SaveChanges();

                    SignUpInResult result = authService.SignIn(new SignInRequest()
                    {
                        Email    = email,
                        Password = password,
                    });

                    var updatedAuthToken = context.AuthTokens.FirstOrDefault();

                    Assert.NotNull(updatedAuthToken);
                    Assert.True(updatedAuthToken.DateExpired > DateTime.Now);
                    Assert.True(updatedAuthToken.IsActive);
                }
            });
        }
Ejemplo n.º 4
0
        public void IsUserFoundButWrongPasswordSignIn()
        {
            SqlLiteDatabaseTest(options =>
            {
                var authService   = _server.Host.Services.GetService(typeof(IAuthService)) as IAuthService;
                var inviteService = _server.Host.Services.GetService(typeof(IInviteService)) as IInviteService;

                using (var context = new PlayCatDbContext(options))
                {
                    authService.SetDbContext(context);

                    SignUpInResult result = authService.SignUp(new SignUpRequest()
                    {
                        FirstName        = "vlad",
                        LastName         = "Kuz",
                        Password         = "******",
                        ConfirmPassword  = "******",
                        Email            = "*****@*****.**",
                        VerificationCode = inviteService.GenerateInvite(),
                    });

                    Assert.NotNull(result);
                    Assert.True(result.Ok);
                    Assert.NotNull(result.User);
                    Assert.NotNull(result.AuthToken);
                    Assert.Null(result.Errors);
                    Assert.Null(result.Info);

                    SignUpInResult resultSignIn = authService.SignIn(new SignInRequest()
                    {
                        Email    = "*****@*****.**",
                        Password = "******",
                    });

                    Assert.NotNull(resultSignIn);
                    Assert.False(resultSignIn.Ok);
                    Assert.Null(resultSignIn.User);
                    Assert.Null(resultSignIn.AuthToken);
                    Assert.Null(resultSignIn.Errors);
                    Assert.Equal("Email or password is incorrect", resultSignIn.Info);
                    Assert.True(resultSignIn.ShowInfo);
                }
            });
        }
Ejemplo n.º 5
0
        public void IsUsedEmailSignUp()
        {
            SqlLiteDatabaseTest(options =>
            {
                var authService   = _server.Host.Services.GetService(typeof(IAuthService)) as IAuthService;
                var inviteService = _server.Host.Services.GetService(typeof(IInviteService)) as IInviteService;

                using (var context = new PlayCatDbContext(options))
                {
                    authService.SetDbContext(context);

                    string invite = inviteService.GenerateInvite();

                    SignUpInResult result = authService.SignUp(new SignUpRequest()
                    {
                        FirstName        = "vlad",
                        LastName         = "Kuz",
                        Password         = "******",
                        ConfirmPassword  = "******",
                        Email            = "*****@*****.**",
                        VerificationCode = invite
                    });

                    SignUpInResult result2 = authService.SignUp(new SignUpRequest()
                    {
                        FirstName        = "vlad",
                        LastName         = "Kuz",
                        Password         = "******",
                        ConfirmPassword  = "******",
                        Email            = "*****@*****.**",
                        VerificationCode = invite
                    });

                    Assert.NotNull(result2);
                    Assert.False(result2.Ok);
                    Assert.Null(result2.User);
                    Assert.Null(result2.AuthToken);
                    Assert.Null(result2.Errors);
                    Assert.Equal("User with this email already registered", result2.Info);
                    Assert.True(result2.ShowInfo);
                }
            });
        }
Ejemplo n.º 6
0
        public void IsEmptyModelSignUp()
        {
            SqlLiteDatabaseTest(options =>
            {
                var authService = _server.Host.Services.GetService(typeof(IAuthService)) as IAuthService;
                using (var context = new PlayCatDbContext(options))
                {
                    authService.SetDbContext(context);

                    SignUpInResult result = authService.SignUp(new SignUpRequest {
                    });

                    Assert.NotNull(result);
                    Assert.False(result.Ok);
                    Assert.Equal("Model is not valid", result.Info);
                    Assert.False(result.ShowInfo);
                    Assert.Null(result.User);
                    Assert.Null(result.AuthToken);
                    Assert.NotNull(result.Errors);
                    Assert.True(result.Errors.Any());
                }
            });
        }