示例#1
0
        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);
                    }
                }
            }
        }
示例#2
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);
                }
            }
        }