Beispiel #1
0
        public void AddUserWithDoubleEmailTest()
        {
            MsSqlFactory      factory  = new MsSqlFactory(Common.Connectionconfig);
            MsSqlDataProvider provider = factory.CreateDBProvider() as MsSqlDataProvider;

            using (DbContext context = provider.GenerateContext())
            {
                SignUpModel model = new SignUpModel()
                {
                    Login    = "******",
                    Password = "******",
                    EMail    = "*****@*****.**"
                };
                try
                {
                    Assert.IsTrue(provider.AddUser(model) > 0, "Insert failed");
                    Assert.IsFalse(provider.AddUser(model) > 0, "Double insert equals user");
                }
                catch (InsertDbDataException ex)
                {
                    Assert.IsTrue(ex.FieldNames.Count() > 0,
                                  $"Exception thrown, but without error fields: {ex.Message}");
                }
                finally
                {
                    DeleteUserFromDB(context, model.Login, model.EMail);
                    //TODO delete test user
                }
            }
        }
Beispiel #2
0
        private void btnAddUser_Click(object sender, RoutedEventArgs e)
        {
            if (!IsTrueDbConfig())
            {
                MessageBox.Show("Need right db configuration on the first tab.");
                return;
            }
            if (string.IsNullOrWhiteSpace(UserName))
            {
                MessageBox.Show("User name is empty");
                return;
            }
            if (string.IsNullOrWhiteSpace(UserPassword))
            {
                MessageBox.Show("User password is empty");
                return;
            }
            if (string.IsNullOrWhiteSpace(UserEMail))
            {
                MessageBox.Show("User e-mail is empty");
                return;
            }
            User user = new User()
            {
                E_mail   = UserEMail,
                Login    = UserName,
                Password = UserPassword
            };
            DatabaseConfig config = DbConfig;

            new Task((Action)(() =>
            {
                MsSqlDataProvider provider = new MsSqlDataProvider();
                DragonflyEntities context = provider.Initizlize(config) as DragonflyEntities;
                try
                {
                    provider.AddUser(user.Login, user.Password, user.E_mail);
                    Dispatcher.Invoke((Action)(() =>
                    {
                        UserEMail = string.Empty;
                        UserName = string.Empty;
                        UserPassword = string.Empty;
                        LoadUsersRunner(config);
                    }));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            })).Start();
        }
Beispiel #3
0
        public void CreateAccessTokenTest()
        {
            MsSqlFactory        factory        = new MsSqlFactory(Common.Connectionconfig);
            MsSqlDataProvider   provider       = factory.CreateDBProvider() as MsSqlDataProvider;
            IUserAccessProvider accessProvider = factory.CreateUserAccessProvider();

            using (DbContext context = provider.GenerateContext())
            {
                DragonflyEntities ents = context as DragonflyEntities;
                decimal           createdAceessToken = 0;

                try
                {
                    decimal userId = provider.AddUser(_UserSignUpData);
                    Assert.IsTrue(userId > 0, "Error occured on the user save.");
                    string token        = accessProvider.CreateAccessToken(userId);
                    var    accessTokens = (from at in ents.User_Access
                                           where at.ID_User == userId
                                           select at);
                    if (accessTokens.Count() > 1)
                    {
                        foreach (var foundToken in accessTokens)
                        {
                            DeleteAccessTokenFromDB(context, foundToken.ID_User_Access);
                        }
                        Assert.Fail("Too many access tokens");
                    }
                    else if (accessTokens.Count() == 1)
                    {
                        createdAceessToken = accessTokens.First().ID_User_Access;
                        Assert.AreEqual(token, accessTokens.First().Access_Token);
                    }
                    else
                    {
                        Assert.Fail("Access tokens not found in the DB.");
                    }
                }
                finally
                {
                    DeleteUserFromDB(context, _UserSignUpData.Login, _UserSignUpData.EMail);
                    DeleteAccessTokenFromDB(context, createdAceessToken);
                }
            }
        }
Beispiel #4
0
        public void AddUserTest()
        {
            MsSqlFactory      factory  = new MsSqlFactory(Common.Connectionconfig);
            MsSqlDataProvider provider = factory.CreateDBProvider() as MsSqlDataProvider;

            using (DbContext context = provider.GenerateContext())
            {
                SignUpModel model = new SignUpModel()
                {
                    Login    = "******",
                    Password = "******",
                    EMail    = "*****@*****.**"
                };
                try
                {
                    Assert.IsTrue(provider.AddUser(model) > 0, "User not saved without error.");

                    Assert.IsTrue(provider.CheckUserCredentials(model.Login, model.Password), "Wrong user saved (login)");
                    Assert.IsTrue(provider.CheckUserCredentials(model.EMail, model.Password), "Wrong user saved (email)");


                    DragonflyEntities ents = context as DragonflyEntities;
                    if (ents != null)
                    {
                        User foundUser = (from u in ents.User
                                          where u.Login.Equals(model.Login)
                                          select u).FirstOrDefault();
                        if (foundUser != null)
                        {
                            Assert.AreEqual(model.EMail, foundUser.E_mail, "Wrong e-mail saved.");
                            //TODO check stored password
                        }
                    }
                }
                finally
                {
                    DeleteUserFromDB(context, model.Login, model.EMail);
                    //TODO delete test user
                }
            }
        }
Beispiel #5
0
        public void CheckAccessTokenTest()
        {
            MsSqlFactory        factory        = new MsSqlFactory(Common.Connectionconfig);
            MsSqlDataProvider   provider       = factory.CreateDBProvider() as MsSqlDataProvider;
            IUserAccessProvider accessProvider = factory.CreateUserAccessProvider();

            using (DbContext context = provider.GenerateContext())
            {
                DragonflyEntities ents = context as DragonflyEntities;
                try
                {
                    decimal userId = provider.AddUser(_UserSignUpData);
                    Assert.IsTrue(userId > 0, "Error occured on the user save.");
                    string token = accessProvider.CreateAccessToken(userId);
                    Assert.IsTrue(accessProvider.CheckAccessToken(userId, token));
                }
                finally
                {
                    DeleteUserFromDB(context, _UserSignUpData.Login, _UserSignUpData.EMail);
                }
            }
        }
Beispiel #6
0
        public void AdduserWithoutEmailTest()
        {
            MsSqlFactory      factory  = new MsSqlFactory(Common.Connectionconfig);
            MsSqlDataProvider provider = factory.CreateDBProvider() as MsSqlDataProvider;

            using (DbContext context = provider.GenerateContext())
            {
                SignUpModel model = new SignUpModel()
                {
                    Login    = "******",
                    Password = "******"
                };
                try
                {
                    Assert.IsFalse(provider.AddUser(model) > 0, "Inserted without e-mail");
                }
                finally
                {
                    DeleteUserFromDB(context, model.Login, model.EMail);
                    //TODO delete test user
                }
            }
        }
Beispiel #7
0
        public void AccessTokenCascadeDeletionTest()
        {
            MsSqlFactory        factory        = new MsSqlFactory(Common.Connectionconfig);
            MsSqlDataProvider   provider       = factory.CreateDBProvider() as MsSqlDataProvider;
            IUserAccessProvider accessProvider = factory.CreateUserAccessProvider();

            using (DbContext context = provider.GenerateContext())
            {
                DragonflyEntities ents = context as DragonflyEntities;
                decimal           createdAceessToken = 0;

                try
                {
                    decimal userId = provider.AddUser(_UserSignUpData);
                    Assert.IsTrue(userId > 0, "Error occured on the user save.");
                    string token        = accessProvider.CreateAccessToken(userId);
                    var    accessTokens = (from at in ents.User_Access
                                           where at.ID_User == userId
                                           select at);
                    if (accessTokens.Count() == 1)
                    {
                        createdAceessToken = accessTokens.First().ID_User_Access;
                        DeleteUserFromDB(context, _UserSignUpData.Login, _UserSignUpData.EMail);
                        var tokensCount = (from at in ents.User_Access
                                           where at.ID_User == userId
                                           select at).Count();
                        Assert.AreEqual(0, tokensCount, "Access tokens for user stay in the DB");
                    }
                }
                finally
                {
                    DeleteUserFromDB(context, _UserSignUpData.Login, _UserSignUpData.EMail);
                    DeleteAccessTokenFromDB(context, createdAceessToken);
                }
            }
        }
Beispiel #8
0
        public void CreateProjectTest()
        {
            MsSqlFactory        factory      = new MsSqlFactory(Common.Connectionconfig);
            MsSqlDataProvider   provider     = factory.CreateDBProvider() as MsSqlDataProvider;
            IUserAccessProvider userProvider = factory.CreateUserAccessProvider();
            SignUpModel         userData     = new SignUpModel()
            {
                Login    = "******",
                EMail    = "*****@*****.**",
                Password = "******"
            };

            provider.AddUser(userData);
            EUser userModel = userProvider.GetUserByLoginMail("*****@*****.**");

            ProjectModel model = new ProjectModel(provider)
            {
                ProjectDetails = new EProject()
                {
                    Description = "Project description",
                    ProjectName = "Test project name"
                },
                //UserIds = new System.Collections.Generic.List<decimal>()
                //{
                //    userModel.Id
                //}
            };

            try
            {
                provider.CreateProject(model);
                Assert.IsTrue(model.ProjectDetails.Id > 0, "Project id less than 1.");

                ProjectModel selectedProjectModel = new ProjectModel()
                {
                    ProjectDetails = provider.GetProjectById(model.ProjectDetails.Id)
                };
                Assert.IsNotNull(
                    selectedProjectModel,
                    $"Unable to retrieve project with id \'{model.ProjectDetails.Id}\'");
                Assert.AreEqual(
                    model.ProjectDetails.ProjectName,
                    selectedProjectModel.ProjectDetails.ProjectName);
                Assert.AreEqual(
                    model.ProjectDetails.Description,
                    selectedProjectModel.ProjectDetails.Description);

                //Check users
                //using (DragonflyEntities ents = provider.GenerateContext())
                //{
                //    var projectUsers = (from usr in ents.User_Project
                //                        where usr.ID_Project == selectedProjectModel.ProjectId
                //                        select usr).ToList();
                //    Assert.IsTrue(projectUsers.All(pu => model.UserIds.Contains(pu.ID_User)),
                //        "Not all users added to project management.");
                //}
            }
            finally
            {
                if (model != null && model.ProjectDetails.Id > 0)
                {
                    provider.DeleteProject(model.ProjectDetails.Id);
                }
                using (DragonflyEntities ents = provider.GenerateContext())
                {
                    DeleteUserFromDB(ents, userData.Login, userData.EMail);
                }
            }
        }