public void Validate_NoValidationErrors() { // Arrange var command = new CreateNotebookCommand { Name = new string('a', 199) }; // Act var result = _validator.Validate(command); // Assert Assert.IsFalse(result.Errors.Any()); }
public void Validate_ValidationErrors() { // Arrange var command = new CreateNotebookCommand { Name = new string('a', 201) }; // Act var result = _validator.Validate(command); // Assert Assert.IsTrue(result.Errors.Single().ErrorMessage.Contains("200 characters or fewer")); }
public async Task Handle_NotebookShouldBeAdded() { // Arrange var request = new CreateNotebookCommand { Name = "Notebook 01" }; // Act var result = await _handler.Handle(request, CancellationToken.None); // Assert var notebook = await _wolkDbContext.Notebooks.SingleAsync(n => n.Id == result.Id); ShouldBeEqual(notebook, result); }
private IResult <Notebook> CreateNotebook(DateTime timestamp, Employee employee, string comment) { var createNotebookResult = new CreateNotebookCommand(_inventoryUnitOfWork).Execute(timestamp); if (!createNotebookResult.Success) { return(createNotebookResult.ConvertTo((Notebook)null)); } var notebook = createNotebookResult.ResultingObject; if (!string.IsNullOrWhiteSpace(comment)) { var createNoteResult = new CreateNoteCommand(_inventoryUnitOfWork).Execute(notebook, timestamp, employee, comment); if (!createNoteResult.Success) { return(createNoteResult.ConvertTo((Notebook)null)); } } return(new SuccessResult <Notebook>(notebook)); }
public IResult <ProductionBatch> Execute(DateTime timestamp, CreateProductionBatchCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var packSchedule = _productionUnitOfWork.PackScheduleRepository.FindByKey(parameters.PackScheduleKey, p => p.ChileProduct); if (packSchedule == null) { return(new InvalidResult <ProductionBatch>(null, string.Format(UserMessages.PackScheduleNotFound, parameters.PackScheduleKey.KeyValue))); } var employeeResult = new GetEmployeeCommand(_productionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ProductionBatch>()); } var createChileLotCommand = new CreateNewChileLotCommand(_productionUnitOfWork); var createChileLotResult = createChileLotCommand.Execute(new CreateNewChileLotCommandParameters { EmployeeKey = employeeResult.ResultingObject, TimeStamp = timestamp, PackagingReceivedKey = packSchedule, ChileProductKey = new ChileProductKey(packSchedule), LotType = parameters.Parameters.LotType ?? packSchedule.ChileProduct.ChileState.ToLotType(), LotDate = parameters.Parameters.LotDateCreated?.Date ?? timestamp, LotSequence = parameters.Parameters.LotSequence, SetLotProductionStatus = LotProductionStatus.Batched, SetLotQualityStatus = LotQualityStatus.Pending }); if (!createChileLotResult.Success) { return(createChileLotResult.ConvertTo <ProductionBatch>()); } var chileLot = createChileLotResult.ResultingObject; chileLot.Lot.Notes = parameters.Parameters.Notes.TrimTruncate(Constants.StringLengths.LotNotes); var productionResult = new CreateChileLotProductionCommand(_productionUnitOfWork).Execute(new CreateChileLotProduction { TimeStamp = timestamp, EmployeeKey = employeeResult.ResultingObject, LotKey = chileLot, ProductionType = ProductionType.ProductionBatch }); if (!productionResult.Success) { return(productionResult.ConvertTo <ProductionBatch>()); } var production = productionResult.ResultingObject; var notebookResult = new CreateNotebookCommand(_productionUnitOfWork).Execute(timestamp, employeeResult.ResultingObject, parameters.Parameters.Instructions); if (!notebookResult.Success) { return(notebookResult.ConvertTo <ProductionBatch>()); } var notebook = notebookResult.ResultingObject; var productionBatch = new ProductionBatch { EmployeeId = employeeResult.ResultingObject.EmployeeId, TimeStamp = timestamp, LotDateCreated = chileLot.LotDateCreated, LotDateSequence = chileLot.LotDateSequence, LotTypeId = chileLot.LotTypeId, PackScheduleDateCreated = parameters.PackScheduleKey.PackScheduleKey_DateCreated, PackScheduleSequence = parameters.PackScheduleKey.PackScheduleKey_DateSequence, InstructionNotebook = notebook, InstructionNotebookDateCreated = notebook.Date, InstructionNotebookSequence = notebook.Sequence, ProductionHasBeenCompleted = false, TargetParameters = new ProductionBatchTargetParameters(parameters.Parameters), Production = production }; _productionUnitOfWork.ProductionBatchRepository.Add(productionBatch); return(new SuccessResult <ProductionBatch>(productionBatch)); }
public async Task <ActionResult> CreateNotebook([FromBody] CreateNotebookCommand createNotebookCommand) { var commandResult = await _mediator.Send(createNotebookCommand); return(commandResult ? (ActionResult)Ok() : (ActionResult)BadRequest()); }
internal IResult <Contract> Execute(CreateCustomerContractCommandParameters parameters, DateTime timeStamp) { if (parameters == null) { throw new ArgumentNullException("parameters"); } if (timeStamp == null) { throw new ArgumentNullException("timeStamp"); } var customer = _salesUnitOfWork.CustomerRepository.FindByKey(parameters.CustomerKey, c => c.Company.Contacts.Select(n => n.Addresses), c => c.ProductCodes); if (customer == null) { return(new InvalidResult <Contract>(null, string.Format(UserMessages.CustomerNotFound, parameters.CustomerKey.KeyValue))); } var facilityKey = parameters.DefaultPickFromFacilityKey ?? new FacilityKey(GlobalKeyHelpers.RinconFacilityKey); var facility = _salesUnitOfWork.FacilityRepository.FindByKey(facilityKey); if (facility == null) { return(new InvalidResult <Contract>(null, string.Format(UserMessages.FacilityNotFound, facilityKey.KeyValue))); } var employeeResult = new GetEmployeeCommand(_salesUnitOfWork).GetEmployee(parameters.CreateCustomerContractParameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <Contract>()); } var commentsNotebookResult = new CreateNotebookCommand(_salesUnitOfWork).Execute(timeStamp, employeeResult.ResultingObject, parameters.CreateCustomerContractParameters.Comments); if (!commentsNotebookResult.Success) { return(commentsNotebookResult.ConvertTo <Contract>()); } var contractYear = timeStamp.Year; var contractSequence = new EFUnitOfWorkHelper(_salesUnitOfWork).GetNextSequence <Contract>(c => c.ContractYear == contractYear, c => c.ContractSequence); var contract = _salesUnitOfWork.ContractRepository.Add(new Contract { EmployeeId = employeeResult.ResultingObject.EmployeeId, TimeStamp = timeStamp, TimeCreated = timeStamp, ContractYear = contractYear, ContractSequence = contractSequence, CustomerId = customer.Id, BrokerId = customer.BrokerId, DefaultPickFromWarehouseId = facility.Id, CommentsDate = commentsNotebookResult.ResultingObject.Date, CommentsSequence = commentsNotebookResult.ResultingObject.Sequence, Customer = customer, ContractId = _salesUnitOfWork.ContractRepository.SourceQuery.Select(c => c.ContractId).DefaultIfEmpty(0).Max() + 1 }); return(new UpdateCustomerContractConductor(_salesUnitOfWork).SetCustomerContract(contract, employeeResult.ResultingObject, timeStamp, parameters)); }