public async Task GetSpecificResourceInGroupTest() { // Instantiate the tested calss TestContext.WriteLine($"Creating ResourcesRepository for {this.subscriptionId}..."); var factory = new Testee.RepositoryFactory(this.subscriptionId, this.resourceGroupName); var repoToTest = factory.CreateResourcesRepo(this.loggingBuilder); SetTesteeEnvironmentVariables(factory); // Get the resources in the resource group TestContext.WriteLine($"Trying to get {resourcesInGroup.Count} resources from {this.resourceGroupName}..."); foreach (var resourceExpected in this.resourcesInGroup) { TestContext.WriteLine($"- Getting resource {resourceExpected.Id}..."); // Execute the method to test var resourceAsIs = await repoToTest.GetByIdAsync(resourceExpected.Id); // The resource should have been found TestContext.WriteLine($"- Assertions for resource {resourceExpected.Id}..."); Assert.IsNotNull(resourceAsIs); Assert.AreEqual(resourceExpected.Id, resourceAsIs.Id, true); Assert.AreEqual(resourceExpected.Name, resourceAsIs.Name, true); Assert.AreEqual(resourceExpected.RegionName, resourceAsIs.Location, true); } TestContext.WriteLine("Succeeded!"); }
public async Task GetAllResourcesInGroupTest() { // Instantiate the tested calss TestContext.WriteLine($"Creating ResourcesRepository for {this.subscriptionId}..."); var factory = new Testee.RepositoryFactory(this.subscriptionId, this.resourceGroupName); var repoToTest = factory.CreateResourcesRepo(this.loggingBuilder); SetTesteeEnvironmentVariables(factory); // Get the resources in the resource group TestContext.WriteLine($"Getting resources from resource group {this.resourceGroupName}..."); var resourcesAsIs = await repoToTest.GetAllAsync(); // It should return not null all the time and the number of resources should be equal to what the test determined in its initialization. TestContext.WriteLine("Test assertions..."); Assert.IsNotNull(resourcesAsIs); Assert.AreEqual(resourcesInGroup.Count, resourcesAsIs.Count); // Compare the resources found ordered by ID resourcesAsIs.Sort(delegate(Testee.Entities.ResourceEntity a, Testee.Entities.ResourceEntity b) { return(string.Compare(a.Id, b.Id, StringComparison.InvariantCulture)); }); for (int i = 0; i < resourcesAsIs.Count; i++) { Assert.AreEqual(resourcesInGroup[i].Id, resourcesAsIs[i].Id, true); Assert.AreEqual(resourcesInGroup[i].Name, resourcesAsIs[i].Name, true); Assert.AreEqual(resourcesInGroup[i].RegionName, resourcesAsIs[i].Location, true); } TestContext.WriteLine("Succeeded!"); }