public async Task <ICollection <OrderItem> > CreateOrderItems(ICollection <OrderItem> items) { var insertionTasks = new List <Task>(); var responses = new List <GraphQLResponse>(); foreach (var item in items) { var request = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.InsertClientOrderItem, new { ProductId = item.Product.Id, Count = item.Count }); insertionTasks.Add(Task.Run(async() => { responses.Add(await this._Client.PostAsync(request)); })); } await Task.WhenAll(insertionTasks.ToArray()); var orderItems = new List <OrderItem>(); foreach (var response in responses) { orderItems.Add(response.GetDataFieldAs <InsertResult <OrderItem> >("insert_ClientOrderItem").Result.First()); } return(orderItems); }
public async Task <Store> CreateStore(User admin, string name) { var request = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.InsertStore, new { AdminId = admin.Id, Name = name }); var response = await this._Client.PostAsync(request); var insertResult = response.GetDataFieldAs <InsertResult <Store> >("insert_Store"); var store = insertResult.Result.First(); var updateUserRequest = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.UpdateUser_SetStore, new { Id = admin.Id, StoreId = store.Id }); // No need to await the result await this._Client.PostAsync(updateUserRequest); return(store); }
public async Task <ProductCategory> CreateProductCategory(string name) { var request = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.InsertProductCategory, new { Name = name }); var response = await this._Client.PostAsync(request); var insertResponse = response.GetDataFieldAs <InsertResult <ProductCategory> >("insert_ProductCategory"); return(insertResponse.Result.First()); }
public async Task <Product> SetProvider(Product product, Guid providerId) { var request = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.UpdateProduct_SetProvider, new { ProductId = product.Id, ProviderId = providerId }); var response = await this._Client.PostAsync(request); var products = response.GetDataFieldAs <ICollection <Product> >("Product"); return(products.First()); }
public async void CreateProduct_CreatesEmptyProductLot() { var createAdminRequest = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.InsertUser, new { UserName = Guid.NewGuid().ToString(), FullName = Guid.NewGuid().ToString(), PasswordHash = SecurePasswordHasher.Hash(Guid.NewGuid().ToString()) }); var createAdminResponse = await this._Client.PostAsync(createAdminRequest); var admin = createAdminResponse.GetDataFieldAs <InsertResult <User> >("insert_User").Result.First(); var createStoreRequest = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.InsertStore, new { AdminId = admin.Id, Name = Guid.NewGuid().ToString() }); var createStoreResponse = await this._Client.PostAsync(createStoreRequest); var store = createStoreResponse.GetDataFieldAs <InsertResult <Store> >("insert_Store").Result.First(); var productCategory = await this._Repository.CreateProductCategory("TestProduct"); var product = await this._Repository.CreateProduct(store, Guid.NewGuid().ToString(), productCategory, 10.00); Assert.NotNull(product?.Id); Assert.NotNull(product?.ProductLot); var getProductLotRequest = GraphQLQueryManager.GetQueryRequest(GraphQLQueryManager.QueryRequest.GetProductLotByProductId, new { ProductId = product.Id }); var getProductLotResponse = await this._Client.PostAsync(getProductLotRequest); var getProductLotResult = getProductLotResponse.GetDataFieldAs <ICollection <ProductLot> >("ProductLot"); Assert.Equal(getProductLotResult.Count, 1); var productLot = getProductLotResult.First(); Assert.NotNull(productLot); Assert.Equal(productLot.Id, product.ProductLot.Id); Assert.Equal(productLot.Quantity, 0); }
public async Task <User> AddStaffMember(Store store, string userName, string fullName, string password) { var request = GraphQLMutationManager.GetMutationRequest(GraphQLMutationManager.MutationRequest.InsertUser, new { UserName = userName, FullName = fullName, PasswordHash = SecurePasswordHasher.Hash(password), StoreId = store.Id }); var response = await this._Client.PostAsync(request); var insertResult = response.GetDataFieldAs <InsertResult <User> >("insert_User"); return(insertResult.Result.First()); }
public async Task <ProductLot> AlterQuantity(ProductLot productLot, AlterQuantityDelegate @delegate) { var alterProductLotQuantityRequest = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.AlterProductLotQuantity, new { ProductLotId = productLot.Id, NewQuantity = @delegate(productLot.Quantity) }); var alterProductLotQuantityResponse = await this._Client.PostAsync(alterProductLotQuantityRequest); var alterProductLotQuantityResult = alterProductLotQuantityResponse.GetDataFieldAs <InsertResult <ProductLot> >("update_ProductLot"); return(alterProductLotQuantityResult.Result.First()); }
public StoreRepositoryTests() { var userName = Guid.NewGuid().ToString(); var fullName = Guid.NewGuid().ToString(); var passwordHash = SecurePasswordHasher.Hash(Guid.NewGuid().ToString()); var request = GraphQLMutationManager.GetMutationRequest(GraphQLMutationManager.MutationRequest.InsertUser, new { UserName = userName, FullName = fullName, PasswordHash = passwordHash, }); var response = this._Client.PostAsync(request).Result; this._Admin = response.GetDataFieldAs <InsertResult <User> >("insert_User").Result.First(); }
public async Task <ClientOrder> SubmitClientOrder(Guid authorId, ICollection <OrderItem> items) { var insertClientOrderRequest = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.InsertOrderClient, new { AuthorId = authorId }); var insertClientOrderResponse = await this._Client.PostAsync(insertClientOrderRequest); var clientOrder = insertClientOrderResponse.GetDataFieldAs <InsertResult <ClientOrder> >("insert_ClientOrder").Result.First(); var updateTasks = new List <Task>(); var updateResponses = new List <GraphQLResponse>(); foreach (var orderItem in items) { var updateClientOrderItemRequest = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.UpdateClientOrderItem_SetClientOrder, new { Id = orderItem.Id, ClientOrderId = clientOrder.Id }); updateTasks.Add(Task.Run(async() => { updateResponses.Add(await this._Client.PostAsync(updateClientOrderItemRequest)); })); } await Task.WhenAll(updateTasks.ToArray()); foreach (var response in updateResponses) { var orderItem = response.GetDataFieldAs <InsertResult <OrderItem> >("update_ClientOrderItem").Result.First(); if (clientOrder.Items == null) { clientOrder.Items = new List <OrderItem>(); } clientOrder.Items.Add(orderItem); } return(clientOrder); }
public async Task <User> CreateUser(string userName, string password, string fullName) { var request = GraphQLMutationManager.GetMutationRequest(GraphQLMutationManager.MutationRequest.InsertUser, new { UserName = userName, FullName = fullName, PasswordHash = SecurePasswordHasher.Hash(password) }); var response = await this._Client.PostAsync(request); if (response.Errors?.Length > 0) { throw new DuplicateUserException(userName); } var insertResult = response.GetDataFieldAs <InsertResult <User> >("insert_User"); return(insertResult.Result.First()); }
public async Task <Product> CreateProduct(Store store, string reference, ProductCategory category, double price, Provider provider = null, string name = null) { var insertProductRequest = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.InsertProduct, new { Reference = reference, CategoryId = category.Id, Price = price, Name = name, ProviderId = provider?.Id }); var insertProductResponse = await this._Client.PostAsync(insertProductRequest); var insertProductResult = insertProductResponse.GetDataFieldAs <InsertResult <Product> >("insert_Product"); var product = insertProductResult.Result.First(); var insertProductLotRequest = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.InsertProductLot, new { StoreId = store.Id, ProductId = product.Id }); var insertProductLotResponse = await this._Client.PostAsync(insertProductLotRequest); var insertProductLotResult = insertProductLotResponse.GetDataFieldAs <InsertResult <ProductLot> >("insert_ProductLot"); var productLot = insertProductLotResult.Result.First(); var updateProductLotRequest = GraphQLMutationManager.GetMutationRequest( GraphQLMutationManager.MutationRequest.UpdateProduct_SetProductLot, new { Id = product.Id, ProductLotId = productLot.Id }); var updateProductLotResponse = await this._Client.PostAsync(updateProductLotRequest); var updateResult = updateProductLotResponse.GetDataFieldAs <InsertResult <Product> >("update_Product"); return(updateResult.Result.First()); }