public ActionResult AddProject(AddProjectModel addProject)
        {
            if (null == addProject)
                return View("Error");

            var name = addProject.Name;

            if (string.IsNullOrWhiteSpace(name))
                return View("Error");

            var desc = addProject.Description;
            if (string.IsNullOrWhiteSpace(desc))
                desc = null;

            using (var db = new BuildVersioningDataContext())
            {
                if (db.Projects.Any(p => string.Compare(p.Name, name, StringComparison.OrdinalIgnoreCase) == 0))
                    return View("Error"); // <-- A project with the same name already exists.

                var project =
                    new Project
                    {
                        Name = name,
                        Description = desc,
                        BuildNumber = 0,
                        DateBuildNumberUpdated = DateTime.Now
                    };

                db.Projects.Add(project);
                db.SaveChanges();
            }

            return RedirectToRoute("ListProjects");
        }
        public ActionResult DeleteProject(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
                return View("Error", new ErrorInfo("Project", "DeleteProject", "The project name is null, empty or contains only whitespace which is not allowed."));

            using (var db = new BuildVersioningDataContext())
            {
                var project = db.Projects
                    .Include(p => p.ProjectConfigs)
                    .SingleOrDefault(p =>
                        string.Compare(p.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                        );

                if (null == project)
                    return RedirectToRoute("ListProjects");

                var projectConfigIds = project.ProjectConfigs.Select(c => c.Id).ToList();

                // Delete all child project configs.
                foreach (var projectConfigId in projectConfigIds)
                {
                    var projectConfig = db.ProjectConfigs.SingleOrDefault(c => c.Id == projectConfigId);
                    if (null != projectConfig)
                        db.ProjectConfigs.Remove(projectConfig);
                }

                // Delete the project.
                db.Projects.Remove(project);
                db.SaveChanges();
            }

            return RedirectToRoute("ListProjects");
        }
        public ActionResult AddProjectConfig(string projectName)
        {
            if (string.IsNullOrWhiteSpace(projectName))
                return View("Error");

            Project project;

            using (var db = new BuildVersioningDataContext())
            {
                project =
                    db.Projects
                        .SingleOrDefault(p =>
                            string.Compare(p.Name, projectName, StringComparison.OrdinalIgnoreCase) == 0
                            );
            }

            if (null == project)
                return View("Error");

            var model =
                new AddProjectConfigModel
                {
                    ParentProjectId = project.Id,
                    ParentProjectName = project.Name
                };
            return View(model);
        }
Beispiel #4
0
        public ActionResult Index()
        {
            List<RecentActivityModel> recentActivities;

            using (var db = new BuildVersioningDataContext())
            {
                recentActivities =
                    db.VersionHistoryItems
                        .OrderByDescending(item => item.Date)
                        .Take(10)
                        .Select(item =>
                            new RecentActivityModel
                            {
                                Date = item.Date,
                                ProjectConfigId = item.ProjectConfigId,
                                ProjectConfigName = item.ProjectConfigName,
                                ProjectId = item.ProjectId,
                                ProjectName = item.ProjectName,
                                Version = item.Version
                            })
                        .ToList();
            }

            var model = new IndexModel { RecentActivities = recentActivities };
            return View(model);
        }
        public void Can_Execute_Multiple_Times(int iterations)
        {
            var expectedMaxBuildNumber = iterations;

            // Using a set to store each generated build number instead of a list in order to detect duplicates.
            // If an attempt is made to store a duplicate build number in the HashSet instance, an exception will be thrown and the test will fail.
            var set = new HashSet<int>();

            var stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < iterations; ++i)
            {
                var buildNumber = Can_Execute_Test();
                set.Add(buildNumber);
                Thread.Sleep(1); // <-- Used to smooth out race conditions regarding the Date property whereby fast machines can get the date out of order.
            }

            stopwatch.Stop();

            Console.WriteLine("Completed 100 iterations in {0} milliseconds.", stopwatch.ElapsedMilliseconds);

            var list = set.ToList();
            list.ForEach(bn => Console.WriteLine("Build Number: {0}", bn));

            // Assert for the whole set.
            int maxBuildNumber;

            using (var db = new BuildVersioningDataContext(GetConfiguredConnectionString()))
            {
                maxBuildNumber = db.VersionHistoryItems.Max(vhi => vhi.BuildNumber);
            }

            // If there are any duplicates, the max expected build number could not be generated.
            maxBuildNumber.ShouldEqual(expectedMaxBuildNumber);
        }
Beispiel #6
0
        protected Project GetTestProject(string connectionString = null)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
                connectionString = GetConfiguredConnectionString();

            using (var db = new BuildVersioningDataContext(connectionString))
            {
                return db.Projects.SingleOrDefault(p => p.Name == TestProjectName);
            }
        }
        public void Can_Execute_100_Times_For_Each_Of_5_Worker_Threads_With_Random_Short_Thread_Sleep_For_Each_Iteration_In_Each_Worker_Thread()
        {
            _manualResetEvent.Reset();
            var threads =
                new[]
                {
                    new Thread(WorkerThreadAction) { IsBackground = true },
                    new Thread(WorkerThreadAction) { IsBackground = true },
                    new Thread(WorkerThreadAction) { IsBackground = true },
                    new Thread(WorkerThreadAction) { IsBackground = true },
                    new Thread(WorkerThreadAction) { IsBackground = true }
                }.ToList();

            threads.ForEach(t => t.Start());

            _manualResetEvent.Set();

            threads.ForEach(t => t.Join(90000));

            _manualResetEvent.Reset();

            // Assert for the whole set.
            var expectedMaxBuildNumber = 100 * threads.Count;

            int maxBuildNumber;

            using (var db = new BuildVersioningDataContext(GetConfiguredConnectionString()))
            {
                maxBuildNumber = db.VersionHistoryItems.Max(vhi => vhi.BuildNumber);
            }

            // If there are any duplicates, the max expected build number could not be generated.
            maxBuildNumber.ShouldEqual(expectedMaxBuildNumber);

            // Assert for the project's current build number.
            var project = GetTestProject();
            project.BuildNumber.ShouldEqual(expectedMaxBuildNumber);
        }
        public ActionResult EditProjectConfig(string projectName, string name)
        {
            if (string.IsNullOrWhiteSpace(projectName))
                return View("Error");

            if (string.IsNullOrWhiteSpace(name))
                return View("Error");

            ProjectConfig projectConfig;

            using (var db = new BuildVersioningDataContext())
            {
                projectConfig =
                    db.ProjectConfigs
                        .Include(c => c.Project)
                        .SingleOrDefault(c =>
                            string.Compare(c.Project.Name, projectName, StringComparison.OrdinalIgnoreCase) == 0 &&
                            string.Compare(c.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                            );
            }

            if (null == projectConfig)
                return View("Error");

            var generatedBuildNumberPosition = projectConfig.GeneratedBuildNumberPosition;

            BuildNumberPositions buildNumberPosition;
            switch (generatedBuildNumberPosition)
            {
                case 3:
                    buildNumberPosition = BuildNumberPositions.Three;
                    break;

                case 4:
                    buildNumberPosition = BuildNumberPositions.Four;
                    break;

                default:
                    return View("Error");
            }

            var model =
                new EditProjectConfigModel
                {
                    BuildNumberPosition = buildNumberPosition,
                    Description = projectConfig.Description,
                    GeneratedBuildNumberPosition = projectConfig.GeneratedBuildNumberPosition,
                    GeneratedVersionPart1 = projectConfig.GeneratedVersionPart1,
                    GeneratedVersionPart2 = projectConfig.GeneratedVersionPart2,
                    GeneratedVersionPart3 = projectConfig.GeneratedVersionPart3,
                    GeneratedVersionPart4 = projectConfig.GeneratedVersionPart4,
                    Id = projectConfig.Id,
                    Name = name,
                    OriginalName = name,
                    ProductVersionPart1 = projectConfig.ProductVersionPart1,
                    ProductVersionPart2 = projectConfig.ProductVersionPart2,
                    ProductVersionPart3 = projectConfig.ProductVersionPart3,
                    ProductVersionPart4 = projectConfig.ProductVersionPart4,
                    ParentProjectId = projectConfig.Project.Id,
                    ParentProjectName = projectConfig.Project.Name,
                    ReleaseType = projectConfig.ReleaseType
                };
            return View(model);
        }
Beispiel #9
0
        private static void DeleteTestProjectAndTestProjectConfig(BuildVersioningDataContext db)
        {
            var projectExists = db.Projects.Any(p => p.Name == TestProjectName);

            if (projectExists)
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {

                        #region " Delete Test VersionHistoryItems SQL "

                        var sql = string.Format(@"DELETE FROM [dbo].[VersionHistory]
            WHERE [ProjectConfigId] IN (
            SELECT PC.[Id]
            FROM [dbo].[ProjectConfig] PC
            INNER JOIN [dbo].[Project] P ON PC.[ProjectId] = P.[Id]
            WHERE P.[Name] = N'{0}'
            );", TestProjectName);

                        #endregion

                        db.Database.ExecuteSqlCommand(sql);

                        sql = string.Format("DELETE FROM [dbo].[ProjectConfig] WHERE [ProjectId] = (SELECT [Id] FROM [dbo].[Project] WHERE [Name] = N'{0}');", TestProjectName);
                        db.Database.ExecuteSqlCommand(sql);

                        sql = string.Format("DELETE FROM [dbo].[Project] WHERE [Name] = N'{0}';", TestProjectName);
                        db.Database.ExecuteSqlCommand(sql);

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
        public ActionResult EditProjectConfig(string projectName, string name, EditProjectConfigModel editProjectConfig)
        {
            if (null == editProjectConfig)
                return View("Error");

            // Validate id (the ProjectConfig.Id to be edited)
            var id = editProjectConfig.Id;
            if (id < 1)
                return View("Error");

            // Validate ParentProjectId
            var parentProjectId = editProjectConfig.ParentProjectId;
            if (parentProjectId < 1)
                return View("Error");

            // Validate ParentProjectName
            var parentProjectName = editProjectConfig.ParentProjectName;
            if (string.IsNullOrWhiteSpace(parentProjectName))
                return View("Error");

            // Validate Name
            var newName = editProjectConfig.Name;
            if (string.IsNullOrWhiteSpace(name))
                return View("Error");

            var desc = editProjectConfig.Description;
            if (string.IsNullOrWhiteSpace(desc))
                desc = null;

            var buildNumberPostion = (int)editProjectConfig.BuildNumberPosition;
            if (buildNumberPostion < 3 || buildNumberPostion > 4)
                return View("Error");

            // Force the GeneratedVersion part that corresponds to the build number position to a value of zero.
            switch (buildNumberPostion)
            {
                case 3:
                    editProjectConfig.GeneratedVersionPart3 = 0;
                    break;
                case 4:
                    editProjectConfig.GeneratedVersionPart4 = 0;
                    break;
            }

            using (var db = new BuildVersioningDataContext())
            {
                if (name != newName && db.ProjectConfigs
                    .Include(c => c.Project)
                    .Any(c =>
                        c.Project.Id == parentProjectId &&
                        string.Compare(c.Name, newName, StringComparison.OrdinalIgnoreCase) == 0
                        ))
                    return View("Error"); // <-- A ProjectConfig with the same parent Project and the same name already exists.

                var projectConfig =
                    db.ProjectConfigs
                        .Include(c => c.Project)
                        .SingleOrDefault(c =>
                            c.Project.Id == parentProjectId &&
                            c.Id == id
                            );

                if (null == projectConfig)
                    return View("Error");

                projectConfig.Description = desc;
                projectConfig.GeneratedBuildNumberPosition = buildNumberPostion;
                projectConfig.GeneratedVersionPart1 = editProjectConfig.GeneratedVersionPart1;
                projectConfig.GeneratedVersionPart2 = editProjectConfig.GeneratedVersionPart2;
                projectConfig.GeneratedVersionPart3 = editProjectConfig.GeneratedVersionPart3;
                projectConfig.GeneratedVersionPart4 = editProjectConfig.GeneratedVersionPart4;
                projectConfig.Name = newName;
                projectConfig.ProductVersionPart1 = editProjectConfig.ProductVersionPart1;
                projectConfig.ProductVersionPart2 = editProjectConfig.ProductVersionPart2;
                projectConfig.ProductVersionPart3 = editProjectConfig.ProductVersionPart3;
                projectConfig.ProductVersionPart4 = editProjectConfig.ProductVersionPart4;
                projectConfig.ReleaseType = editProjectConfig.ReleaseType;

                db.SaveChanges();
            }

            return RedirectToRoute("ViewProjectConfig", new { projectName = parentProjectName, name });
        }
        public ActionResult EditProject(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
                return View("Error", new ErrorInfo("Project", "EditProject", "The project name is null, empty or contains only whitespace which is not allowed."));

            Project project;

            using (var db = new BuildVersioningDataContext())
            {
                project = db.Projects
                    .SingleOrDefault(p =>
                        string.Compare(p.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                        );
            }

            if (null == project)
                return View("Error");

            var model =
                new EditProjectModel
                {
                    BuildNumber = project.BuildNumber,
                    Description = project.Description,
                    Id = project.Id,
                    Name = project.Name
                };
            return View(model);
        }
        public ActionResult ViewProject(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
                return View("Error", new ErrorInfo("Project", "ViewProject", "The project name is null, empty or contains only whitespace which is not allowed."));

            Project project;

            using (var db = new BuildVersioningDataContext())
            {
                project = db.Projects
                    .Include(p => p.ProjectConfigs)
                    .SingleOrDefault(p =>
                        string.Compare(p.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                        );
            }

            if (null == project)
                return View("Error");

            var model = new ProjectModel { Project = project };
            return View(model);
        }
        public ActionResult ListProjectConfigsByProject(string projectName)
        {
            List<ProjectConfig> projectConfigs;

            using (var db = new BuildVersioningDataContext())
            {
                projectConfigs = db.ProjectConfigs
                    .Include(c => c.Project)
                    .Where(c =>
                        string.Compare(c.Project.Name, projectName, StringComparison.OrdinalIgnoreCase) == 0
                        )
                    .OrderBy(c => c.Name).ToList();
            }

            var model = new ProjectConfigsModel { ProjectConfigs = projectConfigs };
            return View(model);
        }
        public ActionResult ListProjects()
        {
            List<Project> projects;

            using (var db = new BuildVersioningDataContext())
            {
                projects = db.Projects.OrderBy(p => p.Name).ToList();
            }

            var model = new ProjectsModel { Projects = projects };
            return View(model);
        }
        public ActionResult DeleteProjectConfig(string projectName, string name)
        {
            if (string.IsNullOrWhiteSpace(projectName))
                return View("Error");

            if (string.IsNullOrWhiteSpace(name))
                return View("Error");

            using (var db = new BuildVersioningDataContext())
            {
                var projectConfig = db.ProjectConfigs
                    .Include(c => c.Project)
                    .SingleOrDefault(c =>
                        string.Compare(c.Project.Name, projectName, StringComparison.OrdinalIgnoreCase) == 0 &&
                        string.Compare(c.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                    );

                if (null == projectConfig)
                    return RedirectToRoute("ViewProject", new { name = projectName });

                db.ProjectConfigs.Remove(projectConfig);
                db.SaveChanges();
            }

            return RedirectToRoute("ViewProject", new { name = projectName });
        }
        public ActionResult PrepareToDeleteProjectConfig(string projectName, string name)
        {
            if (string.IsNullOrWhiteSpace(projectName))
                return View("Error");

            if (string.IsNullOrWhiteSpace(name))
                return View("Error");

            ProjectConfig projectConfig;

            using (var db = new BuildVersioningDataContext())
            {
                projectConfig =
                    db.ProjectConfigs
                        .Include(c => c.Project)
                        .SingleOrDefault(c =>
                            string.Compare(c.Project.Name, projectName, StringComparison.OrdinalIgnoreCase) == 0 &&
                            string.Compare(c.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                            );
            }

            if (null == projectConfig)
                return RedirectToRoute("ViewProject", new { name = projectName });

            var model = new PrepareToDeleteProjectConfigModel { ProjectConfig = projectConfig };
            return View(model);
        }
        public ActionResult AddProjectConfig(AddProjectConfigModel addProjectConfig)
        {
            if (null == addProjectConfig)
                return View("Error");

            // Validate ParentProjectId
            var parentProjectId = addProjectConfig.ParentProjectId;
            if (parentProjectId < 1)
                return View("Error");

            // Validate ParentProjectName
            var parentProjectName = addProjectConfig.ParentProjectName;
            if (string.IsNullOrWhiteSpace(parentProjectName))
                return View("Error");

            // Validate Name
            var name = addProjectConfig.Name;
            if (string.IsNullOrWhiteSpace(name))
                return View("Error");

            var desc = addProjectConfig.Description;
            if (string.IsNullOrWhiteSpace(desc))
                desc = null;

            var buildNumberPostion = (int)addProjectConfig.BuildNumberPosition;
            if (buildNumberPostion < 3 || buildNumberPostion > 4)
                return View("Error");

            // Force the GeneratedVersion part that corresponds to the build number position to a value of zero.
            switch (buildNumberPostion)
            {
                case 3:
                    addProjectConfig.GeneratedVersionPart3 = 0;
                    break;
                case 4:
                    addProjectConfig.GeneratedVersionPart4 = 0;
                    break;
            }

            using (var db = new BuildVersioningDataContext())
            {
                if (db.ProjectConfigs
                    .Include(c => c.Project)
                    .Any(c =>
                        c.Project.Id == parentProjectId &&
                        string.Compare(c.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                        ))
                    return View("Error"); // <-- A ProjectConfig with the same parent Project and the same name already exists.

                var projectConfig =
                    new ProjectConfig
                    {
                        Description = desc,
                        GeneratedBuildNumberPosition = buildNumberPostion,
                        GeneratedVersionPart1 = addProjectConfig.GeneratedVersionPart1,
                        GeneratedVersionPart2 = addProjectConfig.GeneratedVersionPart2,
                        GeneratedVersionPart3 = addProjectConfig.GeneratedVersionPart3,
                        GeneratedVersionPart4 = addProjectConfig.GeneratedVersionPart4,
                        Name = name,
                        ProductVersionPart1 = addProjectConfig.ProductVersionPart1,
                        ProductVersionPart2 = addProjectConfig.ProductVersionPart2,
                        ProductVersionPart3 = addProjectConfig.ProductVersionPart3,
                        ProductVersionPart4 = addProjectConfig.ProductVersionPart4,
                        ProjectId = parentProjectId,
                        ReleaseType = addProjectConfig.ReleaseType
                    };

                db.ProjectConfigs.Add(projectConfig);
                db.SaveChanges();
            }

            return RedirectToRoute("ViewProject", new { name = parentProjectName });
        }
        public ActionResult ViewProjectConfig(string projectName, string name)
        {
            ProjectConfig projectConfig;

            using (var db = new BuildVersioningDataContext())
            {
                projectConfig = db.ProjectConfigs
                    .Include(c => c.Project)
                    .SingleOrDefault(c =>
                        string.Compare(c.Project.Name, projectName, StringComparison.OrdinalIgnoreCase) == 0 &&
                        string.Compare(c.Name, name, StringComparison.OrdinalIgnoreCase) == 0
                        );
            }

            if (null == projectConfig)
                return View("Error");

            var model = new ProjectConfigModel { ProjectConfig = projectConfig };
            return View(model);
        }
Beispiel #19
0
        protected virtual void Initialize(string connectionString = null)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
                connectionString = GetConfiguredConnectionString();

            using (var db = new BuildVersioningDataContext(connectionString))
            {
                DeleteTestProjectAndTestProjectConfig(db);

                var project =
                    new Project
                    {
                        Name = TestProjectName,
                        BuildNumber = 0,
                        DateBuildNumberUpdated = DateTime.Now
                    };
                db.Projects.Add(project);
                db.SaveChanges();

                var projectConfig =
                    new ProjectConfig
                    {
                        ProjectId = project.Id,
                        Name = TestProjectConfigName,
                        GeneratedBuildNumberPosition = 3,
                        GeneratedVersionPart1 = 1,
                        GeneratedVersionPart2 = 0,
                        GeneratedVersionPart3 = 0,
                        GeneratedVersionPart4 = 0,
                        ProductVersionPart1 = 1,
                        ProductVersionPart2 = 0,
                        ProductVersionPart3 = 0,
                        ProductVersionPart4 = 0,
                        ReleaseType = ReleaseType.PreRelease
                    };
                db.ProjectConfigs.Add(projectConfig);
                db.SaveChanges();
            }
        }
        public ActionResult EditProject(string name, EditProjectModel editProject)
        {
            if (null == editProject)
                return View("Error", new ErrorInfo("Project", "EditProject", "The editProject model is null which is not allowed."));

            var id = editProject.Id;
            if (id < 1)
                return View("Error", new ErrorInfo("Project", "EditProject", "The project id is not valid."));

            var newName = editProject.Name;
            if (string.IsNullOrWhiteSpace(newName))
                return View("Error", new ErrorInfo("Project", "EditProject", "The new project name is null, empty or contains only whitespace which is not allowed."));

            var desc = editProject.Description;
            if (string.IsNullOrWhiteSpace(desc))
                desc = null;

            var buildNumber = editProject.BuildNumber;
            if (buildNumber < 0)
                buildNumber = 0;

            using (var db = new BuildVersioningDataContext())
            {
                if (name != newName && db.Projects.Any(p => string.Compare(p.Name, newName, StringComparison.OrdinalIgnoreCase) == 0))
                    return View("Error", new ErrorInfo("Project", "EditProject", "A project with the specified new name already exists."));

                var project = db.Projects.SingleOrDefault(p => p.Id == id);
                if (null == project)
                    return View("Error", new ErrorInfo("Project", "EditProject", "The specified project id of the project to be edited does not exist."));

                project.Name = newName;
                project.Description = desc;

                if (project.BuildNumber != buildNumber)
                {
                    project.BuildNumber = buildNumber;
                    project.DateBuildNumberUpdated = DateTime.Now;
                }

                db.SaveChanges();
            }

            return RedirectToRoute("ViewProject", new { name });
        }