示例#1
0
        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");
        }
示例#2
0
        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));
        }
示例#3
0
        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);
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        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);
        }
示例#7
0
        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));
        }
示例#8
0
        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);
        }
示例#9
0
        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));
        }
示例#10
0
 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));
 }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        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);
        }