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 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); }
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 ResourcePool CreateDefaultResourcePool(User user, string resourcePoolName, bool useFixedResourcePoolRate, string mainElementName, bool addDirectIncomeField, bool addMultiplierField, bool addImportanceIndex, int numberOfItems) { // Resource pool, main element, fields var resourcePool = new ResourcePool(user, resourcePoolName); if (useFixedResourcePoolRate) { resourcePool.UseFixedResourcePoolRate = true; resourcePool.AddUserResourcePool(10); } // Main element var element = resourcePool.AddElement(mainElementName); element.IsMainElement = true; // Resource pool field if (addDirectIncomeField) element.AddField("Direct Income", ElementFieldDataType.DirectIncome, true); // Multiplier field if (addMultiplierField) element.AddField("Multiplier", ElementFieldDataType.Multiplier); // Importance field ElementField importanceField = null; if (addImportanceIndex) { importanceField = element.AddField("Importance Field", ElementFieldDataType.Decimal, false); importanceField.EnableIndex(); } // Items, cells, user cells for (var i = 1; i <= numberOfItems; i++) { var itemName = string.Format("Item {0}", i); var item = element.AddItem(itemName); if (addDirectIncomeField) item.AddCell(element.DirectIncomeField).SetValue(100M); // Default value if (addMultiplierField) item.AddCell(element.MultiplierField); if (addImportanceIndex) item.AddCell(importanceField); } // Return return resourcePool; }
static ResourcePool CreateDefaultResourcePool(User user, string resourcePoolName, bool useFixedResourcePoolRate, string mainElementName, bool addDirectIncomeField, bool addMultiplierField, bool addImportanceIndex, int numberOfItems) { // Resource pool, main element, fields var resourcePool = new ResourcePool(user, resourcePoolName); if (useFixedResourcePoolRate) { resourcePool.UseFixedResourcePoolRate = true; resourcePool.AddUserResourcePool(10); resourcePool.ResourcePoolRateTotal = 10; // Computed field resourcePool.ResourcePoolRateCount = 1; // Computed field } // Main element var element = resourcePool.AddElement(mainElementName); element.IsMainElement = true; // Resource pool field if (addDirectIncomeField) { element.AddField("Direct Income", ElementFieldDataType.DirectIncome, true); } // Multiplier field if (addMultiplierField) { element.AddField("Multiplier", ElementFieldDataType.Multiplier); } // Importance field ElementField importanceField = null; if (addImportanceIndex) { importanceField = element.AddField("Importance Field", ElementFieldDataType.Decimal, false); importanceField.EnableIndex(); } // Items, cells, user cells for (var i = 1; i <= numberOfItems; i++) { var itemName = string.Format("Item {0}", i); var item = element.AddItem(itemName); if (addDirectIncomeField) { item.AddCell(element.DirectIncomeField).SetValue(100M); // Default value } if (addMultiplierField) { item.AddCell(element.MultiplierField); } if (addImportanceIndex) { item.AddCell(importanceField); } } // Return return(resourcePool); }