Example #1
0
        public ActionResult DeleteTestCase(IList <TestCase> rows)
        {
            var testCaseRepo = new TestCaseRepository();

            foreach (var row in rows)
            {
                var testCase = testCaseRepo.GetById(row.Id);

                if (testCase.Evidences != null && testCase.Evidences.Count > 0)
                {
                    var evidenceRepo = new EvidenceRepository();
                    foreach (var evidence in testCase.Evidences)
                    {
                        System.IO.File.Delete(Server.MapPath("~/Uploads/" + evidence.Name + evidence.Extension));
                        evidenceRepo.Delete(evidence);
                    }
                }

                if (testCase.Reviews != null && testCase.Reviews.Count > 0)
                {
                    var reviewsRepo = new ReviewRepository();
                    foreach (var review in testCase.Reviews)
                    {
                        reviewsRepo.Delete(review);
                    }
                }

                testCaseRepo.Delete(testCase);
            }

            TempData["success"] = "Test case/s was deleted!";

            return(View("CompanyTests"));
        }
Example #2
0
        public ActionResult DeleteAttachment(string id, string attachment)
        {
            TestCaseRepository testCaseRepo = new TestCaseRepository();
            EvidenceRepository evidenceRepo = new EvidenceRepository();

            TestCase testCase = testCaseRepo.GetById(Guid.Parse(id));

            if (testCase.Evidences != null && testCase.Evidences.Count > 0)
            {
                foreach (var evidence in testCase.Evidences)
                {
                    if (evidence.Id == Guid.Parse(attachment))
                    {
                        System.IO.File.Delete(Server.MapPath("~/Uploads/" + evidence.Name + evidence.Extension));
                        evidenceRepo.Delete(evidence);
                    }
                }
            }

            SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository();
            IList <SoftwareType>   swTypes    = swTypeRepo.GetAllValid();

            ViewBag.SoftwareTypes = swTypes;

            TestCategoryRepository testCatRepo = new TestCategoryRepository();
            IList <TestCategory>   testCats    = testCatRepo.GetAllValid();

            ViewBag.TestCategories = testCats;

            return(RedirectToAction("EditTestCase", "Tests", new { id = testCase.Id.ToString() }));
        }
Example #3
0
        public static ITestCaseRepository CreateTestCaseRepository()
        {
            var dirPath = MapRepositoryPath("TestCase");
            var result  = new TestCaseRepository(dirPath);

            return(result);
        }
Example #4
0
 public TestCaseRepositoryTest_Create()
 {
     this.createdDirectory     = new Directory();
     this.fileSystemRepository = Mock.Of <IFileSystemRepository>(
         r => r.CreateDirectory(It.IsAny <string>()) == createdDirectory);
     this.testCaseRepository = new TestCaseRepository("Root", fileSystemRepository);
 }
        public ActionResult DeleteAttachedTestCase(string id, string testCaseId)
        {
            TestGroupRepository testGroupRepo = new TestGroupRepository();
            TestCaseRepository  testCaseRepo  = new TestCaseRepository();

            TestGroup testGroup = testGroupRepo.GetById(Guid.Parse(id));

            if (testGroup.TestCases != null && testGroup.TestCases.Count > 0)
            {
                foreach (var tempTestCase in testGroup.TestCases)
                {
                    if (tempTestCase.Id == Guid.Parse(testCaseId))
                    {
                        testGroup.TestCases.Remove(tempTestCase);
                        break;
                    }
                }

                testGroup.SkillDificulty = testGroup.CountSkillDificulty();
                testGroup.TimeDificulty  = testGroup.CountTimeDificulty();
                testGroupRepo.Update(testGroup);

                TestCase testCase = testCaseRepo.GetById(Guid.Parse(testCaseId));

                testCase.IsInGroup = false;
                testCaseRepo.Update(testCase);
            }

            return(RedirectToAction("EditTestGroup", "TestGroups", new { id = testGroup.Id.ToString() }));
        }
        private async Task <Dictionary <int, Defect> > GetAsyncHelper(string sql, DynamicParameters parameters = null)
        {
            TestCaseRepository testCaseRepository = new TestCaseRepository(_connectionString);

            using (var conn = GetOpenConnection())
            {
                var defectDictionary = new Dictionary <int, Defect>();

                var defectHistoryDictionary  = new Dictionary <int, List <int> >();
                var testCaseDefectDictionary = new Dictionary <int, List <int> >();

                await conn.QueryAsync <Defect, DefectHistory, TestCaseDefectMap, Defect>(
                    sql,
                    (defect, defectHistory, testCaseDefectMap) =>
                {
                    Defect defectEntry;

                    if (!defectDictionary.TryGetValue(defect.DefectId, out defectEntry))
                    {
                        defectEntry = defect;
                        if (defectHistory != null && defectHistory.DefectHistoryId != 0)
                        {
                            defectEntry.DefectHistories = new List <DefectHistory>();
                            defectHistoryDictionary.Add(defect.DefectId, new List <int>());
                        }
                        if (testCaseDefectMap != null && testCaseDefectMap.TestCaseDefectId != 0)
                        {
                            defectEntry.TestCases = new List <TestCase>();
                            testCaseDefectDictionary.Add(testCaseDefectMap.DefectId, new List <int>());
                        }
                        defectDictionary.Add(defect.DefectId, defect);
                    }

                    var defectId = defect.DefectId;

                    if (defectHistoryDictionary.ContainsKey(defectId) &&
                        !defectHistoryDictionary[defectId].Contains(defectHistory.DefectHistoryId))
                    {
                        defectEntry.DefectHistories.Add(defectHistory);
                        defectHistoryDictionary[defectId].Add(defectHistory.DefectHistoryId);
                    }

                    if (testCaseDefectDictionary.ContainsKey(defectId) &&
                        !testCaseDefectDictionary[defectId].Contains(testCaseDefectMap.TestCaseDefectId))
                    {
                        TestCase testCase = testCaseRepository.GetAsync(testCaseDefectMap.TestCaseId).Result;
                        defectEntry.TestCases.Add(testCase);

                        testCaseDefectDictionary[defectId].Add(testCaseDefectMap.TestCaseDefectId);
                    }

                    return(defectEntry);
                },
                    parameters,
                    splitOn : "DefectHistoryId, TestCaseDefectId"
                    );

                return(defectDictionary);
            }
        }
Example #7
0
 public TestCaseRepositoryTest_AddExecution()
 {
     this.createdFile          = new File();
     this.fileSystemRepository = Mock.Of <IFileSystemRepository>(
         r => r.CreateFile(It.IsAny <string>(), It.IsAny <string>()) == this.createdFile);
     this.testCaseRepository = new TestCaseRepository("Root", fileSystemRepository);
 }
Example #8
0
        // GET: Public
        public ActionResult Index()
        {
            ViewBag.Title = "TestCrowd";

            ApplicationUserRepository <ApplicationUser> testCrowdUserDao = new ApplicationUserRepository <ApplicationUser>();
            int count = testCrowdUserDao.GetAll().Count;

            TestCaseRepository testCasesRepo = new TestCaseRepository();
            int testCount = testCasesRepo.GetCount();

            ViewBag.Clients = count.ToString();
            ViewBag.Tests   = testCount.ToString();
            return(View());
        }
Example #9
0
        public async Task <ActionResult> TestDetails(Guid testGuid)
        {
            TestCaseRepository testCaseRepo = new TestCaseRepository();
            var testCaseTask = testCaseRepo.GetByIdAsync(testGuid);

            ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>();
            var testerTask = userRepo.GetByUserNameAsync(User.Identity.Name);

            TestsRepository testsRepo = new TestsRepository();

            ViewBag.Takened   = testsRepo.GetTestStatus(await testCaseTask, await testerTask);
            ViewBag.TestsGuid = testsRepo.GetByTestCaseForTester(await testerTask, await testCaseTask);
            return(View(await testCaseTask));
        }
        public ActionResult DeleteTestGroupAll(IList <TestGroup> rows)
        {
            IList <Guid> testCasesId = new List <Guid>();

            foreach (var row in rows)
            {
                var       testGroupRepo = new TestGroupRepository();
                TestGroup testGroup     = testGroupRepo.GetById(row.Id);
                foreach (var testCase in testGroup.TestCases)
                {
                    testCase.IsInGroup = false;
                    testCasesId.Add(testCase.Id);
                }

                testGroupRepo.Update(testGroup);
                testGroupRepo.Delete(testGroup);
            }

            TestCaseRepository testCaseRepo = new TestCaseRepository();

            foreach (var id in testCasesId)
            {
                TestCase testCase = testCaseRepo.GetById(id);

                if (testCase.Evidences != null && testCase.Evidences.Count > 0)
                {
                    var evidenceRepo = new EvidenceRepository();
                    foreach (var evidence in testCase.Evidences)
                    {
                        System.IO.File.Delete(Server.MapPath("~/Uploads/" + evidence.Name + evidence.Extension));
                        evidenceRepo.Delete(evidence);
                    }
                }

                if (testCase.Reviews != null && testCase.Reviews.Count > 0)
                {
                    var reviewsRepo = new ReviewRepository();
                    foreach (var review in testCase.Reviews)
                    {
                        reviewsRepo.Delete(review);
                    }
                }

                testCaseRepo.Delete(testCase);
            }

            TempData["success"] = "Test group/s and tests was deleted!";

            return(View("CompanyTestGroups"));
        }
Example #11
0
        public async Task <ActionResult> TesterTests(int?page, Guid?swTypeGuid, Guid?testCatGuid, string searchTerm)
        {
            TestCaseRepository testCaseRepo = new TestCaseRepository();

            ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>();
            var testerTask = userRepo.GetByUserNameAsync(User.Identity.Name);

            SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository();

            ViewBag.SoftTypes = swTypeRepo.GetAllValid();

            TestCategoryRepository testCatRepo = new TestCategoryRepository();

            ViewBag.TestCategories = testCatRepo.GetAllValid();

            int itemsOnPage = 8;
            int pg          = page ?? 1;
            int startIndex  = (pg * itemsOnPage) - itemsOnPage;

            SoftwareType swType = null;

            if (swTypeGuid != null)
            {
                swType           = swTypeRepo.GetById((Guid)swTypeGuid);
                ViewBag.SoftType = swType;
            }

            TestCategory testCat = null;

            if (testCatGuid != null)
            {
                testCat = testCatRepo.GetById((Guid)testCatGuid);
                ViewBag.TestCategory = testCat;
            }

            ViewBag.CurrentSearch = searchTerm;
            IList <TestCase> testCases = testCaseRepo.GetAvailableEntities(out var totalTests, DateTime.Today, await testerTask, swType, testCat, startIndex, itemsOnPage, searchTerm);

            ViewBag.Pages       = (int)Math.Ceiling((double)totalTests / (double)itemsOnPage);
            ViewBag.CurrentPage = pg;

            if (Request.IsAjaxRequest())
            {
                return(PartialView(testCases));
            }

            return(View(testCases));
        }
Example #12
0
        public ActionResult TestsResaults(int?page, Guid?testCaseGuid, Guid?statusGuid)
        {
            TestsRepository testsRepo = new TestsRepository();

            ApplicationUserRepository <Company> userRepo = new ApplicationUserRepository <Company>();
            Company company = userRepo.GetByUserName(User.Identity.Name);

            TestCaseRepository testCaseRepo = new TestCaseRepository();

            ViewBag.TestCases = testCaseRepo.GetAllForCompany(company);

            TestStatusRepository statusRepo = new TestStatusRepository();

            ViewBag.Statuses = statusRepo.GetAll();

            int itemsOnPage = 20;
            int pg          = page ?? 1;
            int startIndex  = (pg * itemsOnPage) - itemsOnPage;

            TestCase testCase = null;

            if (testCaseGuid != null)
            {
                testCase         = testCaseRepo.GetById((Guid)testCaseGuid);
                ViewBag.TestCase = testCase;
            }

            TestStatus testStatus = null;

            if (statusGuid != null)
            {
                testStatus     = statusRepo.GetById((Guid)statusGuid);
                ViewBag.Status = testStatus;
            }

            IList <DataAccess.Model.Tests.Tests> testses = testsRepo.GetTestsForCompany(company, out int totalTests, out int filteredCount, testCase, testStatus, startIndex, itemsOnPage);

            ViewBag.Pages       = (int)Math.Ceiling((double)totalTests / (double)itemsOnPage);
            ViewBag.CurrentPage = pg;

            if (Request.IsAjaxRequest())
            {
                return(PartialView(testses));
            }

            return(View(testses));
        }
Example #13
0
        public ActionResult DetailTestCaseCompany(string id)
        {
            SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository();
            IList <SoftwareType>   swTypes    = swTypeRepo.GetAllValid();

            ViewBag.SoftwareTypes = swTypes;

            TestCategoryRepository testCatRepo = new TestCategoryRepository();
            IList <TestCategory>   testCats    = testCatRepo.GetAllValid();

            ViewBag.TestCategories = testCats;

            var testCaseRepo = new TestCaseRepository();
            var testCase     = testCaseRepo.GetById(Guid.Parse(id));

            return(View(testCase));
        }
Example #14
0
        public async Task <ActionResult> ResolveTest(Guid testGuid)
        {
            TestCaseRepository testCaseRepo = new TestCaseRepository();
            var testCaseTask = testCaseRepo.GetByIdAsync(testGuid);

            ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>();
            var testerTask = userRepo.GetByUserNameAsync(User.Identity.Name);

            TestsRepository testsRepo = new TestsRepository();
            var             testsTask = testsRepo.GetByTestCaseForTesterAsync(await testerTask, await testCaseTask);

            TestStatusRepository testStatusRepo = new TestStatusRepository();

            ViewBag.TestStatus = testStatusRepo.GetAll();

            return(View(await testsTask));
        }
Example #15
0
        public async Task TakeTest(Guid testGuid)
        {
            TestCaseRepository testCaseRepo = new TestCaseRepository();
            var testCaseTask = testCaseRepo.GetByIdAsync(testGuid);

            ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>();
            var testerTask = userRepo.GetByUserNameAsync(User.Identity.Name);

            DataAccess.Model.Tests.Tests tests = new DataAccess.Model.Tests.Tests();
            tests.Test    = await testCaseTask;
            tests.Status  = TestsStatus.Takened;
            tests.Takened = DateTime.Now;
            tests.Tester  = await testerTask;

            TestsRepository testsRepo = new TestsRepository();

            testsRepo.Create(tests);
        }
        public JsonResult GetTestCases(string searchTerm)
        {
            ApplicationUserRepository <Company> companyRepo = new ApplicationUserRepository <Company>();
            Company currentCompany = companyRepo.GetByUserName(User.Identity.Name);

            TestCaseRepository testCaseRepo = new TestCaseRepository();

            IList <TestCase> testCases;

            testCases = !string.IsNullOrEmpty(searchTerm) ? testCaseRepo.GetFilteredForCompanyNotInGroup(currentCompany, nameof(TestCase.Name), searchTerm) : testCaseRepo.GetFilteredForCompanyNotInGroup(currentCompany);

            var modifiedData = testCases.Select(x => new
            {
                id   = x.Id,
                text = x.Name + " (available to: " + x.AvailableTo.ToShortDateString() + ")"
            });

            return(Json(modifiedData, JsonRequestBehavior.AllowGet));
        }
Example #17
0
        public ActionResult CompanyTestsDataTable(IDataTablesRequest request)
        {
            ApplicationUserRepository <Company> companyRepo = new ApplicationUserRepository <Company>();
            var company      = companyRepo.GetByUserName(User.Identity.Name);
            var testCaseRepo = new TestCaseRepository();

            var orderColumn = request.Columns.Where(c => c.Sort != null).First();

            bool asc;

            if (orderColumn.Sort.Direction == 0)
            {
                asc = true;
            }
            else
            {
                asc = false;
            }

            var testCases = testCaseRepo.GetEntitiesForCompany(out int totalCount, out int filteredCount, request.Start, request.Length, nameof(TestCase.Name), request.Search.Value, orderColumn.Name, asc, company).Select(x => new
            {
                x.Id,
                x.Name,
                x.SkillDificulty,
                x.TimeDificulty,
                x.Reward,
                x.Rating,
                x.Created,
                x.AvailableTo,
                x.SoftwareType,
                x.Category
            });

            var response = DataTablesResponse.Create(request, totalCount, filteredCount, testCases);

            return(new DataTablesJsonResult(response, JsonRequestBehavior.DenyGet));
        }
Example #18
0
        // GET: Testing/Home
        public async Task <ActionResult> Index()
        {
            if (User.IsInRole("company"))
            {
                ViewBag.Role = "company";

                ApplicationUserRepository <Company> companyRepo = new ApplicationUserRepository <Company>();
                TestCaseRepository  testCaseRepo  = new TestCaseRepository();
                TestGroupRepository testGroupRepo = new TestGroupRepository();
                DisputeRepository   disputeRepo   = new DisputeRepository();
                Company             company       = companyRepo.GetByUserName(User.Identity.Name);

                var tests      = testCaseRepo.GetCountForCompanyAsync(company);
                var testGroups = testGroupRepo.GetCountForCompanyAsync(company);
                var disputes   = disputeRepo.GetCountWithCompanyAsync(company);

                ViewBag.Credits    = company.Credits;
                ViewBag.Tests      = await tests;
                ViewBag.TestGroups = await testGroups;
                ViewBag.Disputes   = await disputes;
            }

            if (User.IsInRole("tester"))
            {
                ViewBag.Role = "tester";

                ApplicationUserRepository <Tester> testerRepo = new ApplicationUserRepository <Tester>();
                DisputeRepository disputeRepo = new DisputeRepository();
                TestsRepository   testRepo    = new TestsRepository();
                var tester  = testerRepo.GetByUserName(User.Identity.Name);
                var dispute = disputeRepo.GetCountWithTesterAsync(tester);

                IList <TestsStatus> takened = new List <TestsStatus>();
                takened.Add(TestsStatus.Takened);

                IList <TestsStatus> finished = new List <TestsStatus>();
                finished.Add(TestsStatus.Finished);
                finished.Add(TestsStatus.Reviewed);

                ViewBag.Credits       = tester.Credits;
                ViewBag.Disputes      = await dispute;
                ViewBag.ResolvedTests = testRepo.GetCountByStatus(finished, tester);
                ViewBag.TakenedTests  = testRepo.GetCountByStatus(takened, tester);
            }

            if (User.IsInRole("admin"))
            {
                ViewBag.Role = "admin";

                ApplicationUserRepository <Admin> adminRepo = new ApplicationUserRepository <Admin>();
                DisputeRepository      disputeRepo1         = new DisputeRepository();
                DisputeRepository      disputeRepo2         = new DisputeRepository();
                DisputeRepository      disputeRepo3         = new DisputeRepository();
                SoftwareTypeRepository swTypeRepo           = new SoftwareTypeRepository();
                TestCaseRepository     testCatRepo          = new TestCaseRepository();

                Admin admin = adminRepo.GetByUserName(User.Identity.Name);

                var disputes           = disputeRepo1.GetCountPandingAsync();
                var inProgressDisputes = disputeRepo2.GetCountForAdminInProgressAsync(admin);
                var resolvedDisputes   = disputeRepo3.GetCountForAdminResolvedAsync(admin);
                var admins             = adminRepo.GetCountAsync();
                var softwareTypes      = swTypeRepo.GetCountAsync();
                var testCategories     = testCatRepo.GetCountAsync();

                ViewBag.Disputes           = await disputes;
                ViewBag.InProgressDisputes = await inProgressDisputes;
                ViewBag.ResolvedDisputes   = await resolvedDisputes;
                ViewBag.Admins             = await admins;
                ViewBag.SoftwareTypes      = await softwareTypes;
                ViewBag.TestCategories     = await testCategories;
            }

            return(View());
        }
        public ActionResult AddTestGroup(TestGroup testGroup, string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                TempData["error"] = "At least one test case must be selected!";
                return(View("CreateTestGroup"));
            }

            ModelState.Remove(nameof(TestGroup.TestCases));
            ModelState.Remove(nameof(TestGroup.Created));
            ModelState.Remove(nameof(TestGroup.Creator));
            ModelState.Remove(nameof(TestGroup.Rating));
            ModelState.Remove(nameof(TestGroup.TimeDificulty));
            ModelState.Remove(nameof(TestGroup.SkillDificulty));
            if (ModelState.IsValid)
            {
                ApplicationUserRepository <Company> userRepo = new ApplicationUserRepository <Company>();
                Company currentUser = userRepo.GetByUserName(User.Identity.Name);

                var testCasesId = data.Split(',');
                TestCaseRepository testCaseRepo = new TestCaseRepository();
                IList <TestCase>   testCases    = new List <TestCase>();

                foreach (var testCaseId in testCasesId)
                {
                    TestCase tempTestCase = testCaseRepo.GetByIdForCompanyNotInGroup(currentUser, Guid.Parse(testCaseId));
                    tempTestCase.IsInGroup = true;
                    testCases.Add(tempTestCase);
                }

                DateTime latestAvailability = testCases.OrderByDescending(x => x.AvailableTo).First().AvailableTo;
                if (testGroup.AvailableTo < latestAvailability)
                {
                    TempData["error"] = $"Available To must be equal or greater than availability of latest test case ({latestAvailability.ToShortDateString()})!";
                    return(View("CreateTestGroup"));
                }

                testGroup.TestCases      = testCases;
                testGroup.SkillDificulty = testGroup.CountSkillDificulty();
                testGroup.TimeDificulty  = testGroup.CountTimeDificulty();

                testGroup.RewardMultiplier = (testGroup.RewardMultiplier + 100) / 100;

                testGroup.Creator = currentUser;
                testGroup.Created = DateTime.Now;

                foreach (var testCase in testCases)
                {
                    testCaseRepo.Update(testCase);
                }

                TestGroupRepository testGroupRepo = new TestGroupRepository();
                testGroupRepo.Create(testGroup);

                TempData["success"] = "Test group was added";
            }
            else
            {
                return(View("CreateTestGroup"));
            }

            return(RedirectToAction("CompanyTestGroups"));
        }
Example #20
0
 public TestCaseRepositoryTest_Get()
 {
     this.directory            = new Directory();
     this.fileSystemRepository = Mock.Of <IFileSystemRepository>(r => r.GetDirectory(It.IsAny <string>()) == directory);
     this.testCaseRepository   = new TestCaseRepository("Root", fileSystemRepository);
 }
        public ActionResult UpdateTestGroup(TestGroup testGroup, string data)
        {
            TestGroupRepository testGroupRepo = new TestGroupRepository();

            TestGroup oldTestGroup = testGroupRepo.GetById(testGroup.Id);

            if (string.IsNullOrEmpty(data) && oldTestGroup.TestCases.Count <= 0)
            {
                TempData["error"] = "At least one test case must be selected!";
                return(View("EditTestGroup", testGroup));
            }

            ModelState.Remove(nameof(TestGroup.TestCases));
            ModelState.Remove(nameof(TestGroup.Created));
            ModelState.Remove(nameof(TestGroup.Creator));
            ModelState.Remove(nameof(TestGroup.Rating));
            ModelState.Remove(nameof(TestGroup.TimeDificulty));
            ModelState.Remove(nameof(TestGroup.SkillDificulty));
            if (ModelState.IsValid)
            {
                var testCasesId = data.Split(',');
                TestCaseRepository testCaseRepo = new TestCaseRepository();

                IList <TestCase> testCases = new List <TestCase>();

                if (!testCasesId[0].IsNullOrEmpty())
                {
                    foreach (var testCaseId in testCasesId)
                    {
                        TestCase tempTestCase = testCaseRepo.GetByIdForCompanyNotInGroup(testGroup.Creator, Guid.Parse(testCaseId));
                        tempTestCase.IsInGroup = true;
                        oldTestGroup.TestCases.Add(tempTestCase);
                        testCases.Add(tempTestCase);
                    }
                }

                DateTime latestAvailability = oldTestGroup.TestCases.OrderByDescending(x => x.AvailableTo).First().AvailableTo;
                if (testGroup.AvailableTo < latestAvailability)
                {
                    testGroup.TestCases        = oldTestGroup.TestCases;
                    testGroup.RewardMultiplier = oldTestGroup.RewardMultiplier;

                    TempData["error"] = $"Available To must be equal or greater than availability of latest test case ({latestAvailability.ToShortDateString()})!";
                    return(View("EditTestGroup", testGroup));
                }

                oldTestGroup.SkillDificulty = oldTestGroup.CountSkillDificulty();
                oldTestGroup.TimeDificulty  = oldTestGroup.CountTimeDificulty();

                oldTestGroup.RewardMultiplier = (testGroup.RewardMultiplier + 100) / 100;

                oldTestGroup.Name        = testGroup.Name;
                oldTestGroup.AvailableTo = testGroup.AvailableTo;

                foreach (var testCase in testCases)
                {
                    testCaseRepo.Update(testCase);
                }

                testGroupRepo.Update(oldTestGroup);

                TempData["success"] = "Test group was edited";
            }
            else
            {
                return(View("CreateTestGroup"));
            }

            return(RedirectToAction("CompanyTestGroups"));
        }
Example #22
0
 public TestCaseRepositoryTest_FetchAll()
 {
     this.directories          = new List <Directory>();
     this.fileSystemRepository = Mock.Of <IFileSystemRepository>(r => r.FetchAllDirectories(It.IsAny <string>()) == directories);
     this.testCaseRepository   = new TestCaseRepository(string.Empty, fileSystemRepository);
 }
Example #23
0
        public async Task <ActionResult> UpdateTestCase(TestCase testCase, HttpPostedFileBase[] files)
        {
            ModelState.Remove(nameof(testCase.Evidences));
            ModelState.Remove(nameof(testCase.Rating));
            ModelState.Remove(nameof(testCase.Created));
            ModelState.Remove(nameof(testCase.Creator));
            ModelState.Remove(nameof(testCase.Reviews));
            ModelState.Remove(nameof(testCase.IsInGroup));
            ModelState.Remove("SoftwareType.Name");
            ModelState.Remove("Category.Name");
            ModelState.Remove("files");
            if (ModelState.IsValid)
            {
                TestCaseRepository     testCaseRepo = new TestCaseRepository();
                TestCategoryRepository testCatRepo  = new TestCategoryRepository();
                SoftwareTypeRepository swTypeRepo   = new SoftwareTypeRepository();

                TestCase oldTestCase = testCaseRepo.GetById(testCase.Id);

                IList <Evidence> evidences = new List <Evidence>();

                if (testCase.AvailableTo <= DateTime.Now)
                {
                    IList <SoftwareType> swTypes  = swTypeRepo.GetAllValid();
                    IList <TestCategory> testCats = testCatRepo.GetAllValid();
                    ViewBag.SoftwareTypes  = swTypes;
                    ViewBag.TestCategories = testCats;

                    TempData["error"] = "Available To must be in future!";
                    return(View("EditTestCase", testCase));
                }

                if (files[0] != null)
                {
                    if (oldTestCase.Evidences == null || oldTestCase.Evidences.Count <= 0)
                    {
                        oldTestCase.Evidences = new List <Evidence>();
                    }

                    var maxSizeInMb    = 20;
                    var byteSize       = 1048576;
                    var maxSizeInBytes = byteSize * maxSizeInMb;
                    foreach (var file in files)
                    {
                        if (file.ContentLength > maxSizeInBytes)
                        {
                            IList <SoftwareType> swTypes  = swTypeRepo.GetAllValid();
                            IList <TestCategory> testCats = testCatRepo.GetAllValid();
                            ViewBag.SoftwareTypes  = swTypes;
                            ViewBag.TestCategories = testCats;

                            TempData["error"] = "File " + file.FileName + " is too big! (max size is " + maxSizeInMb + "MB)";
                            return(View("EditTestCase", testCase));
                        }
                    }

                    foreach (var file in files)
                    {
                        Evidence evidence = new Evidence();
                        evidence.Id       = Guid.NewGuid();
                        evidence.Name     = evidence.Id.ToString();
                        evidence.RealName = Path.GetFileNameWithoutExtension(file.FileName);
                        evidence.Attached = DateTime.Now;

                        var extension = Path.GetExtension(file.FileName);
                        evidence.Extension = extension;

                        var path = Path.Combine(Server.MapPath("~/Uploads"), evidence.Name + extension);
                        Directory.CreateDirectory(Server.MapPath("~/Uploads"));
                        file.SaveAs(path);

                        oldTestCase.Evidences.Add(evidence);
                        evidences.Add(evidence);
                    }
                }

                var swType  = swTypeRepo.GetByIdAsync(testCase.SoftwareType.Id);
                var testCat = testCatRepo.GetByIdAsync(testCase.Category.Id);

                oldTestCase.SoftwareType   = await swType;
                oldTestCase.Category       = await testCat;
                oldTestCase.Name           = testCase.Name;
                oldTestCase.SkillDificulty = testCase.SkillDificulty;
                oldTestCase.TimeDificulty  = testCase.TimeDificulty;
                oldTestCase.AvailableTo    = testCase.AvailableTo;
                oldTestCase.Description    = testCase.Description;
                oldTestCase.Reward         = testCase.Reward;

                EvidenceRepository evidRepo = new EvidenceRepository();

                foreach (var evidence in evidences)
                {
                    evidRepo.Create(evidence);
                }
                testCaseRepo.Update(oldTestCase);
                TempData["success"] = "Test case was edited";
            }
            else
            {
                SoftwareTypeRepository swTypeRepo = new SoftwareTypeRepository();
                IList <SoftwareType>   swTypes    = swTypeRepo.GetAllValid();
                ViewBag.SoftwareTypes = swTypes;

                TestCategoryRepository testCatRepo = new TestCategoryRepository();
                IList <TestCategory>   testCats    = testCatRepo.GetAllValid();
                ViewBag.TestCategories = testCats;

                if (!swTypeRepo.IsSwTypeExist(testCase.SoftwareType.Id))
                {
                    TempData["error"] = "Please select Software type!";
                    return(View("EditTestCase", testCase));
                }

                if (!testCatRepo.IsTestCatExist(testCase.Category.Id))
                {
                    TempData["error"] = "Please select Category!";
                    return(View("EditTestCase", testCase));
                }

                return(View("EditTestCase", testCase));
            }

            return(RedirectToAction("CompanyTests"));
        }