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 } } }
public override void Execute(ExecutionContext context) { var connectionInfo = new ConnectionInfo { ConnectionName = (string)context.ResolveVariable(ConnectionName), DataSource = (string)context.ResolveVariable(DataSource), InitialCatalog = InitialCatalog, InitialCatalogName = (string)context.ResolveVariable(InitialCatalogName), UserName = (string)context.ResolveVariable(UserName), Password = (string)context.ResolveVariable(Password) }; var connectionString = MsSqlDataContext.GetConnectionString(connectionInfo); var initialData = InitialData.Load(new SenseNetServicesInitialData(), null); var dataOptions = Options.Create(DataOptions.GetLegacyConfiguration()); var connOptions = Options.Create(new ConnectionStringOptions { ConnectionString = connectionString }); var installer = new MsSqlDataInstaller(connOptions, NullLoggerFactory.Instance.CreateLogger <MsSqlDataInstaller>()); var dataProvider = new MsSqlDataProvider(dataOptions, connOptions, installer); installer.InstallInitialDataAsync(initialData, dataProvider, CancellationToken.None).GetAwaiter().GetResult(); }
public IDBWrapper CreateDatabase() { IDBWrapper database = null; switch (connectionStringSettings.ProviderName.ToLower()) { case "system.data.sqlclient": database = new MsSqlDataProvider(connectionStringSettings.ConnectionString); break; case "mysql.data.mysqlclient": database = new MySQLDataProvider(connectionStringSettings.ConnectionString); break; case "system.data.sqlite": database = new SQLLiteDataProvider(connectionStringSettings.ConnectionString); break; //case "system.data.oleDb": // database = new OledbDataAccess(connectionStringSettings.ConnectionString); // break; //case "system.data.odbc": // database = new OdbcDataAccess(connectionStringSettings.ConnectionString); // break; } return(database); }
private void btnDeleteUser_Click(object sender, RoutedEventArgs e) { if (!IsTrueDbConfig()) { MessageBox.Show("Need right db configuration on the first tab."); return; } if (SelectedUser == null) { MessageBox.Show("Please select the user to delete."); return; } User userToDelete = SelectedUser; DatabaseConfig config = DbConfig; new Task((Action)(() => { MsSqlDataProvider provider = new MsSqlDataProvider(); DragonflyEntities context = provider.Initizlize(config) as DragonflyEntities; try { provider.DeleteUser(userToDelete.Login); Dispatcher.Invoke((Action)(() => { LoadUsersRunner(config); })); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } })).Start(); }
public bool ChangePassword(ChangePassword data) { if (dataProvider.ChangePassword(data.OldPassword, data.NewPassword)) { dataProvider = new MsSqlDataProvider(CreateConnectionString(User.Login, data.NewPassword)); return(true); } return(false); }
public bool ChangePassword(ChangePassword data) { if (dataProvider.ChangePassword(data.OldPassword, data.NewPassword)) { dataProvider = new MsSqlDataProvider(CreateConnectionString(User.Login, data.NewPassword)); return true; } return false; }
public override bool ValidateUser(string username, string password) { string connectionString = ConfigurationManager.ConnectionStrings["CTS"].ConnectionString + "UID=" + username + ";PWD=" + password; var provider = new MsSqlDataProvider(connectionString); return(provider.TestConnection()); }
public ActionResult <string> Get(string id1, string id2) { var parameters = Startup.parameters; Request request = new Request(id1, id2); _ = new TextFileDataProvider(request.Numbers, parameters); _ = new MsSqlDataProvider(request.Numbers, parameters); return($"Wynik dodawania {request.Numbers.Ids[0]} i {request.Numbers.Ids[1]} rowna sie {request.Numbers.addition}"); }
public void InitializeConnection() { MsSqlFactory factory = new MsSqlFactory(Common.Connectionconfig); MsSqlDataProvider provider = factory.CreateDBProvider() as MsSqlDataProvider; using (var context = provider.GenerateContext()) { Assert.IsNotNull(context, "Context not created."); } }
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(); }
public void UserToUserModelTest() { MsSqlFactory factory = new MsSqlFactory(Common.Connectionconfig); MsSqlDataProvider provider = factory.CreateDBProvider() as MsSqlDataProvider; User user = InitUser(); EUser model = user.ToEUser(); Assert.AreEqual(user.ID_User, model.Id, "Bad user id"); Assert.AreEqual(user.Name, model.Name, "Bad name"); Assert.AreEqual(user.Login, model.Login, "Bad login"); Assert.AreEqual(user.E_mail, model.EMail, "Bad e-mail"); }
public bool Authenticate(Credentials credentials) { string connectionString = CreateConnectionString(credentials.Username, credentials.Password); var provider = new MsSqlDataProvider(connectionString); if (provider.TestConnection()) { dataProvider = provider; User = provider.GetItem(new UserDataFilter { Login = credentials.Username }); return true; } return false; }
public bool Authenticate(Credentials credentials) { string connectionString = CreateConnectionString(credentials.Username, credentials.Password); var provider = new MsSqlDataProvider(connectionString); if (provider.TestConnection()) { dataProvider = provider; User = provider.GetItem(new UserDataFilter { Login = credentials.Username }); return(true); } return(false); }
/// <summary>Methor run a loading all users from database.</summary> private void LoadUsersRunner(DatabaseConfig config) { Users.Clear(); new Task(() => { MsSqlDataProvider provider = new MsSqlDataProvider(); DragonflyEntities context = provider.Initizlize(config) as DragonflyEntities; var users = (from u in context.User select u).ToList(); Dispatcher.Invoke((Action)(() => { foreach (User user in users) { Users.Add(user); } })); }).Start(); }
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); } } }
public void WrongDbNameConnectionTest() { Common.Connectionconfig.DbName = "Dragonfly"; MsSqlFactory factory = new MsSqlFactory(Common.Connectionconfig); DbContext context = null; try { MsSqlDataProvider provider = factory.CreateDBProvider() as MsSqlDataProvider; context = provider.GenerateContext(); Assert.IsNull(context, "Context created - is wrong."); } finally { Common.Connectionconfig.DbName = "Dragonfly.Test"; context?.Dispose(); } }
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 } } }
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); } } }
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 } } }
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); } } }
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); } } }