public void Create_ValidCertificateDetails_CertificateCreated()
        {
            var id = Guid.NewGuid();
            var certificateTypeId = Guid.NewGuid();
            var categoryId        = Guid.NewGuid();
            var jobItemId         = Guid.NewGuid();
            var procedureList     = "001; 002";

            var certificateRepositoryMock = MockRepository.GenerateMock <ICertificateRepository>();

            certificateRepositoryMock.Expect(x => x.Create(null)).IgnoreArguments();
            _certificateService = CertificateServiceFactory.Create(
                _userContext,
                ListItemRepositoryTestHelper.GetListItemRepository_StubsGetById_ReturnsCertificateAndCategory(certificateTypeId, categoryId),
                certificateRepositoryMock,
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId));
            Create(id, certificateTypeId, categoryId, jobItemId, procedureList);
            certificateRepositoryMock.VerifyAllExpectations();
            Assert.AreNotEqual(Guid.Empty, _savedCertificate.Id);
            Assert.AreEqual("E2000", _savedCertificate.CertificateNumber);
            Assert.AreEqual(_dateCreated, _savedCertificate.DateCreated);
            Assert.AreEqual("*****@*****.**", _savedCertificate.CreatedBy.EmailAddress);
            Assert.IsNotNull(_savedCertificate.JobItem);
            Assert.IsNotNull(_savedCertificate.Type);
            Assert.IsNotNull(_savedCertificate.Category);
        }
 public void GetCertificates_UserHasInsufficientSecurityClearance_DomainValidationExceptionThrown()
 {
     _certificateService = CertificateServiceFactory.Create(
         TestUserContext.Create("*****@*****.**", "Graham Robertson", "Operations Manager", UserRole.Public),
         MockRepository.GenerateStub <IListItemRepository>(),
         MockRepository.GenerateStub <ICertificateRepository>(),
         MockRepository.GenerateStub <IJobItemRepository>());
     GetCertificates();
     Assert.IsTrue(_domainValidationException.ResultContainsMessage(Messages.InsufficientSecurityClearance));
 }
        public void Create_NonCertificateListItemId_ArgumentExceptionThrown()
        {
            var id = Guid.NewGuid();
            var certificateTypeId = Guid.NewGuid();
            var categoryId        = Guid.NewGuid();
            var jobItemId         = Guid.NewGuid();
            var procedureList     = "001; 002";

            _certificateService = CertificateServiceFactory.Create(
                _userContext,
                ListItemRepositoryTestHelper.GetListItemRepository_StubsGetById_ReturnsNonCertificateType(certificateTypeId),
                MockRepository.GenerateStub <ICertificateRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId));
            Create(id, certificateTypeId, categoryId, jobItemId, procedureList);
        }
        public void Create_UserHasInsufficientClearance_DomainValidationExceptionThrown()
        {
            var id = Guid.NewGuid();
            var certificateTypeId = Guid.NewGuid();
            var categoryId        = Guid.NewGuid();
            var jobItemId         = Guid.NewGuid();
            var procedureList     = "001; 002";

            _certificateService = CertificateServiceFactory.Create(
                TestUserContext.Create("*****@*****.**", "Graham Robertson", "Operations Manager", UserRole.Public),
                ListItemRepositoryTestHelper.GetListItemRepository_StubsGetById_ReturnsCertificateAndCategory(certificateTypeId, categoryId),
                MockRepository.GenerateStub <ICertificateRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId));
            Create(id, certificateTypeId, categoryId, jobItemId, procedureList);
            Assert.IsTrue(_domainValidationException.ResultContainsMessage(Messages.InsufficientSecurityClearance));
        }
        public void Create_ProcedureListGreaterThan255Characters_DomainValidationExceptionThrown()
        {
            var id = Guid.NewGuid();
            var certificateTypeId = Guid.NewGuid();
            var categoryId        = Guid.NewGuid();
            var jobItemId         = Guid.NewGuid();
            var procedureList     = new string('a', 256);

            _certificateService = CertificateServiceFactory.Create(
                _userContext,
                ListItemRepositoryTestHelper.GetListItemRepository_StubsGetById_ReturnsCertificateAndCategory(certificateTypeId, categoryId),
                MockRepository.GenerateStub <ICertificateRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId));
            Create(id, certificateTypeId, categoryId, jobItemId, procedureList);
            Assert.IsTrue(_domainValidationException.ResultContainsMessage(Messages.ProcedureListTooLarge));
        }