public void Initial()
        {
            var mockIProjectService        = new Mock <IProjectService>();
            var mockIProjectsShareService  = new Mock <IProjectsShareService>();
            var mockIUserService           = new Mock <IUserService>();
            var mockIConnectionDbService   = new Mock <IConnectionDbService>();
            var mockIQueryService          = new Mock <IQueryService>();
            var mockIQueriesHistoryService = new Mock <IQueriesHistoryService>();

            Mapper.Initialize(m => m.AddProfile <ViewModelToDomainMappingProfile>());
            mockIProjectService.Setup(a => a.GetProjects()).Returns(new List <Project>()
            {
                new Project()
            });
            mockIUserService.Setup(a => a.GetUsers()).Returns(new List <ApplicationUser>()
            {
                new ApplicationUser()
                {
                    FirstName = "s", LastName = "d"
                }
            });
            mockIProjectsShareService.Setup(a => a.GetUserProjects(new ApplicationUser())).Returns(new List <Project>());
            mockIConnectionDbService.Setup(a => a.GetConnectionDBs()).Returns(new List <ConnectionDB>()
            {
                new ConnectionDB()
                {
                    ConnectionID = 0, ConnectionName = "Name", PasswordDB = Rijndael.EncryptStringToBytes("pass"), DatabaseName = "nameDB"
                }
            });
            mockIQueryService.Setup(a => a.GetQueries()).Returns(new List <Query>()
            {
                new Query()
                {
                    QueryID = 1, QueryBody = "Select", ProjectID = 1
                }
            });
            mockIQueriesHistoryService.Setup(a => a.GetQueriesHistory()).Returns(new List <QueryHistory>());

            wc = new WorkflowController(mockIProjectService.Object, mockIUserService.Object, mockIProjectsShareService.Object,
                                        mockIConnectionDbService.Object, mockIQueryService.Object, mockIQueriesHistoryService.Object);
        }
Exemplo n.º 2
0
        protected override void Configure()
        {
            Mapper.CreateMap <ProjectViewModel, Project>()
            .ForMember("ProjectID", opt => opt.MapFrom(src => src.IdCurrentProject))
            .ForMember("ProjectName", opt => opt.MapFrom(src => src.Name))
            .ForMember("ProjectDescription", opt => opt.MapFrom(src => src.Description));
            Mapper.CreateMap <ConnectionViewModel, ConnectionDB>()
            .ForMember("ConnectionName", opt => opt.MapFrom(src => src.ConnectionName))
            .ForMember("ConnectionID", opt => opt.MapFrom(src => src.ConnectionID))
            .ForMember("ServerName", opt => opt.MapFrom(src => src.ServerName))
            .ForMember("LoginDB", opt => opt.MapFrom(src => src.LoginDB))
            .ForMember("DatabaseName", opt => opt.MapFrom(src => src.DatabaseName))
            .ForMember("ConnectionOwner", opt => opt.MapFrom(src => src.ConnectionOwner))
            .ForMember("PasswordDB", opt => opt.MapFrom(src => Rijndael.EncryptStringToBytes(src.PasswordDB)));

            Mapper.CreateMap <UserViewModel, ApplicationUser>()
            .ForMember(x => x.Id, opt => opt.MapFrom(src => src.UserId));
            Mapper.CreateMap <QueryViewModel, Query>();
            Mapper.CreateMap <QueryListViewModel, Query>();
            Mapper.CreateMap <QueryHistoryViewModel, QueryHistory>();
            Mapper.CreateMap <QueryHistoryListViewModel, QueryHistory>();
        }
        public ProjectViewModel GetExampleProject()
        {
            var proj = new List <ProjectsListViewModel>
            {
                new ProjectsListViewModel
                {
                    ProjectID          = 1,
                    ProjectName        = "Example",
                    ProjectDescription = "This project for demonstration service",
                    UserRole           = UserRoleProjectsShareConstants.Owner,
                }
            };
            var connect = new List <ConnectionsListViewModel>
            {
                new ConnectionsListViewModel
                {
                    ConnectionID    = -1,
                    ConnectionName  = "Example",
                    ConnectionOwner = proj[0].ProjectID,
                    DatabaseName    = DefaultDatabaseConstants.DatabaseName,
                    LoginDB         = DefaultDatabaseConstants.Login,
                    ServerName      = DefaultDatabaseConstants.ServerName,
                    PasswordDB      = Rijndael.EncryptStringToBytes(DefaultDatabaseConstants.Password)
                }
            };

            _projectModel.ConnectionDbs    = connect;
            _projectModel.IdCurrentProject = proj[0].ProjectID;
            _projectModel.Name             = proj[0].ProjectName;
            _projectModel.Description      = proj[0].ProjectDescription;
            _projectModel.Projects         = proj;

            var sqlConnection =
                $"Data source= {connect[0].ServerName}; Initial catalog= {connect[0].DatabaseName}; UID= {connect[0].LoginDB}; Password= {"Instance@1"};";

            ViewBag.ConnectionString = sqlConnection;
            return(_projectModel);
        }
        public string GetGridModel(string query, int idCurrentProject)
        {
            ConnectionDB connect;

            if (User.Identity.IsAuthenticated)
            {
                var connectionsCurrentProject = _serviceConnection.GetConnectionDBs(idCurrentProject);
                connect = connectionsCurrentProject.FirstOrDefault();
            }
            else
            {
                connect = new ConnectionDB
                {
                    DatabaseName = DefaultDatabaseConstants.DatabaseName,
                    LoginDB      = DefaultDatabaseConstants.Login,
                    ServerName   = DefaultDatabaseConstants.ServerName,
                    PasswordDB   = Rijndael.EncryptStringToBytes(DefaultDatabaseConstants.Password)
                };
            }

            var dataTable = new DataTable();

            if (connect != null)
            {
                var connectionString = $"Data source= {connect.ServerName};Initial catalog= {connect.DatabaseName}; UID= {connect.LoginDB}; Password= {Rijndael.DecryptStringFromBytes(connect.PasswordDB)};";

                var resultQuery = SqlExecuteData.SqlReturnDataFromQuery(query, connectionString);

                if (!resultQuery.HasError)
                {
                    dataTable = resultQuery.ResultData;
                }
                else
                {
                    return(JsonConvert.SerializeObject(resultQuery.ErrorText));
                }
            }

            Session["datatableForGrid"] = dataTable;

            var header = (from DataColumn column in dataTable.Columns
                          select new DataGridModel
            {
                Name = column.ColumnName,
                Index = column.ColumnName,
                Sortable = true,
                Align = "center"
            }).ToList();

            if (User.Identity.IsAuthenticated)
            {
                _queryHistoryModel.QueryDate = DateTime.Now;
                _queryHistoryModel.QueryBody = query;
                _queryHistoryModel.ProjectID = idCurrentProject;

                var newQuery = Mapper.Map <QueryHistoryViewModel, QueryHistory>(_queryHistoryModel);
                _serviceQueryHistory.SaveQueryHistory(newQuery);
            }

            return(JsonConvert.SerializeObject(header));
        }