public async Task TestCascadedOwnership_BlankObjectAndGroupOwnerShouldReturnRootLevel() { await using var context = JosekiTestsDb.CreateUniqueContext(); const string rootLevelId = "/subscriptions/0000-000-000-0000"; const string groupLevelId = "/subscriptions/0000-000-000-0000/resource_group/das-rg"; const string objectLevelId = "/subscriptions/0000-000-000-0000/resource_group/das-rg/VirtualNetwork/das-vn"; context.Ownership.AddRange(new OwnershipEntity[] { new OwnershipEntity { ComponentId = rootLevelId, Owner = "*****@*****.**", }, new OwnershipEntity { ComponentId = groupLevelId, Owner = string.Empty, }, new OwnershipEntity { ComponentId = objectLevelId, Owner = string.Empty, }, }); await context.SaveChangesAsync(); var ownershipCache = new OwnershipCache(context, new MemoryCache(new MemoryCacheOptions())); var owner = await ownershipCache.GetOwner(objectLevelId); owner.Should().Be("*****@*****.**"); }
public async Task InvalidComponentId_ShouldThrowException() { await using var context = JosekiTestsDb.CreateUniqueContext(); var ownershipCache = new OwnershipCache(context, new MemoryCache(new MemoryCacheOptions())); const string invalidId_missingSlashPrefix = "subscription/0000-000-000-0000/"; var owner1 = await ownershipCache.GetOwner(invalidId_missingSlashPrefix); owner1.Should().Be(string.Empty); }
public async Task EmptyComponentId_ShouldThrowException() { await using var context = JosekiTestsDb.CreateUniqueContext(); var ownershipCache = new OwnershipCache(context, new MemoryCache(new MemoryCacheOptions())); string emptyComponentId = string.Empty; var owner1 = await ownershipCache.GetOwner(emptyComponentId); owner1.Should().Be(string.Empty); }
public async Task OwnershipCache_ShouldInvalidateOnCall() { await using var context = JosekiTestsDb.CreateUniqueContext(); const string rootLevelId = "/subscriptions/0000-000-000-0000"; var ownerEntry = new OwnershipEntity { ComponentId = rootLevelId, Owner = "*****@*****.**", }; context.Ownership.Add(ownerEntry); await context.SaveChangesAsync(); var ownershipCache = new OwnershipCache(context, new MemoryCache(new MemoryCacheOptions())); var owner1 = await ownershipCache.GetOwner(rootLevelId); owner1.Should().Be("*****@*****.**"); // remove entry from db context.Ownership.Remove(ownerEntry); await context.SaveChangesAsync(); // see that cache is in progress. var ownerAgain = await ownershipCache.GetOwner(rootLevelId); ownerAgain.Should().Be("*****@*****.**"); // invalidate cache ownershipCache.Invalidate(); var ownerNull = await ownershipCache.GetOwner(rootLevelId); ownerNull.Should().Be(string.Empty); }