public async Task ListShoppingListItems__HappyCase() { // arrange CreateShoppingListRequest request = new CreateShoppingListRequest { Name = "Test record", UserId = TestConstants.TestUser }; CreateShoppingListResponse shoppingListResponse = await _mediator.Send(request); var createShoppingListItemResponse = await _mediator.Send(new CreateShoppingListItemRequest { Completed = false, Price = 3, ProductCategory = "Pet", ProductName = "Cat", ShoppingListId = shoppingListResponse.Id, Qty = 3, UnitPrice = 5, UserId = "mrosario" }); // Act var shoppingListItemsResponse = await _mediator.Send(new ListShoppingListItemRequest { ShoppingListId = shoppingListResponse.Id }); // Assert Assert.IsTrue(shoppingListItemsResponse.Records.Count == 1); }
public async Task <IActionResult> Create(String Name) { CreateShoppingListRequest createShoppingListRequest = new CreateShoppingListRequest { Name = Name }; CreateShoppingListResponse response = null; try { response = await _mediator.Send(createShoppingListRequest); } catch (RequestValidationException rve) { foreach (var validationException in rve.ValidationErrors) { ModelState.AddModelError(validationException.PropertyName, validationException.ErrorMessage); } return(View(new ShoppingList { Name = Name })); } return(RedirectToAction("Index")); }
public async Task CreateShoppingListWithOneItem() { // arrange CreateShoppingListRequest request = new CreateShoppingListRequest { Name = "Test record", UserId = TestConstants.TestUser }; CreateShoppingListResponse response = await _mediator.Send(request); // Act var createShoppingListItemResponse = await _mediator.Send(new CreateShoppingListItemRequest { Completed = false, Price = 3, ProductCategory = "Pet", ProductName = "Cat", ShoppingListId = response.Id, Qty = 3, UnitPrice = 5, UserId = "mrosario" }); // Assert var getRecordResponse = await _mediator.Send(new GetShoppingListItemRequest { Id = createShoppingListItemResponse.Id, UserId = "mrosario" }); Assert.IsTrue(getRecordResponse.Code == Enums.ResponseCode.Success); }
public override async Task <ShoppingListReply> CreateShoppingList(CreateShoppingListRequest request, ServerCallContext context) { var shoppingList = new ShoppingList() { Name = request.Name, Items = new List <ShoppingListItem>() }; return(AsReply(await _repository.Save(shoppingList))); }
public async Task CreateShoppingList__PassNoName() { // arrange var request = new CreateShoppingListRequest { Name = "" }; // Act CreateShoppingListResponse response = await _mediator.Send(request); Assert.IsTrue(response.ValidationErrors.Count > 0); }
private async Task <string> createShoppingList() { CreateShoppingListRequest request = new CreateShoppingListRequest { Name = "Test record", UserId = TestConstants.TestUser }; CreateShoppingListResponse response = await _mediator.Send(request); string shoppingListId = response.Id; return(shoppingListId); }
public async void ShouldCreateAShoppingList() { var request = new CreateShoppingListRequest { Name = "First list" }; var actual = await _client.CreateShoppingListAsync(request); Assert.NotNull(actual); Assert.NotNull(actual.Id); Assert.Equal(24, actual.Id.Length); Assert.Equal(request.Name, actual.Name); }
public async Task CreateShoppingList__HappyCase() { // arrange CreateShoppingListRequest request = new CreateShoppingListRequest { Name = "Test record", UserId = TestConstants.TestUser }; // Act CreateShoppingListResponse response = await _mediator.Send(request); // Assert Assert.IsTrue(response != null, "response is defined"); }
public async void ShouldCreateAShoppingListAndPutItemsOnIt() { var shoppingListRequest = new CreateShoppingListRequest { Name = "First list" }; var shoppingList = await _client.CreateShoppingListAsync(shoppingListRequest); Assert.NotNull(shoppingList); var potatoItem = new AddShoppingListItemRequest { ShoppingListId = shoppingList.Id, Name = "Potato", Amount = 1, Unit = Unit.Kg }; var brocolliItem = new AddShoppingListItemRequest { ShoppingListId = shoppingList.Id, Name = "Potato", Amount = 1, Unit = Unit.Kg }; var actualPotato = await _client.AddShoppingListItemAsync(potatoItem); var actualBrocolli = await _client.AddShoppingListItemAsync(brocolliItem); var actualList = await _client.FindShoppingListAsync(new FindListsRequest { Id = shoppingList.Id }); Assert.NotNull(actualPotato); Assert.NotNull(actualBrocolli); Assert.NotNull(actualList); Assert.Equal(shoppingList.Id, actualList.Id); var actualItems = actualList.Items.ToList(); Assert.Equal(new List <ShoppingListItemReply> { actualPotato, actualBrocolli }, actualItems); }
public async Task <IActionResult> CreateShoppingList([FromBody] CreateShoppingListRequest request) { var response = await _mediator.Send(request); return(Json(response)); }
public async Task <ActionResult <OutputShoppingListData> > CreateShoppingList([FromBody] CreateShoppingListRequest request, CancellationToken cancellationToken) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var shoppingList = await shoppingListService.CreateShoppingListFromTemplate(request.TemplateId.ToId(), cancellationToken); return(Created(GetShoppingListUri(shoppingList.Id), new OutputShoppingListData(shoppingList))); }