public async Task CreateAsync_Should_Create_Successfully() { //Arrange var context = Context; IOfficeBusiness officeBusiness = new OfficeBusiness(context, _mapper, _cache, _busMock.Object); CreateOfficeCommand command = new CreateOfficeCommand { Location = "Amsterdam", OpenTime = DateTime.Now.TimeOfDay, CloseTime = DateTime.Now.AddHours(1).TimeOfDay }; //Act await officeBusiness.CreateAsync(command); var addedOffice = await context.Offices .FirstOrDefaultAsync(); //Assert Assert.NotNull(addedOffice); Assert.Equal("Amsterdam", addedOffice.Location); }
public async Task CreateAsync_Should_Publish_Event_Successfully() { //Arrange var context = Context; var harness = new InMemoryTestHarness(); await harness.Start(); IOfficeBusiness officeBusiness = new OfficeBusiness(context, _mapper, _cache, harness.Bus); CreateOfficeCommand command = new CreateOfficeCommand { Location = "Amsterdam", OpenTime = DateTime.Now.TimeOfDay, CloseTime = DateTime.Now.AddHours(1).TimeOfDay }; //Act await officeBusiness.CreateAsync(command); //Assert try { Assert.True(await harness.Published.Any <OfficeCreated>()); } finally { await harness.Stop(); } }
public async Task <ActionResult <Office> > CreateOffice([FromBody] CreateOfficeRequest request) { var command = new CreateOfficeCommand(request.OfficeCode); var response = await _mediator.Send(command); var office = _mapper.Map <Office>(response); return(CreatedAtAction("Get", "Office", new { OfficeId = office.UniqueId }, office)); }
public async Task CreateAsync(CreateOfficeCommand command) { Check.NotNull(command, nameof(command)); Office office = _mapper.Map <Office>(command); await _applicationContext.Offices.AddAsync(office); await _applicationContext.SaveChangesAsync(); await _bus.Publish <OfficeCreated>(new { OfficeId = office.Id }); }
public async Task <IActionResult> CreateOfficeAsync([FromBody] CreateOfficeCommand createOfficeCommand) { await _officeBusiness.CreateAsync(createOfficeCommand); return(Ok()); }
public Task CreateOffice([FromBody] CreateOfficeCommand command) { return(Mediator.Send(command)); }