public void Create_InvalidCustomerIdSupplied_ArgumentExceptionThrown() { var id = Guid.NewGuid(); var customerId = Guid.Empty; var typeId = Guid.NewGuid(); _jobService = JobServiceFactory.Create(typeId, customerId); CreateJob(id, "job instructions", "PO1000", "AD1000", typeId, customerId, "some notes", "job contact"); }
public void Create_ContactGreaterThan50Characters_DomainValidationExceptionThrown() { var id = Guid.NewGuid(); var customerId = Guid.NewGuid(); var typeId = Guid.NewGuid(); _jobService = JobServiceFactory.Create(typeId, customerId); CreateJob(id, "job instructions", "PO1000", "AD1000", typeId, customerId, "some notes", new string('a', 51)); Assert.IsTrue(_domainValidationException.ResultContainsMessage(JobSystem.Resources.Jobs.Messages.ContactTooLarge)); }
public void AddAttachment_InvalidJobIdSupplied_ArgumentExceptionThrow() { var attachmentId = Guid.NewGuid(); var fileName = "attachment.pdf"; var contentType = "image"; byte[] content = new byte[] { 1, 2, 3, 4, 5 }; var jobRepositoryStub = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryStub.Stub(x => x.GetById(Guid.Empty)).Return(null); _jobService = JobServiceFactory.Create(jobRepositoryStub, MockRepository.GenerateStub <IJobAttachmentDataRepository>()); AddAttachment(_jobForAttachmentId, attachmentId, fileName, contentType, content); }
public void AddAttachment_FilenameNotSupplied_DomainValidationExceptionThrow() { var attachmentId = Guid.NewGuid(); var fileName = String.Empty; var contentType = "image"; var content = new byte[] { 1, 2, 3, 4, 5 }; var jobRepositoryStub = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryStub.Stub(x => x.GetById(_jobForAttachmentId)).Return(_jobForAttachment); _jobService = JobServiceFactory.Create(jobRepositoryStub, MockRepository.GenerateStub <IJobAttachmentDataRepository>()); AddAttachment(_jobForAttachmentId, attachmentId, fileName, contentType, content); Assert.IsTrue(_domainValidationException.ResultContainsMessage(JobSystem.Resources.Jobs.Messages.FileNameRequired)); }
public void Edit_InstructionsGreaterThan2000Characters_ThrowsDomainValidationException() { var orderNumber = "orderno-edited"; var adviceNumber = "adviceno-edited"; var contact = "contact-edited"; var notes = "notes-edited"; var instructions = new String('a', 2001); var jobRepositoryMock = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryMock.Stub(x => x.GetById(_jobForEditId)).Return(_jobForEdit); _jobService = JobServiceFactory.Create(jobRepositoryMock); Edit(_jobForEditId, orderNumber, adviceNumber, contact, notes, instructions); Assert.IsTrue(_domainValidationException.ResultContainsMessage(JobSystem.Resources.Jobs.Messages.InstructionsTooLarge)); }
public void Edit_InvalidJobId_ThrowsArgumentException() { var id = Guid.NewGuid(); var orderNumber = "orderno-edited"; var adviceNumber = "adviceno-edited"; var contact = "contact-edited"; var notes = "notes-edited"; var instructions = "instructions-edited"; var jobRepositoryMock = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryMock.Stub(x => x.GetById(id)).Return(null); _jobService = JobServiceFactory.Create(jobRepositoryMock); Edit(_jobForEditId, orderNumber, adviceNumber, contact, notes, instructions); }
public void AddAttachment_UserDoesNotHaveMemberRole_DomainValidationExceptionThrow() { var attachmentId = Guid.NewGuid(); var fileName = "attachment.pdf"; var contentType = "image"; byte[] content = new byte[] { 1, 2, 3, 4, 5 }; var jobRepositoryStub = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryStub.Stub(x => x.GetById(_jobForAttachmentId)).Return(_jobForAttachment); _jobService = JobServiceFactory.Create(jobRepositoryStub, MockRepository.GenerateStub <IJobAttachmentDataRepository>(), TestUserContext.Create("*****@*****.**", "Graham Robertson", "Operations Manager", UserRole.Public)); AddAttachment(_jobForAttachmentId, attachmentId, fileName, contentType, content); Assert.IsTrue(_domainValidationException.ResultContainsMessage(JobSystem.Resources.Jobs.Messages.InsufficientSecurityClearance)); }
public void AddAttachment_ValidAttachmentDetails_AttachmentAdded() { var attachmentId = Guid.NewGuid(); var fileName = "attachment.pdf"; var contentType = "image"; var content = new byte[] { 1, 2, 3, 4, 5 }; var jobRepositoryMock = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryMock.Expect(x => x.Update(null)).IgnoreArguments(); jobRepositoryMock.Stub(x => x.GetById(_jobForAttachmentId)).Return(_jobForAttachment); _jobService = JobServiceFactory.Create(jobRepositoryMock, MockRepository.GenerateStub <IJobAttachmentDataRepository>()); AddAttachment(_jobForAttachmentId, attachmentId, fileName, contentType, content); jobRepositoryMock.VerifyAllExpectations(); Assert.AreEqual(1, _jobForAttachment.Attachments.Count); }
public void Edit_UserHasInsufficientSecurityClearance_ThrowsDomainValidationException() { var orderNumber = "orderno-edited"; var adviceNumber = "adviceno-edited"; var contact = "contact-edited"; var notes = "notes-edited"; var instructions = "instructions-edited"; var jobRepositoryMock = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryMock.Stub(x => x.GetById(_jobForEditId)).Return(_jobForEdit); _jobService = JobServiceFactory.Create( jobRepositoryMock, TestUserContext.Create("*****@*****.**", "Graham Robertson", "Operations Manager", UserRole.Member)); Edit(_jobForEditId, orderNumber, adviceNumber, contact, notes, instructions); Assert.IsTrue(_domainValidationException.ResultContainsMessage(JobSystem.Resources.Jobs.Messages.InsufficientSecurityClearance)); }
public void GetPendingJobs_UserHasInsufficientSecurityClearance_DomainValidationExceptionThrown() { try { var customerId = Guid.NewGuid(); var typeId = Guid.NewGuid(); var jobRepositoryMock = MockRepository.GenerateMock <IJobRepository>(); _jobService = JobServiceFactory.Create( jobRepositoryMock, typeId, customerId, TestUserContext.Create("*****@*****.**", "Test User", "Operations Manager", UserRole.Public)); _jobService.GetPendingJobs(); } catch (DomainValidationException dex) { _domainValidationException = dex; } Assert.IsTrue(_domainValidationException.ResultContainsMessage(JobSystem.Resources.Jobs.Messages.InsufficientSecurityClearance)); }
public void Create_ValidJobDetails_SuccessfullyCreateJob() { var id = Guid.NewGuid(); var customerId = Guid.NewGuid(); var typeId = Guid.NewGuid(); var jobRepositoryMock = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryMock.Expect(x => x.Create(null)).IgnoreArguments(); _jobService = JobServiceFactory.Create(jobRepositoryMock, typeId, customerId); CreateJob(id, "job instructions", "PO1000", "AD1000", typeId, customerId, "some notes", "job contact"); jobRepositoryMock.VerifyAllExpectations(); Assert.That(_savedJob.Id == id); Assert.That(!String.IsNullOrEmpty(_savedJob.JobNo) && _savedJob.JobNo.EndsWith("JR")); Assert.IsTrue(_savedJob.IsPending); Assert.AreEqual(_savedJob.DateCreated, _dateCreated); Assert.AreEqual("*****@*****.**", _savedJob.CreatedBy.EmailAddress); }
public void Edit_ValidJobDetails_SuccessfullyEditJob() { var orderNumber = "orderno-edited"; var adviceNumber = "adviceno-edited"; var contact = "contact-edited"; var notes = "notes-edited"; var instructions = "instructions-edited"; var jobRepositoryMock = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryMock.Stub(x => x.GetById(_jobForEditId)).Return(_jobForEdit); jobRepositoryMock.Expect(x => x.Update(null)).IgnoreArguments(); _jobService = JobServiceFactory.Create(jobRepositoryMock); Edit(_jobForEditId, orderNumber, adviceNumber, contact, notes, instructions); jobRepositoryMock.VerifyAllExpectations(); Assert.AreEqual(_jobForEdit.Id, _jobForEditId); Assert.AreEqual(_jobForEdit.OrderNo, orderNumber); Assert.AreEqual(_jobForEdit.AdviceNo, adviceNumber); Assert.AreEqual(_jobForEdit.Notes, notes); Assert.AreEqual(_jobForEdit.Instructions, instructions); }
public void Edit_AdminUserContext_SuccessfullyEditJob() { var orderNumber = "orderno-edited"; var adviceNumber = "adviceno-edited"; var contact = "contact-edited"; var notes = "notes-edited"; var instructions = "instructions-edited"; var jobRepositoryMock = MockRepository.GenerateMock <IJobRepository>(); jobRepositoryMock.Stub(x => x.GetById(_jobForEditId)).Return(_jobForEdit); jobRepositoryMock.Expect(x => x.Update(null)).IgnoreArguments(); _jobService = JobServiceFactory.Create( jobRepositoryMock, TestUserContext.Create("*****@*****.**", "Graham Robertson", "Operations Manager", UserRole.Admin | UserRole.Member)); Edit(_jobForEditId, orderNumber, adviceNumber, contact, notes, instructions); jobRepositoryMock.VerifyAllExpectations(); Assert.AreEqual(_jobForEdit.Id, _jobForEditId); Assert.AreEqual(_jobForEdit.OrderNo, orderNumber); Assert.AreEqual(_jobForEdit.AdviceNo, adviceNumber); Assert.AreEqual(_jobForEdit.Notes, notes); Assert.AreEqual(_jobForEdit.Instructions, instructions); }