public async Task <User> Login(string userName, string password) { var request = GraphQLQueryManager.GetQueryRequest( GraphQLQueryManager.QueryRequest.GetUserByUserName, new { UserName = userName }); var response = await this._Client.PostAsync(request); var users = response.GetDataFieldAs <ICollection <User> >("User"); if (!users.Any()) { throw new AccountNotFoundException(userName); } var user = users.First(); if (!SecurePasswordHasher.Verify(password, user.PasswordHash)) { throw new WrongPasswordException(); } return(user); }
public async void AddStaffMember_ReturnsStoreWithNewStaffMember() { var userName = Guid.NewGuid().ToString(); var store = await this._Repository.CreateStore(this._Admin, Guid.NewGuid().ToString()); var newStaffMember = await this._Repository.AddStaffMember(userName : userName, fullName : Guid.NewGuid().ToString(), password : Guid.NewGuid().ToString(), store : store); var getStoreByIdRequest = GraphQLQueryManager.GetQueryRequest( GraphQLQueryManager.QueryRequest.GetStoreById, new { Id = store.Id }); var response = await this._Client.PostAsync(getStoreByIdRequest); var stores = response.GetDataFieldAs <ICollection <Store> >("Store"); Assert.NotEmpty(stores); var returnedStore = stores.First(); Assert.Equal(returnedStore.Id, store.Id); Assert.Equal(returnedStore.Name, store.Name); Assert.Contains(returnedStore.StaffMembers, user => user.Id == newStaffMember.Id); }
public async void CreateUser_AddsUserRowIntoDatabase() { var userName = Guid.NewGuid().ToString(); var fullName = Guid.NewGuid().ToString(); var password = Guid.NewGuid().ToString(); await this._Repository.CreateUser(userName : userName, password : password, fullName : fullName); var request = GraphQLQueryManager.GetQueryRequest( GraphQLQueryManager.QueryRequest.GetUserByUserName, new { UserName = userName }); var response = await this._Client.PostAsync(request); var users = response.GetDataFieldAs <ICollection <User> >("User"); Assert.NotEmpty(users); var user = users.First(); Assert.Equal(userName, user.UserName); Assert.Equal(fullName, user.FullName); Assert.True(SecurePasswordHasher.Verify(password, user.PasswordHash)); }
public async void AddStaffMember_CreatesMember() { var userName = Guid.NewGuid().ToString(); var store = await this._Repository.CreateStore(this._Admin, Guid.NewGuid().ToString()); await this._Repository.AddStaffMember(userName : userName, fullName : Guid.NewGuid().ToString(), password : Guid.NewGuid().ToString(), store : store); var getUserByUserNameRequest = GraphQLQueryManager.GetQueryRequest( GraphQLQueryManager.QueryRequest.GetUserByUserName, new { UserName = userName }); var response = await this._Client.PostAsync(getUserByUserNameRequest); var users = response.GetDataFieldAs <ICollection <User> >("User"); Assert.NotEmpty(users); var user = users.First(); Assert.Equal(user.UserName, userName); Assert.NotNull(user.Store); Assert.Equal(user.Store.Id, store.Id); Assert.Equal(user.Store.Name, store.Name); }
public async Task <ICollection <Product> > GetProductsByStoreId(Guid storeId) { var request = GraphQLQueryManager.GetQueryRequest(GraphQLQueryManager.QueryRequest.GetProductsByStoreId, new { StoreId = storeId }); var response = await this._Client.PostAsync(request); return(response.GetDataFieldAs <ICollection <Product> >("Product")); }
public async Task <ICollection <User> > GetStoreStaffMembers(Store store) { var request = GraphQLQueryManager.GetQueryRequest(GraphQLQueryManager.QueryRequest.GetStoreStaffMembers, new { StoreId = store.Id }); var response = await this._Client.PostAsync(request); return(response.GetDataFieldAs <ICollection <User> >("User")); }
public async Task <ICollection <ClientOrder> > SelectOrders(Guid storeId, ClientOrderFilter filter) { var request = GraphQLQueryManager.GetQueryRequest(GraphQLQueryManager.QueryRequest.GetClientOrdersForStore, new { StoreId = storeId }); var response = await this._Client.PostAsync(request); var results = response.GetDataFieldAs <ICollection <ClientOrder> >("ClientOrder"); return(results.Where(order => filter(order)).ToList()); }
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 void CreateStore_InsertsIntoDatabaseAndReturnsId() { var store = this._Repository.CreateStore(admin: this._Admin, name: Guid.NewGuid().ToString()).Result; var getStoreByIdRequest = GraphQLQueryManager.GetQueryRequest( GraphQLQueryManager.QueryRequest.GetStoreById, new { Id = store.Id }); var getStoreByIdResponse = await this._Client.PostAsync(getStoreByIdRequest); var stores = getStoreByIdResponse.GetDataFieldAs <ICollection <Store> >("Store"); Assert.NotEmpty(stores); Assert.Equal(store.Id, stores.First().Id); Assert.Equal(store.Name, stores.First().Name); Assert.Equal(store.Admin.Id, stores.First().Admin.Id); Assert.Equal(store.Admin.UserName, stores.First().Admin.UserName); }
public async Task <Product> GetProductById(Guid id) { var request = GraphQLQueryManager.GetQueryRequest( GraphQLQueryManager.QueryRequest.GetProductById, new { Id = id } ); var response = await this._Client.PostAsync(request); var products = response.GetDataFieldAs <ICollection <Product> >("Product"); if (products.Count == 0) { throw new ProductNotFoundException(id); } return(products.First()); }
public async void CreateProductCategory_InsertsIntoDatabase() { var productCategory = await this._Repository.CreateProductCategory("TestProduct"); Assert.NotNull(productCategory); Assert.NotNull(productCategory.Id); var getCategoryByIdRequest = GraphQLQueryManager.GetQueryRequest( GraphQLQueryManager.QueryRequest.GetProductCategoryById, new { Id = productCategory.Id }); var getCategoryByIdResponse = await this._Client.PostAsync(getCategoryByIdRequest); var getCategoryByIdResult = getCategoryByIdResponse.GetDataFieldAs <ICollection <ProductCategory> >("ProductCategory"); Assert.NotEmpty(getCategoryByIdResult); Assert.Equal(productCategory.Id, getCategoryByIdResult.First().Id); Assert.Equal(productCategory.Name, getCategoryByIdResult.First().Name); Assert.Equal(productCategory.Products.Count, getCategoryByIdResult.First().Products.Count); }