예제 #1
0
        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);
                }
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
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);
                }
            }
        }
예제 #4
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);
                }
            }
        }
예제 #5
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);
                }
            }
        }