public void Create_ValidDetailsSuppliedConsignmentHas1Items_SuccessfullyCreated() { var id = Guid.NewGuid(); var consignmentId = Guid.NewGuid(); var instructions = "Consignment instructions"; var consignmentItemRepositoryMock = MockRepository.GenerateMock <IConsignmentItemRepository>(); consignmentItemRepositoryMock.Expect(x => x.Create(null)).IgnoreArguments(); var jobItemRepositoryMock = MockRepository.GenerateMock <IJobItemRepository>(); jobItemRepositoryMock.Stub(x => x.GetById(_jobItemToUpdate.Id)).Return(_jobItemToUpdate); jobItemRepositoryMock.Expect(x => x.EmitItemHistory( _userContext.GetCurrentUser(), _jobItemToUpdate.Id, 0, 0, "Item consigned on CR2000", ListItemType.StatusConsigned, ListItemType.WorkTypeAdministration)); jobItemRepositoryMock.Expect(x => x.Update(_jobItemToUpdate)).IgnoreArguments(); _consignmentItemService = ConsignmentItemServiceFactory.Create(consignmentItemRepositoryMock, jobItemRepositoryMock, consignmentId, _userContext, 1); _jobItemService = _jobItemService = JobItemServiceFactory.CreateToReturnJobItem(jobItemRepositoryMock, _userContext); CreateConsignmentItem(id, _jobItemToUpdate.Id, consignmentId, instructions); consignmentItemRepositoryMock.VerifyAllExpectations(); jobItemRepositoryMock.VerifyAllExpectations(); Assert.AreNotEqual(Guid.Empty, _savedConsigmentItem.Id); Assert.AreEqual(2, _savedConsigmentItem.ItemNo); Assert.AreEqual(ListItemType.StatusConsigned, _jobItemToUpdate.Status.Type); }
public void Create_InvalidJobItemIdSupplied_ArgumentExceptionThrown() { var id = Guid.NewGuid(); var consignmentId = Guid.NewGuid(); var instructions = "Consignment instructions"; var jobItemRepositoryMock = MockRepository.GenerateMock <IJobItemRepository>(); jobItemRepositoryMock.Stub(x => x.GetById(Guid.NewGuid())).Return(null); _consignmentItemService = ConsignmentItemServiceFactory.Create(MockRepository.GenerateStub <IConsignmentItemRepository>(), jobItemRepositoryMock, consignmentId, _userContext); _jobItemService = _jobItemService = JobItemServiceFactory.CreateToReturnJobItem(jobItemRepositoryMock, _userContext); CreateConsignmentItem(id, _jobItemToUpdate.Id, consignmentId, instructions); }
public void Create_InstructionsGreaterThan10000Characters_DomainValidationExceptionThrown() { var id = Guid.NewGuid(); var consignmentId = Guid.NewGuid(); var instructions = new string('a', 10001); var jobItemRepositoryMock = MockRepository.GenerateMock <IJobItemRepository>(); jobItemRepositoryMock.Stub(x => x.GetById(_jobItemToUpdate.Id)).Return(_jobItemToUpdate); _consignmentItemService = ConsignmentItemServiceFactory.Create(MockRepository.GenerateStub <IConsignmentItemRepository>(), jobItemRepositoryMock, consignmentId, _userContext); _jobItemService = _jobItemService = JobItemServiceFactory.CreateToReturnJobItem(jobItemRepositoryMock, _userContext); CreateConsignmentItem(id, _jobItemToUpdate.Id, consignmentId, instructions); Assert.IsTrue(_domainValidationException.ResultContainsMessage(Messages.InstructionsTooLarge)); }
public void Create_NoIdSupplied_ArgumentExceptionThrown() { var id = Guid.Empty; var consignmentId = Guid.NewGuid(); var instructions = "Consignment instructions"; _jobItemToUpdate.Job.IsPending = true; var jobItemRepositoryStub = MockRepository.GenerateMock <IJobItemRepository>(); jobItemRepositoryStub.Stub(x => x.GetById(_jobItemToUpdate.Id)).Return(_jobItemToUpdate); _consignmentItemService = ConsignmentItemServiceFactory.Create(MockRepository.GenerateStub <IConsignmentItemRepository>(), jobItemRepositoryStub, consignmentId, _userContext); _jobItemService = _jobItemService = JobItemServiceFactory.CreateToReturnJobItem(jobItemRepositoryStub, _userContext); CreateConsignmentItem(id, _jobItemToUpdate.Id, consignmentId, instructions); Assert.IsTrue(_domainValidationException.ResultContainsMessage(Messages.PendingJob)); }
public void Create_UserHasInsufficientSecurityClearance_ArgumentExceptionThrown() { var id = Guid.NewGuid(); var consignmentId = Guid.NewGuid(); var instructions = "Consignment instructions"; var jobItemRepositoryMock = MockRepository.GenerateMock <IJobItemRepository>(); jobItemRepositoryMock.Stub(x => x.GetById(Guid.NewGuid())).Return(null); _consignmentItemService = ConsignmentItemServiceFactory.Create( MockRepository.GenerateStub <IConsignmentItemRepository>(), jobItemRepositoryMock, consignmentId, TestUserContext.Create("*****@*****.**", "Graham Robertson", "Operations Manager", UserRole.Public)); _jobItemService = _jobItemService = JobItemServiceFactory.CreateToReturnJobItem(jobItemRepositoryMock, TestUserContext.Create("*****@*****.**", "Graham Robertson", "Operations Manager", UserRole.Public)); CreateConsignmentItem(id, _jobItemToUpdate.Id, consignmentId, instructions); Assert.IsTrue(_domainValidationException.ResultContainsMessage(Messages.InsufficientSecurityClearance)); }