public async Task <IHttpActionResult> Post(Question question) { if (question == null) { return(BadRequest("Request doesn't have a valid question to save.")); } if (question.Skill == null) { return(BadRequest("Input question doesn't have a skill, add it in order to save it.")); } if (question.Competency == null) { return(BadRequest("Input question doesn't have a competency, add it in order to save it.")); } try { question.DocumentTypeId = DocumentType.Questions; var result = await commandRepository.Insert(question); return(Ok(result.Id)); } catch (Exception) { return(InternalServerError()); } }
public CommandModel Push <TCommand>(TCommand command, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified) where TCommand : Command { Ensure.That(command, () => command).IsNotNull(); _logger.Trace("Publishing {0}", command.Name); _logger.Trace("Checking if command is queued or started: {0}", command.Name); var existingCommands = QueuedOrStarted(command.Name); var existing = existingCommands.SingleOrDefault(c => CommandEqualityComparer.Instance.Equals(c.Body, command)); if (existing != null) { _logger.Trace("Command is already in progress: {0}", command.Name); return(existing); } var commandModel = new CommandModel { Name = command.Name, Body = command, QueuedAt = DateTime.UtcNow, Trigger = trigger, Priority = priority, Status = CommandStatus.Queued }; _logger.Trace("Inserting new command: {0}", commandModel.Name); _repo.Insert(commandModel); _commandQueue.Add(commandModel); return(commandModel); }
public void test_delete_of_department_should_delete_the_underlying_employee() { //Arrange using (ICommandRepository <Department> departmentCommandRepository = GetCommandRepositoryInstance <Department>()) using (ICommandRepository <Employee> employeeCommandRepository = GetCommandRepositoryInstance <Employee>()) using (IQueryableRepository <Employee> employeeQueryableRepository = GetQueryableRepositoryInstance <Employee>()) { //Arrange Department departmentFake = FakeData.GetDepartmentFake(); Employee employeeFake = FakeData.GetEmployeeFake(); employeeFake.EmployeeName = "XYZ"; employeeFake.DeptID = departmentFake.Id; employeeFake.Department = departmentFake; //Action //Employee insert will automatically insert the department object before inserting this employee object //since department object is marked as required in the employee map. employeeCommandRepository.Insert(employeeFake); // Should delete the employee object automatically since the map is defined so // (WillCascadeOnDelete is set to true). departmentCommandRepository.Delete(departmentFake); //Assert employeeQueryableRepository.Count().Should().Be(0); }; }
public async Task <IHttpActionResult> Post(Exercise exercise) { if (exercise == null) { return(BadRequest("Request doesn't have a valid exercise to save.")); } if (exercise.Skills == null || !exercise.Skills.Any()) { return(BadRequest("Input exercise doesn't have a skill, add it in order to save it.")); } if (exercise.Competency == null) { return(BadRequest("Input exercise doesn't have a competency, add it in order to save it.")); } try { exercise.DocumentTypeId = DocumentType.Exercises; var result = await commandRepository.Insert(exercise); return(Ok(result.Id)); } catch (Exception) { return(InternalServerError()); } }
public Task <Unit> Handle(CreateEmployee request, CancellationToken cancellationToken) { repository.Insert(new Employee { FirstName = request.FirstName, LastName = request.LastName, DateOfBirth = request.DateOfBirth }); return(Unit.Task); }
public void test_insert_multiple_employees_without_any_explicit_transaction_scope_should_be_saved() { //Arrange using (ICommandRepository <Department> departmentCommandRepository = GetCommandRepositoryInstance <Department>()) using (ICommandRepository <Employee> employeeCommandRepository = GetCommandRepositoryInstance <Employee>()) using (IQueryableRepository <Department> departmentQueryableRepository = GetQueryableRepositoryInstance <Department>()) using (IQueryableRepository <Employee> employeeQueryableRepository = GetQueryableRepositoryInstance <Employee>()) { //Arrange Department departmentFake = FakeData.GetDepartmentFake(); Employee managerEmployeeFake = FakeData.GetEmployeeFake(); managerEmployeeFake.EmployeeName = "XYZ"; managerEmployeeFake.DeptID = departmentFake.Id; managerEmployeeFake.Department = departmentFake; Employee subEmployeeFake = FakeData.GetEmployeeFake(2); subEmployeeFake.DeptID = departmentFake.Id; subEmployeeFake.Department = departmentFake; subEmployeeFake.ManagerId = managerEmployeeFake.Id; subEmployeeFake.Manager = managerEmployeeFake; //Action //Considering cascading inserts, here the order in which the list is inserted with different employee //objects is important. Since department object is defined as required in the EmployeMap class, //Effort(just like EF) automatically inserts the department object before inserting the employee objects. //But again in EmployeeMap class, Manager is marked as optional, so manager and the employees under him or her needs to //be explicitly inserted in proper order.Also here, EF doesn't ensure that if managerEmployeeFake gets //saved successfully and then subEmployeeFake doesn't get saved, then all the operations will be //rolled back (at the DB level). //And all these(inserting department object first, then manager object and then sub emloyee object), happens // internally within the same transaction (just like EF6) and one doesn't need to use the UnitOfWork class // (available in this project). employeeCommandRepository.Insert(new List <Employee> { managerEmployeeFake, subEmployeeFake }); //Assert departmentQueryableRepository.Count().Should().Be(1); employeeQueryableRepository.Count().Should().Be(2); employeeQueryableRepository.First().EmployeeName.Should().Be("XYZ"); employeeQueryableRepository.Single(x => x.EmployeeName == "Sandip").Id.Should().Be(2); // LINQ to Entities doesn't support the method "Last" and so will throw an exception.That's one of // the differences w.r.t LINQ to Objects.If tested with some mock(s) then the below code won't throw any // exception since internally mocks uses LINQ to Objects (atleast as far as LINQ in general is concerned) // and so true behaviour won't reflect using mocks. Action action = () => employeeQueryableRepository.Last(); action.ShouldThrow <NotSupportedException>(); }; }
/// <summary> /// /// </summary> /// <param name="event"></param> public void Handle(StockCreatedEvent @event) { _commandRepository.Insert(new Infrastructure.Model.Stock() { ID = @event.Id, StockType = @event.StockType, Up = @event.Up, Down = @event.Down, StockChange = @event.StockChange }); _commandRepository.Commit(); _interProcessBus.SendMessage("OrderCreatedEvent"); }
public int Insert(Command Value) { int commandId = _commandRepo.Insert(Value.CommandDAOToCommanDTO()); if (commandId > 0) { foreach (CommandWine cw in Value.CommandWine) { cw.IdCommand = commandId; _commandRepo.InsertCommandWine(cw.CommandWineDAOToCommandWineDTO()); } } return(commandId); }
public void test_insert_single_department_without_any_explicit_transaction_scope_should_be_saved() { //Arrange using (ICommandRepository <Department> departmentCommandRepository = GetCommandRepositoryInstance <Department>()) using (IQueryableRepository <Department> departmentQueryableRepository = GetQueryableRepositoryInstance <Department>()) { //Arrange Department departmentFake = FakeData.GetDepartmentFake(); //Action departmentCommandRepository.Insert(departmentFake); //Assert departmentQueryableRepository.Single().DepartmentName.Should().Be("Election"); }; }
public void test_insert_multiple_employees_alongwith_department_with_explicit_transaction_scope_with_exception_thrown_in_between_should_rollback() { //Arrange IUnitOfWork unitOfWorkWithExceptionToBeThrown = GetUnitOfWorkInstance(true); using (ICommandRepository <Department> departmentCommandRepository = GetCommandRepositoryInstance <Department>(unitOfWorkWithExceptionToBeThrown)) using (ICommandRepository <Employee> employeeCommandRepository = GetCommandRepositoryInstance <Employee>(unitOfWorkWithExceptionToBeThrown)) using (IQueryableRepository <Department> departmentQueryableRepository = GetQueryableRepositoryInstance <Department>()) using (IQueryableRepository <Employee> employeeQueryableRepository = GetQueryableRepositoryInstance <Employee>()) { //Arrange Department departmentFake = FakeData.GetDepartmentFake(); Department departmentFake2 = FakeData.GetDepartmentFake(2); Employee managerEmployeeFake = FakeData.GetEmployeeFake(); managerEmployeeFake.EmployeeName = "XYZ"; managerEmployeeFake.DeptID = departmentFake.Id; managerEmployeeFake.Department = departmentFake; Employee subEmployeeFake = FakeData.GetEmployeeFake(2); subEmployeeFake.DeptID = departmentFake.Id; subEmployeeFake.Department = departmentFake; subEmployeeFake.ManagerId = managerEmployeeFake.Id; subEmployeeFake.Manager = managerEmployeeFake; //Action /// Order of operations of different instances of same type or different types needs to be handled at /// the Business or Service Layer. employeeCommandRepository.Insert(new List <Employee> { managerEmployeeFake, subEmployeeFake }); departmentCommandRepository.Insert(departmentFake2); unitOfWorkWithExceptionToBeThrown.Commit(); //Assert departmentQueryableRepository.Count().Should().Be(0); employeeQueryableRepository.Count().Should().Be(0); }; }
public virtual bool Insert(TEntity item, Action operationToExecuteBeforeNextOperation = null) { CheckForObjectAlreadyDisposedOrNot(typeof(CommandDomainService <TEntity>).FullName); return(InvokeAfterWrappingWithinExceptionHandling(() => _repository.Insert(item, operationToExecuteBeforeNextOperation))); }
public void Insert(TEntity item) { ContractUtility.Requires <ArgumentNullException>(item.IsNotNull(), "item cannot be null"); _commandRepository.Insert(item); }
public virtual bool Insert(TEntity item, Action operationToExecuteBeforeNextOperation = null) { return(InvokeAfterWrappingWithinExceptionHandling(() => _repository.Insert(item, operationToExecuteBeforeNextOperation))); }
public virtual void Insert(TEntity entity) { _commandRepository.Insert(entity); }
public async Task InsertCommand(Command command) { await _commandRepository.Insert(command); }