// PUT odata/ResourcePool(5) public virtual async Task<IHttpActionResult> Put([FromODataUri] int key, ResourcePool resourcePool) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != resourcePool.Id) { return BadRequest(); } try { await MainUnitOfWork.UpdateAsync(resourcePool); } catch (DbUpdateConcurrencyException) { if (!MainUnitOfWork.Exists(key)) { return NotFound(); } else { return Conflict(); } } return Ok(resourcePool); }
// POST odata/ResourcePool public override async Task<IHttpActionResult> Post(ResourcePool resourcePool) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { var currentUser = await GetCurrentUserAsync(); await MainUnitOfWork.InsertAsync(resourcePool); } catch (DbUpdateException) { if (MainUnitOfWork.Exists(resourcePool.Id)) { return Conflict(); } else { throw; } } return Created(resourcePool); }
public async Task AddUserResourcePool_IdShouldBeBiggerThanZero() { // Arrange var userStore = new UserStore(Context); userStore.AutoSaveChanges = false; var user = new User("User"); await userStore.CreateAsync(user); await Context.SaveChangesAsync(); LoginAs(user); var resourcePool = new ResourcePool(user, "ResourcePool"); var userResourcePool = resourcePool.AddUserResourcePool(100); // Act resourcePoolRepository.Insert(resourcePool); await Context.SaveChangesAsync(); // Assert Assert.IsTrue(user.Id > 0); Assert.IsTrue(resourcePool.Id > 0); //Assert.IsTrue(userResourcePool.Id > 0); }
public Element(ResourcePool resourcePool, string name) : this() { Validations.ArgumentNullOrDefault(resourcePool, "resourcePool"); Validations.ArgumentNullOrDefault(name, "name"); ResourcePool = resourcePool; Name = name; }
public UserResourcePool(ResourcePool resourcePool, decimal resourcePoolRate) : this() { // Validations.ArgumentNullOrDefault(user, "user"); Validations.ArgumentNullOrDefault(resourcePool, "resourcePool"); // User = user; ResourcePool = resourcePool; ResourcePoolRate = resourcePoolRate; //UserElementFieldIndexSet = new HashSet<UserElementFieldIndex>(); }
public async Task InsertNewResourcePool_IdShouldBeBiggerThanZero() { // Arrange var user = new User("User"); var resourcePool = new ResourcePool(user, "ResourcePool"); // Act resourcePoolRepository.Insert(resourcePool); await Context.SaveChangesAsync(); // Assert Assert.IsTrue(resourcePool.Id > 0); }
public async Task DbInterceptor_ShouldOnlyGetAuthenticatedUserData() { // Arrange var userStore = new UserStore(Context); userStore.AutoSaveChanges = false; var user1 = new User("User 1"); var user2 = new User("User 2"); await userStore.CreateAsync(user1); await userStore.CreateAsync(user2); await Context.SaveChangesAsync(); // Act var resourcePool = new ResourcePool(user1, "ResourcePool"); resourcePoolRepository.Insert(resourcePool); LoginAs(user1); resourcePool.AddUserResourcePool(100); await Context.SaveChangesAsync(); LoginAs(user2); resourcePool.AddUserResourcePool(100); await Context.SaveChangesAsync(); // Assert: Clear the context and retrieve the data one more time, it should only get the authenticated user's data RefreshStore(); var resourcePoolFromDb = resourcePoolRepository .AllLiveIncluding(item => item.UserResourcePoolSet) .OrderByDescending(item => item.CreatedOn) .First(); Assert.IsTrue(resourcePoolFromDb.Id == resourcePool.Id); Assert.IsTrue(resourcePoolFromDb.UserResourcePoolSet.Count == 1); Assert.IsTrue(resourcePoolFromDb.UserResourcePoolSet.Single().UserId == user2.Id); }
public async Task DbInterceptor_NoLoggedInUser_ShouldNotGetAnyUserData() { // Arrange var userStore = new UserStore(Context); userStore.AutoSaveChanges = false; var user1 = new User("User 1"); var user2 = new User("User 2"); await userStore.CreateAsync(user1); await userStore.CreateAsync(user2); await Context.SaveChangesAsync(); // Act var resourcePool = new ResourcePool(user1, "ResourcePool"); resourcePoolRepository.Insert(resourcePool); LoginAs(user1); resourcePool.AddUserResourcePool(100); await Context.SaveChangesAsync(); LoginAs(user2); resourcePool.AddUserResourcePool(100); await Context.SaveChangesAsync(); // Assert: Clear the context and retrieve the data one more time, since there is no logged in user, it shouldn't retrieve any user level data Logout(); RefreshStore(); var resourcePoolFromDb = resourcePoolRepository .AllLiveIncluding(item => item.UserResourcePoolSet) .OrderByDescending(item => item.CreatedOn) .First(); Assert.IsTrue(resourcePoolFromDb.Id == resourcePool.Id); TestContext.WriteLine("resourcePoolFromDb.UserResourcePoolSet.Count: " + resourcePoolFromDb.UserResourcePoolSet.Count); Assert.IsTrue(resourcePoolFromDb.UserResourcePoolSet.Count == 1); Assert.IsTrue(resourcePoolFromDb.UserResourcePoolSet.Single().UserId == user2.Id); }