Beispiel #1
0
        public void CreatePending_JobItemWithQuoteItem_PendingItemCreatedSuccessfully()
        {
            var id         = Guid.NewGuid();
            var customerId = Guid.NewGuid();
            var jobItemId  = Guid.NewGuid();
            var notes      = "some notes";

            var deliveryItemRepositoryMock = MockRepository.GenerateMock <IDeliveryItemRepository>();

            deliveryItemRepositoryMock.Expect(x => x.CreatePending(null)).IgnoreArguments();
            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                MockRepository.GenerateStub <IDeliveryRepository>(),
                deliveryItemRepositoryMock,
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId),
                QuoteItemRepositoryTestHelper.GetQuoteItemRepository_StubsGetQuoteItemForJobItem_ReturnsQuoteItem(jobItemId),
                MockRepository.GenerateStub <IListItemRepository>(),
                CustomerRepositoryTestHelper.GetCustomerRepository_StubsGetById_ReturnsCustomer(customerId));
            CreatePending(id, customerId, jobItemId, notes);
            deliveryItemRepositoryMock.VerifyAllExpectations();
            Assert.AreNotEqual(Guid.Empty, _savedPendingItem.Id);
            Assert.IsNotNull(_savedPendingItem.JobItem);
            Assert.IsNotNull(_savedPendingItem.QuoteItem);
            Assert.IsNotNull(_savedPendingItem.Customer);
        }
Beispiel #2
0
        public void CreatePending_InvalidCustomerId_ArgumentExceptionThrown()
        {
            var id         = Guid.NewGuid();
            var customerId = Guid.NewGuid();
            var jobItemId  = Guid.NewGuid();
            var notes      = "some notes";

            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                MockRepository.GenerateStub <IDeliveryRepository>(),
                MockRepository.GenerateStub <IDeliveryItemRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId),
                QuoteItemRepositoryTestHelper.GetQuoteItemRepository_StubsGetQuoteItemForJobItem_ReturnsQuoteItem(jobItemId),
                MockRepository.GenerateStub <IListItemRepository>(),
                CustomerRepositoryTestHelper.GetCustomerRepository_StubsGetById_ReturnsNull(customerId));
            CreatePending(id, customerId, jobItemId, notes);
        }
Beispiel #3
0
        public void Edit_InvalidDeliveryItemId_ThrowsArgumentException()
        {
            var notes = "some notes";

            var deliveryItemRepositoryStub = MockRepository.GenerateMock <IDeliveryItemRepository>();

            deliveryItemRepositoryStub.Stub(x => x.GetById(_deliveryItemForEditId)).Return(null);
            _jobItemService      = JobItemServiceFactory.Create(_userContext, MockRepository.GenerateStub <IJobItemRepository>());
            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                MockRepository.GenerateStub <IDeliveryRepository>(),
                deliveryItemRepositoryStub,
                MockRepository.GenerateStub <IJobItemRepository>(),
                MockRepository.GenerateStub <IQuoteItemRepository>(),
                MockRepository.GenerateStub <IListItemRepository>(),
                MockRepository.GenerateStub <ICustomerRepository>());
            Edit(_deliveryItemForEditId, notes);
        }
Beispiel #4
0
        public void CreatePending_UserHasInsufficientSecurityClearance_ArgumentExceptionThrown()
        {
            var id         = Guid.NewGuid();
            var customerId = Guid.NewGuid();
            var jobItemId  = Guid.NewGuid();
            var notes      = "some notes";

            _deliveryItemService = DeliveryItemServiceFactory.Create(
                TestUserContext.Create("*****@*****.**", "Graham Robertson", "Operations Manager", UserRole.Public),
                MockRepository.GenerateStub <IDeliveryRepository>(),
                MockRepository.GenerateStub <IDeliveryItemRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId),
                QuoteItemRepositoryTestHelper.GetQuoteItemRepository_StubsGetQuoteItemForJobItem_ReturnsQuoteItem(jobItemId),
                MockRepository.GenerateStub <IListItemRepository>(),
                CustomerRepositoryTestHelper.GetCustomerRepository_StubsGetById_ReturnsCustomer(customerId));
            CreatePending(id, customerId, jobItemId, notes);
            Assert.IsTrue(_domainValidationException.ResultContainsMessage(DeliveryItemMessages.InsufficientSecurityClearance));
        }
Beispiel #5
0
        public void CreatePending_NotesGreaterThan255Characters_ArgumentExceptionThrown()
        {
            var id         = Guid.NewGuid();
            var customerId = Guid.NewGuid();
            var jobItemId  = Guid.NewGuid();
            var notes      = new string('a', 256);

            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                MockRepository.GenerateStub <IDeliveryRepository>(),
                MockRepository.GenerateStub <IDeliveryItemRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId),
                QuoteItemRepositoryTestHelper.GetQuoteItemRepository_StubsGetQuoteItemForJobItem_ReturnsQuoteItem(jobItemId),
                MockRepository.GenerateStub <IListItemRepository>(),
                CustomerRepositoryTestHelper.GetCustomerRepository_StubsGetById_ReturnsCustomer(customerId));
            CreatePending(id, customerId, jobItemId, notes);
            Assert.IsTrue(_domainValidationException.ResultContainsMessage(DeliveryItemMessages.InvalidNotes));
        }
Beispiel #6
0
        public void CreatePending_JobIsPending_DomainValidationExceptionThrown()
        {
            var id         = Guid.NewGuid();
            var customerId = Guid.NewGuid();
            var jobItemId  = Guid.NewGuid();
            var notes      = "some notes";

            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                MockRepository.GenerateStub <IDeliveryRepository>(),
                MockRepository.GenerateStub <IDeliveryItemRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItemOnPendingJob(jobItemId),
                QuoteItemRepositoryTestHelper.GetQuoteItemRepository_StubsGetQuoteItemForJobItem_ReturnsQuoteItem(jobItemId),
                MockRepository.GenerateStub <IListItemRepository>(),
                CustomerRepositoryTestHelper.GetCustomerRepository_StubsGetById_ReturnsNull(customerId));
            CreatePending(id, customerId, jobItemId, notes);
            Assert.IsTrue(_domainValidationException.ResultContainsMessage(DeliveryItemMessages.JobPending));
        }
Beispiel #7
0
        public void Create_InvalidDeliveryId_ArgumentExceptionThrown()
        {
            var id         = Guid.NewGuid();
            var deliveryId = Guid.NewGuid();
            var jobItemId  = _jobItemToUpdateId;
            var notes      = "some notes";

            _jobItemService      = JobItemServiceFactory.Create(_userContext, MockRepository.GenerateStub <IJobItemRepository>());
            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                DeliveryRepositoryTestHelper.GetDeliveryRepository_StubsGetById_ReturnsNull(deliveryId),
                MockRepository.GenerateStub <IDeliveryItemRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId),
                QuoteItemRepositoryTestHelper.GetQuoteItemRepository_StubsGetQuoteItemForJobItem_ReturnsQuoteItem(jobItemId),
                ListItemRepositoryTestHelper.GetListItemRepository_StubsGetByType_ReturnsListItem(new ListItemType[] { ListItemType.StatusDeliveryNoteProduced }),
                MockRepository.GenerateStub <ICustomerRepository>());
            CreateDeliveryItem(id, deliveryId, jobItemId, notes);
        }
Beispiel #8
0
        public void Edit_NotesGreaterThan255Characters_ThrowsDomainValidationException()
        {
            var notes = new string('a', 256);

            var deliveryItemRepositoryStub = MockRepository.GenerateMock <IDeliveryItemRepository>();

            deliveryItemRepositoryStub.Stub(x => x.GetById(_deliveryItemForEditId)).Return(_deliveryItemForEdit);
            _jobItemService      = JobItemServiceFactory.Create(_userContext, MockRepository.GenerateStub <IJobItemRepository>());
            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                MockRepository.GenerateStub <IDeliveryRepository>(),
                deliveryItemRepositoryStub,
                MockRepository.GenerateStub <IJobItemRepository>(),
                MockRepository.GenerateStub <IQuoteItemRepository>(),
                MockRepository.GenerateStub <IListItemRepository>(),
                MockRepository.GenerateStub <ICustomerRepository>());
            Edit(_deliveryItemForEditId, notes);
            Assert.IsTrue(_domainValidationException.ResultContainsMessage(DeliveryItemMessages.InvalidNotes));
        }
Beispiel #9
0
        public void Create_UserHasInsufficientSecurityClearance_DomainValidationExceptionThrown()
        {
            var id         = Guid.NewGuid();
            var deliveryId = Guid.NewGuid();
            var jobItemId  = _jobItemToUpdateId;
            var notes      = "some notes";

            _jobItemService      = JobItemServiceFactory.Create(_userContext, MockRepository.GenerateStub <IJobItemRepository>());
            _deliveryItemService = DeliveryItemServiceFactory.Create(
                TestUserContext.Create("*****@*****.**", "Graham Robertson", "Operations Manager", UserRole.Public),
                DeliveryRepositoryTestHelper.GetDeliveryRepository_StubsGetByIdForDeliveryWith1Item_ReturnsDelivery(deliveryId),
                MockRepository.GenerateStub <IDeliveryItemRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId),
                QuoteItemRepositoryTestHelper.GetQuoteItemRepository_StubsGetQuoteItemForJobItem_ReturnsQuoteItem(jobItemId),
                ListItemRepositoryTestHelper.GetListItemRepository_StubsGetByType_ReturnsListItem(new ListItemType[] { ListItemType.StatusDeliveryNoteProduced }),
                MockRepository.GenerateStub <ICustomerRepository>());
            CreateDeliveryItem(id, deliveryId, jobItemId, notes);
            Assert.IsTrue(_domainValidationException.ResultContainsMessage(DeliveryItemMessages.InsufficientSecurityClearance));
        }
Beispiel #10
0
        public void Create_NotesGreaterThan255Characters_DomainValidationExceptionThrown()
        {
            var id         = Guid.NewGuid();
            var deliveryId = Guid.NewGuid();
            var jobItemId  = _jobItemToUpdateId;
            var notes      = new string('a', 256);

            _jobItemService      = JobItemServiceFactory.Create(_userContext, MockRepository.GenerateStub <IJobItemRepository>());
            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                DeliveryRepositoryTestHelper.GetDeliveryRepository_StubsGetByIdForDeliveryWith1Item_ReturnsDelivery(deliveryId),
                MockRepository.GenerateStub <IDeliveryItemRepository>(),
                JobItemRepositoryTestHelper.GetJobItemRepository_StubsGetById_ReturnsJobItem(jobItemId),
                QuoteItemRepositoryTestHelper.GetQuoteItemRepository_StubsGetQuoteItemForJobItem_ReturnsQuoteItem(jobItemId),
                ListItemRepositoryTestHelper.GetListItemRepository_StubsGetByType_ReturnsListItem(new ListItemType[] { ListItemType.StatusDeliveryNoteProduced }),
                MockRepository.GenerateStub <ICustomerRepository>());
            CreateDeliveryItem(id, deliveryId, jobItemId, notes);
            Assert.IsTrue(_domainValidationException.ResultContainsMessage(DeliveryItemMessages.InvalidNotes));
        }
Beispiel #11
0
        public void Edit_ValidItemDetails_ItemEdited()
        {
            var notes = "some notes";

            var deliveryItemRepositoryMock = MockRepository.GenerateMock <IDeliveryItemRepository>();

            deliveryItemRepositoryMock.Stub(x => x.GetById(_deliveryItemForEditId)).Return(_deliveryItemForEdit);
            deliveryItemRepositoryMock.Expect(x => x.Update(null)).IgnoreArguments();
            _jobItemService      = JobItemServiceFactory.Create(_userContext, MockRepository.GenerateStub <IJobItemRepository>());
            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                MockRepository.GenerateStub <IDeliveryRepository>(),
                deliveryItemRepositoryMock,
                MockRepository.GenerateStub <IJobItemRepository>(),
                MockRepository.GenerateStub <IQuoteItemRepository>(),
                MockRepository.GenerateStub <IListItemRepository>(),
                MockRepository.GenerateStub <ICustomerRepository>());
            Edit(_deliveryItemForEditId, notes);
            deliveryItemRepositoryMock.VerifyAllExpectations();
            Assert.AreEqual(_deliveryItemForEditId, _deliveryItemForEdit.Id);
            Assert.AreEqual(notes, _deliveryItemForEdit.Notes);
        }
Beispiel #12
0
        public void Create_DeliveryWith0ItemsAndJobItemWithQuoteItem_DeliveryItemCreated()
        {
            var id         = Guid.NewGuid();
            var deliveryId = Guid.NewGuid();
            var jobItemId  = _jobItemToUpdateId;
            var notes      = "some notes";

            var deliveryRepositoryMock = MockRepository.GenerateMock <IDeliveryItemRepository>();

            deliveryRepositoryMock.Expect(x => x.Create(null)).IgnoreArguments();
            var jobItemRepositoryMock = MockRepository.GenerateMock <IJobItemRepository>();

            jobItemRepositoryMock.Stub(x => x.GetById(_jobItemToUpdateId)).Return(_jobItemToUpdate);
            jobItemRepositoryMock.Expect(x => x.EmitItemHistory(
                                             _userContext.GetCurrentUser(), _jobItemToUpdateId, 0, 0, "Item added to delivery note DR2000", ListItemType.StatusDeliveryNoteProduced, ListItemType.WorkTypeAdministration));
            jobItemRepositoryMock.Expect(x => x.Update(_jobItemToUpdate)).IgnoreArguments();

            _jobItemService      = JobItemServiceFactory.Create(_userContext, jobItemRepositoryMock);
            _deliveryItemService = DeliveryItemServiceFactory.Create(
                _userContext,
                DeliveryRepositoryTestHelper.GetDeliveryRepository_StubsGetByIdForDeliveryWith0Items_ReturnsDelivery(deliveryId),
                deliveryRepositoryMock,
                jobItemRepositoryMock,
                QuoteItemRepositoryTestHelper.GetQuoteItemRepository_StubsGetQuoteItemForJobItem_ReturnsQuoteItem(jobItemId),
                ListItemRepositoryTestHelper.GetListItemRepository_StubsGetByType_ReturnsListItem(new ListItemType[] { ListItemType.StatusDeliveryNoteProduced }),
                MockRepository.GenerateStub <ICustomerRepository>());
            CreateDeliveryItem(id, deliveryId, jobItemId, notes);
            deliveryRepositoryMock.VerifyAllExpectations();
            jobItemRepositoryMock.VerifyAllExpectations();
            Assert.AreNotEqual(Guid.Empty, _savedDeliveryItem.Id);
            Assert.AreEqual(1, _savedDeliveryItem.ItemNo);
            Assert.IsNotNull(_savedDeliveryItem.Delivery);
            Assert.IsNotNull(_savedDeliveryItem.JobItem);
            Assert.IsNotNull(_savedDeliveryItem.QuoteItem);
            Assert.AreEqual(ListItemType.StatusDeliveryNoteProduced, _jobItemToUpdate.Status.Type);
        }