public void NoSaveProjectWithoutUsersTest() { MsSqlFactory factory = new MsSqlFactory(Common.Connectionconfig); IDataBaseProvider provider = factory.CreateDBProvider(); using (var context = ((DataProvider)provider).GenerateContext()) { ProjectModel projectModel = null; try { projectModel = new ProjectModel(provider) { ProjectDetails = new EProject { ProjectName = "Test project name 1", Description = "ProjectDescr" } }; Assert.IsFalse(projectModel.SaveProject()); Assert.IsTrue(projectModel.ProjectDetails.Id == 0); Assert.IsNull( context.User_Project.FirstOrDefault( u => u.ID_Project == projectModel.ProjectDetails.Id), "User_project is saved"); } finally { if (projectModel != null && projectModel.ProjectDetails.Id > 0) { provider.DeleteProject(projectModel.ProjectDetails.Id); } } } }
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 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."); } }
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 void SuccessSaveProjectTest() { MsSqlFactory factory = new MsSqlFactory(Common.Connectionconfig); IDataBaseProvider provider = factory.CreateDBProvider(); IUserAccessProvider usProvider = factory.CreateUserAccessProvider(); UserModel userModel = null; ProjectModel projectModel = null; try { userModel = new UserModel(usProvider) { UserDetails = SaveANewUser(provider, usProvider) }; projectModel = new ProjectModel(provider) { ProjectDetails = new EProject { ProjectName = "Test project name 1", Description = "ProjectDescr" } }; projectModel.AddUserToProject(userModel.UserDetails.Id, 0); Assert.IsTrue(projectModel.SaveProject(), "Unable to save project"); Assert.IsTrue( projectModel.ProjectDetails.Id > 0, $"Retuen the bad project ID: {projectModel.ProjectDetails.Id}"); var context = ((DataProvider)provider).GenerateContext(); Assert.IsNotNull( context.User_Project.FirstOrDefault( u => u.ID_Project == projectModel.ProjectDetails.Id), "User_project is not saved"); } finally { if (projectModel != null && projectModel.ProjectDetails.Id > 0) { provider.DeleteProject(projectModel.ProjectDetails.Id); } using (var context = ((DataProvider)provider).GenerateContext()) { DeleteUserFromDB(context, userModel?.UserDetails?.Login, userModel?.UserDetails?.EMail); } } }
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); } } }