예제 #1
0
        public void ShouldCreateDirectory()
        {
            // Arrange
            var testCase = new TestCase();

            testCase.Name = "TestCase01";

            // Act
            testCaseRepository.Create(testCase);

            // Assert
            Mock.Get(fileSystemRepository)
            .Verify(r => r.CreateDirectory("Root\\TestCase01"), Times.Once());
        }
예제 #2
0
        public async Task <ActionResult> AddTest(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)
            {
                TestCategoryRepository testCatRepo           = new TestCategoryRepository();
                SoftwareTypeRepository swTypeRepo            = new SoftwareTypeRepository();
                ApplicationUserRepository <Company> userRepo = new ApplicationUserRepository <Company>();
                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("CreateTestCase", testCase));
                }

                if (files[0] != null)
                {
                    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("CreateTestCase", 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);

                        evidences.Add(evidence);
                    }

                    testCase.Evidences = evidences;
                }

                var swType      = swTypeRepo.GetByIdAsync(testCase.SoftwareType.Id);
                var testCat     = testCatRepo.GetByIdAsync(testCase.Category.Id);
                var currentUser = userRepo.GetByUserNameAsync(User.Identity.Name);

                testCase.SoftwareType = await swType;
                testCase.Category     = await testCat;
                testCase.Creator      = await currentUser;
                testCase.Created      = DateTime.Now;

                TestCaseRepository testRepo = new TestCaseRepository();
                EvidenceRepository evidRepo = new EvidenceRepository();

                foreach (var evidence in evidences)
                {
                    evidRepo.Create(evidence);
                }
                testRepo.Create(testCase);
                TempData["success"] = "Test case was added";
            }
            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("CreateTestCase", testCase));
                }

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

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

            return(RedirectToAction("CompanyTests"));
        }