public void CleanStorageTest()
        {
            // Add some records to all collections
              var app = new Application {Title = "App1"};
              app = Provider.CreateApplicaton(app);

              var person = new Person {Login = "******", Title = "User Clever"};
              person = Provider.CreatePerson(person);

              var module = new Module {AppId = app.Id, Title = "Module1"};
              module = Provider.CreateModule(module);

              var subModule = new SubModule {ModuleId = module.Id, Title = "SubModule1"};
              subModule = Provider.CreateSubModule(subModule);

              var release = new Release {AppId = app.Id, Title = "Release1"};
              release = Provider.CreateRelease(release);

              var revision = new Revision
                       {
                         AppId = app.Id,
                         BugNumber = 10,
                         Rev = 1,
                         Date = DateTime.Now,
                         Type = BugType.Bug,
                         FoundReleaseId = release.Id,
                         TargetReleaseId = release.Id,
                         Severity = BugSeverity.Critical,
                         Priority = 1,
                         Status = BugStatus.Open,
                         ContributorId = person.Id,
                         ModuleId = module.Id,
                         SubModuleId = subModule.Id,
                         Summary = "Summary text"
                       };

              Provider.CreateRevision(revision);

              // Check that everything is added to storage
              Assert.AreNotEqual(0, Provider.GetApplications().Length);
              Assert.AreNotEqual(0, Provider.GetModules(app.Id).Length);
              Assert.AreNotEqual(0, Provider.GetSubModules(module.Id).Length);
              Assert.AreNotEqual(0, Provider.GetStaff().Length);
              //      Assert.AreNotEqual(0, Provider.GetBugs().Length);
              Assert.AreNotEqual(0, Provider.GetRevisions(10).Length);
              //      Assert.AreNotEqual(0, Provider.GetReleases().Length);

              // Clean storage
              Provider.CleanStorage();
              // And check that it is cleared
              Assert.AreEqual(0, Provider.GetApplications().Length);
              Assert.AreEqual(0, Provider.GetModules(app.Id).Length);
              Assert.AreEqual(0, Provider.GetSubModules(module.Id).Length);
              Assert.AreEqual(0, Provider.GetStaff().Length);
              //      Assert.AreEqual(0, Provider.GetBugs().Length);
              Assert.AreEqual(0, Provider.GetRevisions(10).Length);
              //      Assert.AreEqual(0, Provider.GetReleases().Length);
        }
 private void OnTargetReleasesListBox_SelectionChanged(object sender,
                                                       System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (appsListBox.SelectedIndex != -1)
     {
         Application app = (Application)appsListBox.SelectedValue;
         // Request all releases
         Release[] releases = m_provider.GetReleases(app.Id);
         // And show
         targetReleasesListBox.ItemsSource       = releases;
         targetReleasesListBox.DisplayMemberPath = "Title";
     }
 }
        /// <summary>
        /// Returns application by ID.
        /// </summary>
        public DTO.Application GetApplication(int appId)
        {
            EDM.Application appEDM;
            using (DbManager db = new DbManager())
            {
                appEDM = db.SetCommand(
                    @"SELECT * FROM Applications WHERE app_id = @AppId",
                    db.InputParameter("@AppId", appId)).
                         ExecuteObject <EDM.Application>();
            }

            // Copy EDMs to DTOs
            DTO.Application appDTO = s_appCopier.Copy(appEDM);

            return(appDTO);
        }
        ////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates new application.
        /// </summary>
        public DTO.Application CreateApplicaton(DTO.Application appDTO)
        {
            // Map DTO to EDM
            EDM.Application appEDM = s_appCopier.Copy(appDTO);

            // Insert application
            using (DbManager db = new DbManager())
            {
                db.SetCommand(
                    @"
          INSERT INTO Applications (app_title) VALUES (@app_title) 
          SELECT Cast(SCOPE_IDENTITY() as int) app_id",
                    db.CreateParameters(appEDM, new[] { "app_id" }, null, null)).
                ExecuteObject(appEDM);
            }

            // Map EDM to DTO
            appDTO = s_appCopier.Copy(appEDM);

            return(appDTO);
        }
        public void CreateApplicatonTest()
        {
            const string appTitle = "TestApp";

              var app = new Application {Title = appTitle};
              Application actual = Provider.CreateApplicaton(app);
              Assert.IsNotNull(actual);
              Assert.AreNotEqual(0, actual.Id);
              Assert.AreEqual(appTitle, actual.Title);
        }
        public void GetSubModulesTest()
        {
            const string title1 = "SubModule1";
              const string title2 = "SubModule2";
              const string title3 = "SubModule3";

              var app = new Application { Title = "App1" };
              app = Provider.CreateApplicaton(app);

              var module1 = new Module { AppId = app.Id, Title = "Module1" };
              module1 = Provider.CreateModule(module1);
              var module2 = new Module { AppId = app.Id, Title = "Module2" };
              module2 = Provider.CreateModule(module2);

              Provider.CreateSubModule(
            new SubModule { ModuleId = module1.Id, Title = title1 });
              Provider.CreateSubModule(
            new SubModule { ModuleId = module1.Id, Title = title2 });
              Provider.CreateSubModule(
            new SubModule { ModuleId = module2.Id, Title = title2 });
              Provider.CreateSubModule(
            new SubModule { ModuleId = module2.Id, Title = title3 });

              var actual = Provider.GetSubModules(module2.Id);

              Assert.IsNotNull(actual);
              Assert.AreEqual(2, actual.Length);
              Assert.AreNotEqual(0, actual[0].Id);
              Assert.AreEqual(module2.Id, actual[0].ModuleId);
              Assert.AreEqual(title2, actual[0].Title);
              Assert.AreNotEqual(0, actual[1].Id);
              Assert.AreEqual(module2.Id, actual[1].ModuleId);
              Assert.AreEqual(title3, actual[1].Title);
        }
        public void GetRevisionsTest()
        {
            // Add some records to all collections
              var app = new Application { Title = "App1" };
              app = Provider.CreateApplicaton(app);

              var contributor = new Person { Login = "******", Title = "Contributor" };
              contributor = Provider.CreatePerson(contributor);

              var leader = new Person { Login = "******", Title = "Leader" };
              leader = Provider.CreatePerson(leader);

              var dev = new Person { Login = "******", Title = "Developer" };
              dev = Provider.CreatePerson(dev);

              var tester = new Person { Login = "******", Title = "QM" };
              tester = Provider.CreatePerson(tester);

              var module = new Module { AppId = app.Id, Title = "Module1" };
              module = Provider.CreateModule(module);

              var subModule = new SubModule { ModuleId = module.Id, Title = "SubModule1" };
              subModule = Provider.CreateSubModule(subModule);

              var release = new Release { AppId = app.Id, Title = "Release1" };
              release = Provider.CreateRelease(release);

              var revision1 = Provider.CreateRevision(
            new Revision
              {
            AppId = app.Id,
            BugNumber = 10,
            Rev = 1,
            Date = DateTime.Now,
            Type = BugType.Bug,
            FoundReleaseId = release.Id,
            TargetReleaseId = release.Id,
            Severity = BugSeverity.Critical,
            Priority = 1,
            Status = BugStatus.Open,
            ContributorId = contributor.Id,
            ModuleId = module.Id,
            SubModuleId = subModule.Id,
            Summary = "Summary text"
              });

              var revision2 = Provider.CreateRevision(
            new Revision
              {
            AppId = app.Id,
            BugNumber = 10,
            Rev = 2,
            Date = DateTime.Now.Date,
            Type = BugType.Bug,
            FoundReleaseId = release.Id,
            TargetReleaseId = release.Id,
            Severity = BugSeverity.Critical,
            Priority = 1,
            Status = BugStatus.Verified,
            ContributorId = contributor.Id,
            TeamLeaderId = leader.Id,
            DeveloperId = dev.Id,
            TesterId = tester.Id,
            ModuleId = module.Id,
            SubModuleId = subModule.Id,
            Summary = "Summary text 2"
              });

              Provider.CreateRevision(
            new Revision
              {
            AppId = app.Id,
            BugNumber = 12,
            Rev = 1,
            Date = DateTime.Now.Date,
            Type = BugType.Bug,
            Status = BugStatus.Open,
            ContributorId = contributor.Id,
            Summary = "Summary text 2"
              });

              var revisions = Provider.GetRevisions(10);

              Assert.IsNotNull(revisions);
              Assert.AreEqual(2, revisions.Length);
              Assert.AreEqual(revision1, revisions[0]);
              Assert.AreEqual(revision2, revisions[1]);
        }
        public void GetReleasesTest()
        {
            var app = new Application {Title = "App1"};
              app = Provider.CreateApplicaton(app);

              Release release1 = Provider.CreateRelease(new Release {AppId = app.Id, Title = "Release1"});
              Release release2 = Provider.CreateRelease(new Release {AppId = app.Id, Title = "Release2"});

              Release[] actual = Provider.GetReleases(app.Id);

              Assert.IsNotNull(actual);
              Assert.AreEqual(2, actual.Length);
              Assert.AreNotEqual(0, actual[0].Id);
              Assert.AreEqual(release1.Title, actual[0].Title);
              Assert.AreNotEqual(0, actual[1].Id);
              Assert.AreEqual(release2.Title, actual[1].Title);
        }
        public void GetModulesTest()
        {
            var app1 = new Application {Title = "App1"};
              app1 = Provider.CreateApplicaton(app1);

              Provider.CreateModule(new Module {AppId = app1.Id, Title = "Module1"});
              Provider.CreateModule(new Module {AppId = app1.Id, Title = "Module2"});

              var app2 = new Application {Title = "App2"};
              app2 = Provider.CreateApplicaton(app2);
              Module module3 = Provider.CreateModule(new Module {AppId = app2.Id, Title = "Module1"});
              Module module4 = Provider.CreateModule(new Module {AppId = app2.Id, Title = "Module4"});

              Module[] actual = Provider.GetModules(app2.Id);

              Assert.IsNotNull(actual);
              Assert.AreEqual(2, actual.Length);
              Assert.AreNotEqual(0, actual[0].Id);
              Assert.AreEqual(app2.Id, actual[0].AppId);
              Assert.AreEqual(module3.Title, actual[0].Title);
              Assert.AreNotEqual(0, actual[1].Id);
              Assert.AreEqual(app2.Id, actual[1].AppId);
              Assert.AreEqual(module4.Title, actual[1].Title);
        }
        public void GetApplicationsTest()
        {
            const string appTitle1 = "TestApp1";
              const string appTitle2 = "TestApp2";

              // Create application
              var app1 = new Application {Title = appTitle1};
              app1 = Provider.CreateApplicaton(app1);
              var app2 = new Application {Title = appTitle2};
              app2 = Provider.CreateApplicaton(app2);

              Application[] actual = Provider.GetApplications();
              Assert.IsNotNull(actual);
              Assert.AreEqual(2, actual.Length);
              Assert.IsNotNull(actual[0]);
              Assert.IsNotNull(actual[1]);
              Assert.AreEqual(appTitle1, actual[0].Title);
              Assert.AreEqual(app1.Id, actual[0].Id);
              Assert.AreEqual(appTitle2, actual[1].Title);
              Assert.AreEqual(app2.Id, actual[1].Id);
        }
        public void CreateSubModuleTest()
        {
            const string title = "SubModule1";

              var app = new Application { Title = "App1" };
              app = Provider.CreateApplicaton(app);

              var module = new Module { AppId = app.Id, Title = "Module1" };
              module = Provider.CreateModule(module);

              var subModule = new SubModule { ModuleId = module.Id, Title = title };
              var actual = Provider.CreateSubModule(subModule);

              Assert.IsNotNull(actual);
              Assert.AreNotEqual(0, actual.Id);
              Assert.AreEqual(module.Id, actual.ModuleId);
              Assert.AreEqual(title, actual.Title);
        }
        public void CreateRevisionTest()
        {
            // Add some records to all collections
              var app = new Application { Title = "App1" };
              app = Provider.CreateApplicaton(app);

              var contributor = new Person { Login = "******", Title = "Contributor" };
              contributor = Provider.CreatePerson(contributor);

              var leader = new Person { Login = "******", Title = "Leader" };
              leader = Provider.CreatePerson(leader);

              var dev = new Person { Login = "******", Title = "Developer" };
              dev = Provider.CreatePerson(dev);

              var tester = new Person { Login = "******", Title = "QM" };
              tester = Provider.CreatePerson(tester);

              var module = new Module { AppId = app.Id, Title = "Module1" };
              module = Provider.CreateModule(module);

              var subModule = new SubModule { ModuleId = module.Id, Title = "SubModule1" };
              subModule = Provider.CreateSubModule(subModule);

              var release = new Release { AppId = app.Id, Title = "Release1" };
              release = Provider.CreateRelease(release);

              var revision1 = new Revision
              {
            AppId = app.Id,
            BugNumber = 10,
            Rev = 1,
            Date = DateTime.Now,
            Type = BugType.Bug,
            FoundReleaseId = release.Id,
            TargetReleaseId = release.Id,
            Severity = BugSeverity.Critical,
            Priority = 1,
            Status = BugStatus.Open,
            ContributorId = contributor.Id,
            ModuleId = module.Id,
            SubModuleId = subModule.Id,
            Summary = "Summary text"
              };

              var actual1 = Provider.CreateRevision(revision1);

              Assert.IsNotNull(actual1);
              Assert.AreEqual(app.Id, actual1.AppId);
              Assert.AreEqual(10, actual1.BugNumber);
              Assert.AreEqual(1, actual1.Rev);
              Assert.AreEqual(revision1.Date, actual1.Date);
              Assert.AreEqual(BugType.Bug, actual1.Type);
              Assert.AreEqual(release.Id, actual1.FoundReleaseId);
              Assert.AreEqual(release.Id, actual1.TargetReleaseId);
              Assert.AreEqual(1, actual1.Priority);
              Assert.AreEqual(BugSeverity.Critical, actual1.Severity);
              Assert.AreEqual(BugStatus.Open, actual1.Status);
              Assert.AreEqual(contributor.Id, actual1.ContributorId);
              Assert.IsFalse(actual1.TeamLeaderId.HasValue);
              Assert.IsFalse(actual1.DeveloperId.HasValue);
              Assert.IsFalse(actual1.TesterId.HasValue);
              Assert.AreEqual(module.Id, actual1.ModuleId);
              Assert.AreEqual(subModule.Id, actual1.SubModuleId);
              Assert.AreEqual(revision1.Summary, actual1.Summary);

              var revision2 = new Revision
              {
            AppId = app.Id,
            BugNumber = 10,
            Rev = 2,
            Date = DateTime.Now,
            Type = BugType.Bug,
            FoundReleaseId = release.Id,
            TargetReleaseId = release.Id,
            Severity = BugSeverity.Critical,
            Priority = 1,
            Status = BugStatus.Verified,
            ContributorId = contributor.Id,
            TeamLeaderId = leader.Id,
            DeveloperId = dev.Id,
            TesterId = tester.Id,
            ModuleId = module.Id,
            SubModuleId = subModule.Id,
            Summary = "Summary text 2"
              };

              var actual2 = Provider.CreateRevision(revision2);

              Assert.IsNotNull(actual2);
              Assert.AreEqual(app.Id, actual2.AppId);
              Assert.AreEqual(10, actual2.BugNumber);
              Assert.AreEqual(2, actual2.Rev);
              Assert.AreEqual(revision2.Date, actual2.Date);
              Assert.AreEqual(BugType.Bug, actual2.Type);
              Assert.AreEqual(release.Id, actual2.FoundReleaseId);
              Assert.AreEqual(release.Id, actual2.TargetReleaseId);
              Assert.AreEqual(1, actual2.Priority);
              Assert.AreEqual(BugSeverity.Critical, actual2.Severity);
              Assert.AreEqual(BugStatus.Verified, actual2.Status);
              Assert.AreEqual(contributor.Id, actual2.ContributorId);
              Assert.AreEqual(leader.Id, actual2.TeamLeaderId);
              Assert.AreEqual(dev.Id, actual2.DeveloperId);
              Assert.AreEqual(tester.Id, actual2.TesterId);
              Assert.AreEqual(module.Id, actual2.ModuleId);
              Assert.AreEqual(subModule.Id, actual2.SubModuleId);
              Assert.AreEqual(revision2.Summary, actual2.Summary);
        }
        public void CreateReleaseTest()
        {
            var app = new Application {Title = "App1"};
              app = Provider.CreateApplicaton(app);

              var release = new Release {AppId = app.Id, Title = "Release1"};
              Release actual = Provider.CreateRelease(release);

              Assert.IsNotNull(actual);
              Assert.AreNotEqual(0, actual.Id);
              Assert.AreEqual(release.Title, actual.Title);
        }
        public void CreateModuleTest()
        {
            var app = new Application {Title = "App1"};
              app = Provider.CreateApplicaton(app);

              var module = new Module {AppId = app.Id, Title = "Module1"};
              Module actual = Provider.CreateModule(module);

              Assert.IsNotNull(actual);
              Assert.AreNotEqual(0, actual.Id);
              Assert.AreEqual(module.AppId, actual.AppId);
              Assert.AreEqual(module.Title, actual.Title);
        }