public async Task Does_not_add_a_PlaceholderComponent_with_a_non_existing_Id_and_sets_Error_to_NotFound() { var addComponentCommand = new AddComponentCommand(9999); await addComponentCommand.Process(virtualStudio); Assert.IsNotNull(addComponentCommand.Error); Assert.IsTrue(addComponentCommand.Error.Type == ErrorType.NotFound); Assert.IsTrue(virtualStudio.Components.Count == 0); }
public async Task <ActionResult <ComponentResource> > CreateComponentAsync([FromBody] AddComponentCommand componentCommand) { var componentResource = await _mediator.Send(componentCommand); return(CreatedAtAction( nameof(GetComponentAsync), new { id = componentResource.Id, version = RequestedApiVersion }, componentResource)); }
public async Task Adds_a_cloned_PlaceholderComponent_from_ComponentRepository() { var placeholder = virtualStudio.ComponentRepository.Placeholders.First(); var addComponentCommand = new AddComponentCommand(placeholder.Id); await addComponentCommand.Process(virtualStudio); Assert.IsTrue(virtualStudio.Components.Count == 1); var addedPlaceholder = virtualStudio.Components.First(); Assert.AreNotEqual(placeholder.Id, addedPlaceholder.Id); }
public async Task <Component> Add(AddComponentCommand command) { var component = new Component { Id = Guid.NewGuid(), Name = command.Name, Amount = command.Amount }; await _componentRepository.Add(component); return(component); }
public async Task Adds_a_ClientComponent_from_ComponentRepository() { var clientComponentMock = new Mock <IStudioComponent>(); int clientComponentMockId = 2; clientComponentMock.SetupGet(c => c.Id).Returns(clientComponentMockId); virtualStudio.ComponentRepository.AddClient(clientComponentMock.Object); var addComponentCommand = new AddComponentCommand(clientComponentMockId); await addComponentCommand.Process(virtualStudio); Assert.IsTrue(virtualStudio.Components.Count == 1); Assert.AreEqual(clientComponentMockId, virtualStudio.Components.First().Id); }
public async Task Does_not_add_a_ClientComponent_that_already_exists_in_Components_and_sets_Error_to_InvalidOperation() { var clientComponentMock = new Mock <IStudioComponent>(); int clientComponentMockId = 2; clientComponentMock.SetupGet(c => c.Id).Returns(clientComponentMockId); virtualStudio.ComponentRepository.AddClient(clientComponentMock.Object); await new AddComponentCommand(clientComponentMockId).Process(virtualStudio); var addComponentCommand = new AddComponentCommand(clientComponentMockId); await addComponentCommand.Process(virtualStudio); Assert.IsTrue(virtualStudio.Components.Count == 1); Assert.IsTrue(addComponentCommand.Error.Type == ErrorType.InvalidOperation); }
public async Task <Component> Add(AddComponentCommand command) { var component = new Component { Id = Guid.NewGuid(), Name = command.Name, Brand = command.Brand, Description = command.Description, ImagePath = command.ImagePath, Price = command.Price, Amount = command.Amount, Type = command.Type }; await _componentRepository.Add(component); return(component); }
public async Task <ActionResult> Post([FromBody] AddComponentCommand command) { var result = await _componentService.Add(command); return(Ok(result)); }