From 3194b483e2b20c9ba6847dde52d6dce4084c2103 Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Sun, 27 Oct 2024 10:25:56 +1100 Subject: [PATCH] Rename Pricing to Price in Coster --- README.md | 14 ++-- coster/.gitignore | 6 +- coster/src/AzureVmCoster/AzureVmCoster.csproj | 2 +- .../AzureVmCoster/Models/FileIdentifier.cs | 4 +- coster/src/AzureVmCoster/Models/PricedVm.cs | 34 +++++----- .../Models/{VmPricing.cs => VmPrice.cs} | 2 +- .../{Pricing => Prices}/.gitkeep | 0 coster/src/AzureVmCoster/Program.cs | 4 +- .../AzureVmCoster/Services/PriceService.cs | 8 +-- coster/src/AzureVmCoster/Services/Pricer.cs | 18 ++--- .../AzureVmCoster/Services/VmPriceParser.cs | 40 +++++++++++ .../AzureVmCoster/Services/VmPricingParser.cs | 41 ----------- .../Models/FileIdentifierTests.cs | 4 +- .../Services/InputFileValidatorTests.cs | 2 +- .../Services/PricedVmWriterTests.cs | 4 +- .../Services/PricerTests.cs | 68 +++++++++---------- ...ngParserTests.cs => VmPriceParserTests.cs} | 8 +-- ...-pricing_germany-west-central_windows.json | 0 ...-pricing_germany-west-central_windows.json | 0 .../TestInfrastructure/PricedVmBuilder.cs | 4 +- ...{VmPricingBuilder.cs => VmPriceBuilder.cs} | 26 +++---- 21 files changed, 144 insertions(+), 145 deletions(-) rename coster/src/AzureVmCoster/Models/{VmPricing.cs => VmPrice.cs} (97%) rename coster/src/AzureVmCoster/{Pricing => Prices}/.gitkeep (100%) create mode 100644 coster/src/AzureVmCoster/Services/VmPriceParser.cs delete mode 100644 coster/src/AzureVmCoster/Services/VmPricingParser.cs rename coster/tests/AzureVmCosterTests/Services/{VmPricingParserTests.cs => VmPriceParserTests.cs} (84%) rename coster/tests/AzureVmCosterTests/TestFiles/{EmptyPricing => EmptyPrice}/vm-pricing_germany-west-central_windows.json (100%) rename coster/tests/AzureVmCosterTests/TestFiles/{Pricing => Price}/vm-pricing_germany-west-central_windows.json (100%) rename coster/tests/AzureVmCosterTests/TestInfrastructure/{VmPricingBuilder.cs => VmPriceBuilder.cs} (89%) diff --git a/README.md b/README.md index 7bed938..e0a1e20 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ Mass-pricing of VMs on Azure based on CPU cores count and memory. This is useful This tool is composed of two components: -1. A [Parser](#parser) retrieving the pricing from [Virtual Machines Pricing][virtual-machines-pricing] +1. A [Parser](#parser) retrieving the prices from [Virtual Machines Pricing][virtual-machines-pricing] 2. A [Coster](#coster) using the output from the `Parser` and a list of VM specifications to determine their price -This approach allows to decouple pricing acquisition from its usage and open the door to automation. The `Parser` can be scheduled to retrieve the pricing at regular interval and the `Coster` can then use an always up-to-date pricing. +This approach allows to decouple price acquisition from its usage and open the door to automation. The `Parser` can be scheduled to retrieve the prices at regular interval and the `Coster` can then use always up-to-date prices. [![Build Status][github-actions-parser-shield]][github-actions-parser] ([tests documentation](./docs/parser-tests.md)) @@ -17,11 +17,11 @@ This approach allows to decouple pricing acquisition from its usage and open the ## Parser -Retrieve VMs **hourly pricing** for a specific combination of **culture**, **currency**, **operating system** and **region**. +Retrieve VMs **hourly prices** for a specific combination of **culture**, **currency**, **operating system** and **region**. -:rotating_light: the parser is not - yet - able to retrieve pricing for the regions `east-china2`, `north-china2`, `east-china` and `north-china` as it is available on a [different website][azure-china]. +:rotating_light: the parser is not - yet - able to retrieve prices for the regions `east-china2`, `north-china2`, `east-china` and `north-china` as it is available on a [different website][azure-china]. -:rotating_light: the parser is not able to retrieve pricing for the regions `us-dod-central` and `us-dod-east` as no virtual machines are listed as publicly available. +:rotating_light: the parser is not able to retrieve prices for the regions `us-dod-central` and `us-dod-east` as no virtual machines are listed as publicly available. ### Parser pre-requisites @@ -106,7 +106,7 @@ docker run --rm -it -v ./data:/data/ azure-vm-pricing:latest bash -c "yarn crawl ## Coster -Price VMs using the `JSON` pricing files generated by the `Parser`. The `Coster` will select the cheapest VM that has enough CPU cores and RAM. +Price VMs using the `JSON` prices files generated by the `Parser`. The `Coster` will select the cheapest VM that has enough CPU cores and RAM. ### Coster pre-requisites @@ -114,7 +114,7 @@ Price VMs using the `JSON` pricing files generated by the `Parser`. The `Coster` ### Coster usage -You should paste the `JSON` pricing files generated by the `Parser` in the `coster\src\AzureVmCoster\Pricing\` folder. Setting the `culture` is only relevant when dealing with pricing and input files that were written using another culture with a different decimal point (e.g. comma vs period). +You should paste the `JSON` prices files generated by the `Parser` in the `coster\src\AzureVmCoster\Prices\` folder. Setting the `culture` is only relevant when dealing with prices and input files that were written using another culture with a different decimal point (e.g. comma vs period). In `Release` mode: diff --git a/coster/.gitignore b/coster/.gitignore index d7de614..5f37771 100644 --- a/coster/.gitignore +++ b/coster/.gitignore @@ -6,9 +6,9 @@ bin/ obj/ -# Pricing -src/AzureVmCoster/Pricing/*.json -src/AzureVmCoster/Pricing/*.csv +# Prices +src/AzureVmCoster/Prices/*.json +src/AzureVmCoster/Prices/*.csv # Build artifacts/ diff --git a/coster/src/AzureVmCoster/AzureVmCoster.csproj b/coster/src/AzureVmCoster/AzureVmCoster.csproj index f8bdca0..7af8723 100644 --- a/coster/src/AzureVmCoster/AzureVmCoster.csproj +++ b/coster/src/AzureVmCoster/AzureVmCoster.csproj @@ -25,7 +25,7 @@ - + Always diff --git a/coster/src/AzureVmCoster/Models/FileIdentifier.cs b/coster/src/AzureVmCoster/Models/FileIdentifier.cs index 8a542af..018da9d 100644 --- a/coster/src/AzureVmCoster/Models/FileIdentifier.cs +++ b/coster/src/AzureVmCoster/Models/FileIdentifier.cs @@ -4,7 +4,7 @@ internal class FileIdentifier { public string Region { get; } public string OperatingSystem { get; } - public string PricingFilename => $"vm-pricing_{Region}_{OperatingSystem}.json"; + public string PriceFilename => $"vm-pricing_{Region}_{OperatingSystem}.json"; public FileIdentifier(string region, string operatingSystem) { @@ -23,7 +23,7 @@ public static FileIdentifier From(FileInfo fileInfo) extensionIndex < underscoreLastIndex) { throw new ArgumentOutOfRangeException(nameof(fileInfo), fileInfo.Name, - "The pricing filename does not follow the pattern 'vm-pricing__.json'"); + "The price filename does not follow the pattern 'vm-pricing__.json'"); } var region = fileInfo.Name.Substring(underscoreFirstIndex + 1, underscoreLastIndex - underscoreFirstIndex - 1); diff --git a/coster/src/AzureVmCoster/Models/PricedVm.cs b/coster/src/AzureVmCoster/Models/PricedVm.cs index a11a0d1..17074e2 100644 --- a/coster/src/AzureVmCoster/Models/PricedVm.cs +++ b/coster/src/AzureVmCoster/Models/PricedVm.cs @@ -2,29 +2,29 @@ namespace AzureVmCoster.Models; internal class PricedVm { - public PricedVm(InputVm inputVm, VmPricing? vmPricing) + public PricedVm(InputVm inputVm, VmPrice? vmPrice) { Name = inputVm.Name; Region = inputVm.Region; OperatingSystem = inputVm.OperatingSystem; - if (vmPricing != null) + if (vmPrice != null) { - Instance = vmPricing.Instance; - VCpu = vmPricing.VCpu; - Ram = vmPricing.Ram; - PayAsYouGo = vmPricing.PayAsYouGo; - PayAsYouGoWithAzureHybridBenefit = vmPricing.PayAsYouGoWithAzureHybridBenefit; - OneYearReserved = vmPricing.OneYearReserved; - OneYearReservedWithAzureHybridBenefit = vmPricing.OneYearReservedWithAzureHybridBenefit; - ThreeYearReserved = vmPricing.ThreeYearReserved; - ThreeYearReservedWithAzureHybridBenefit = vmPricing.ThreeYearReservedWithAzureHybridBenefit; - Spot = vmPricing.Spot; - SpotWithAzureHybridBenefit = vmPricing.SpotWithAzureHybridBenefit; - OneYearSavingsPlan = vmPricing.OneYearSavingsPlan; - OneYearSavingsPlanWithAzureHybridBenefit = vmPricing.OneYearSavingsPlanWithAzureHybridBenefit; - ThreeYearSavingsPlan = vmPricing.ThreeYearSavingsPlan; - ThreeYearSavingsPlanWithAzureHybridBenefit = vmPricing.ThreeYearSavingsPlanWithAzureHybridBenefit; + Instance = vmPrice.Instance; + VCpu = vmPrice.VCpu; + Ram = vmPrice.Ram; + PayAsYouGo = vmPrice.PayAsYouGo; + PayAsYouGoWithAzureHybridBenefit = vmPrice.PayAsYouGoWithAzureHybridBenefit; + OneYearReserved = vmPrice.OneYearReserved; + OneYearReservedWithAzureHybridBenefit = vmPrice.OneYearReservedWithAzureHybridBenefit; + ThreeYearReserved = vmPrice.ThreeYearReserved; + ThreeYearReservedWithAzureHybridBenefit = vmPrice.ThreeYearReservedWithAzureHybridBenefit; + Spot = vmPrice.Spot; + SpotWithAzureHybridBenefit = vmPrice.SpotWithAzureHybridBenefit; + OneYearSavingsPlan = vmPrice.OneYearSavingsPlan; + OneYearSavingsPlanWithAzureHybridBenefit = vmPrice.OneYearSavingsPlanWithAzureHybridBenefit; + ThreeYearSavingsPlan = vmPrice.ThreeYearSavingsPlan; + ThreeYearSavingsPlanWithAzureHybridBenefit = vmPrice.ThreeYearSavingsPlanWithAzureHybridBenefit; } else { diff --git a/coster/src/AzureVmCoster/Models/VmPricing.cs b/coster/src/AzureVmCoster/Models/VmPrice.cs similarity index 97% rename from coster/src/AzureVmCoster/Models/VmPricing.cs rename to coster/src/AzureVmCoster/Models/VmPrice.cs index 770b267..07d0bb4 100644 --- a/coster/src/AzureVmCoster/Models/VmPricing.cs +++ b/coster/src/AzureVmCoster/Models/VmPrice.cs @@ -1,6 +1,6 @@ namespace AzureVmCoster.Models; -public class VmPricing +public class VmPrice { public string Region { get; set; } = default!; public string OperatingSystem { get; set; } = default!; diff --git a/coster/src/AzureVmCoster/Pricing/.gitkeep b/coster/src/AzureVmCoster/Prices/.gitkeep similarity index 100% rename from coster/src/AzureVmCoster/Pricing/.gitkeep rename to coster/src/AzureVmCoster/Prices/.gitkeep diff --git a/coster/src/AzureVmCoster/Program.cs b/coster/src/AzureVmCoster/Program.cs index 9c45cb3..9c3657e 100644 --- a/coster/src/AzureVmCoster/Program.cs +++ b/coster/src/AzureVmCoster/Program.cs @@ -13,10 +13,10 @@ public static async Task Main(string[] args) { var builder = Host.CreateDefaultBuilder(args); builder.ConfigureServices(s => s - .AddSingleton(new PriceDirectory(@"Pricing\")) + .AddSingleton(new PriceDirectory(@"Prices\")) .AddSingleton() .AddSingleton() - .AddSingleton() + .AddSingleton() .AddSingleton() .AddSingleton()); var host = builder.Build(); diff --git a/coster/src/AzureVmCoster/Services/PriceService.cs b/coster/src/AzureVmCoster/Services/PriceService.cs index 3a7a79f..31ba79e 100644 --- a/coster/src/AzureVmCoster/Services/PriceService.cs +++ b/coster/src/AzureVmCoster/Services/PriceService.cs @@ -3,13 +3,13 @@ namespace AzureVmCoster.Services; internal class PriceService { private readonly Pricer _pricer; - private readonly VmPricingParser _vmPricingParser; + private readonly VmPriceParser _vmPriceParser; private readonly PricedVmWriter _pricedVmWriter; - public PriceService(Pricer pricer, VmPricingParser vmPricingParser, PricedVmWriter pricedVmWriter) + public PriceService(Pricer pricer, VmPriceParser vmPriceParser, PricedVmWriter pricedVmWriter) { _pricer = pricer; - _vmPricingParser = vmPricingParser; + _vmPriceParser = vmPriceParser; _pricedVmWriter = pricedVmWriter; } @@ -18,7 +18,7 @@ public async Task PriceAsync(string? inputFilePath, string? configurationFilePat var inputFile = InputFileValidator.Validate(inputFilePath); var inputVms = InputVmParser.Parse(inputFile, culture); - var vmPrices = await _vmPricingParser.ParseAsync(); + var vmPrices = await _vmPriceParser.ParseAsync(); var configuration = await CosterConfiguration.FromPathAsync(configurationFilePath); diff --git a/coster/src/AzureVmCoster/Services/Pricer.cs b/coster/src/AzureVmCoster/Services/Pricer.cs index b0519b4..6179d74 100644 --- a/coster/src/AzureVmCoster/Services/Pricer.cs +++ b/coster/src/AzureVmCoster/Services/Pricer.cs @@ -12,9 +12,9 @@ public Pricer(ILogger logger) _logger = logger; } - public List Price(IList inputVms, IList vmPrices, CosterConfiguration configuration) + public List Price(IList inputVms, IList vmPrices, CosterConfiguration configuration) { - EnsurePricingExists(inputVms, vmPrices); + EnsurePriceExists(inputVms, vmPrices); var filteredVmPrices = FilterPrices(vmPrices, configuration.ExcludedVms); @@ -30,24 +30,24 @@ public List Price(IList inputVms, IList vmPrices, var minCpu = vm.Cpu > 0 ? vm.Cpu : medianCpu; var minRam = vm.Ram > 0 ? vm.Ram : medianRam; - var pricing = orderedVmPrices.FirstOrDefault(p => + var price = orderedVmPrices.FirstOrDefault(p => p.Region.Equals(vm.Region, StringComparison.Ordinal) && p.OperatingSystem.Equals(vm.OperatingSystem, StringComparison.Ordinal) && p.Ram >= minRam && p.VCpu >= minCpu); - if (pricing == null) + if (price == null) { - _logger.LogWarning("Could not find a matching pricing for VM '{VmName}' ({VmCpu} CPU cores and {VmRam} GB of RAM)", vm.Name, vm.Cpu, vm.Ram); + _logger.LogWarning("Could not find a matching price for VM '{VmName}' ({VmCpu} CPU cores and {VmRam} GB of RAM)", vm.Name, vm.Cpu, vm.Ram); } - pricedVms.Add(new PricedVm(vm, pricing)); + pricedVms.Add(new PricedVm(vm, price)); } return pricedVms; } - private static void EnsurePricingExists(IList vms, IList vmPrices) + private static void EnsurePriceExists(IList vms, IList vmPrices) { var missingFiles = vms .Select(vm => new FileIdentifier(vm.Region, vm.OperatingSystem)) @@ -59,7 +59,7 @@ private static void EnsurePricingExists(IList vms, IList vmP if (missingFiles.Count > 0) { - throw new InvalidOperationException($"Pricing files are missing for {JsonSerializer.Serialize(missingFiles)}"); + throw new InvalidOperationException($"Price files are missing for {JsonSerializer.Serialize(missingFiles)}"); } } @@ -71,7 +71,7 @@ private static void EnsurePricingExists(IList vms, IList vmP /// The list of prices to filter /// The list of instances to remove /// The filtered prices - private static List FilterPrices(IList vmPrices, IList excludedVms) + private static List FilterPrices(IList vmPrices, IList excludedVms) { return vmPrices.Where(p => !excludedVms.Contains(p.Instance, StringComparer.OrdinalIgnoreCase)).ToList(); } diff --git a/coster/src/AzureVmCoster/Services/VmPriceParser.cs b/coster/src/AzureVmCoster/Services/VmPriceParser.cs new file mode 100644 index 0000000..7496750 --- /dev/null +++ b/coster/src/AzureVmCoster/Services/VmPriceParser.cs @@ -0,0 +1,40 @@ +namespace AzureVmCoster.Services; + +internal class VmPriceParser +{ + private readonly string _priceDirectory; + + public VmPriceParser(PriceDirectory priceDirectory) + { + _priceDirectory = priceDirectory.Directory; + } + + public async Task> ParseAsync() + { + var priceFiles = Directory.GetFiles(_priceDirectory, "*.json"); + + var allVmPrices = new List(); + + foreach (var priceFile in priceFiles) + { + var fileIdentifier = FileIdentifier.From(new FileInfo(priceFile)); + + var fileVmPrices = await JsonReader.DeserializeAsync>(priceFile); + + if (fileVmPrices == null || fileVmPrices.Count == 0) + { + continue; + } + + fileVmPrices.ForEach(price => + { + price.Region = fileIdentifier.Region; + price.OperatingSystem = fileIdentifier.OperatingSystem; + }); + + allVmPrices.AddRange(fileVmPrices); + } + + return allVmPrices; + } +} diff --git a/coster/src/AzureVmCoster/Services/VmPricingParser.cs b/coster/src/AzureVmCoster/Services/VmPricingParser.cs deleted file mode 100644 index 52342f8..0000000 --- a/coster/src/AzureVmCoster/Services/VmPricingParser.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace AzureVmCoster.Services; - -internal class VmPricingParser -{ - private readonly string _pricingDirectory; - - public VmPricingParser(PriceDirectory pricingDirectory) - { - _pricingDirectory = pricingDirectory.Directory; - } - - public async Task> ParseAsync() - { - var pricingFiles = Directory.GetFiles(_pricingDirectory, "*.json"); - - var allVmPricing = new List(); - - foreach (var pricingFile in pricingFiles) - { - var fileInfo = new FileInfo(pricingFile); - var fileIdentifier = FileIdentifier.From(fileInfo); - - var fileVmPricing = await JsonReader.DeserializeAsync>(pricingFile); - - if (fileVmPricing == null || fileVmPricing.Count == 0) - { - continue; - } - - fileVmPricing.ForEach(pricing => - { - pricing.Region = fileIdentifier.Region; - pricing.OperatingSystem = fileIdentifier.OperatingSystem; - }); - - allVmPricing.AddRange(fileVmPricing); - } - - return allVmPricing; - } -} diff --git a/coster/tests/AzureVmCosterTests/Models/FileIdentifierTests.cs b/coster/tests/AzureVmCosterTests/Models/FileIdentifierTests.cs index 1e17bcd..734dbf2 100644 --- a/coster/tests/AzureVmCosterTests/Models/FileIdentifierTests.cs +++ b/coster/tests/AzureVmCosterTests/Models/FileIdentifierTests.cs @@ -3,13 +3,13 @@ namespace AzureVmCosterTests.Models; public static class FileIdentifierTests { [Fact] - public static void GivenInitialisedIdentifier_WhenGetPricingFilename_ThenExpected() + public static void GivenInitialisedIdentifier_WhenGetPriceFilename_ThenExpected() { // Arrange var identifier = new FileIdentifier("some-region", "some-operating-system"); // Actual - var actual = identifier.PricingFilename; + var actual = identifier.PriceFilename; // Assert actual.Should().Be("vm-pricing_some-region_some-operating-system.json"); diff --git a/coster/tests/AzureVmCosterTests/Services/InputFileValidatorTests.cs b/coster/tests/AzureVmCosterTests/Services/InputFileValidatorTests.cs index 34496c1..758cd1b 100644 --- a/coster/tests/AzureVmCosterTests/Services/InputFileValidatorTests.cs +++ b/coster/tests/AzureVmCosterTests/Services/InputFileValidatorTests.cs @@ -30,7 +30,7 @@ public void GivenEmptyOrNullFilePath_ThenThrow(string? filePath) public void GivenNonCsvExtension_ThenThrow() { // Arrange - const string filePath = "TestFiles/Pricing/vm-pricing_germany-west-central_windows.json"; + const string filePath = "TestFiles/Price/vm-pricing_germany-west-central_windows.json"; // Act Assert.Throws(() => InputFileValidator.Validate(filePath)); diff --git a/coster/tests/AzureVmCosterTests/Services/PricedVmWriterTests.cs b/coster/tests/AzureVmCosterTests/Services/PricedVmWriterTests.cs index 0317103..5350933 100644 --- a/coster/tests/AzureVmCosterTests/Services/PricedVmWriterTests.cs +++ b/coster/tests/AzureVmCosterTests/Services/PricedVmWriterTests.cs @@ -16,8 +16,8 @@ public void GivenPricedVm_WhenWrite_ThenPopulateAllColumns() { // Arrange var inputVm = InputVmBuilder.AsUsWestWindowsD2V3Equivalent(); - var vmPricing = VmPricingBuilder.AsUsWestWindowsD2V3(); - var vm = PricedVmBuilder.From(inputVm, vmPricing); + var vmPrice = VmPriceBuilder.AsUsWestWindowsD2V3(); + var vm = PricedVmBuilder.From(inputVm, vmPrice); var fileName = $"{Guid.NewGuid():D}.csv"; // Act diff --git a/coster/tests/AzureVmCosterTests/Services/PricerTests.cs b/coster/tests/AzureVmCosterTests/Services/PricerTests.cs index faa871c..1386279 100644 --- a/coster/tests/AzureVmCosterTests/Services/PricerTests.cs +++ b/coster/tests/AzureVmCosterTests/Services/PricerTests.cs @@ -10,16 +10,16 @@ public class PricerTests private readonly CosterConfiguration _defaultConfiguration = new(); [Fact] - public void GivenMissingRegionAndMissingOperatingSystem_WhenEnsurePricingExists_ThenThrow() + public void GivenMissingRegionAndMissingOperatingSystem_WhenEnsurePriceExists_ThenThrow() { // Arrange var vms = new List { InputVmBuilder.AsUsEastLinuxD2V3Equivalent() }; - var prices = new List + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3() + VmPriceBuilder.AsUsWestWindowsD2V3() }; // Act & Assert @@ -27,16 +27,16 @@ public void GivenMissingRegionAndMissingOperatingSystem_WhenEnsurePricingExists_ } [Fact] - public void GivenExistingRegionAndExistingOperatingSystem_WhenEnsurePricingExists_ThenDoNotThrow() + public void GivenExistingRegionAndExistingOperatingSystem_WhenEnsurePriceExists_ThenDoNotThrow() { // Arrange var vms = new List { InputVmBuilder.AsUsWestWindowsD2V3Equivalent() }; - var prices = new List + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3() + VmPriceBuilder.AsUsWestWindowsD2V3() }; // Act @@ -47,16 +47,16 @@ public void GivenExistingRegionAndExistingOperatingSystem_WhenEnsurePricingExist } [Fact] - public void GivenExistingRegionAndMissingOperatingSystem_WhenEnsurePricingExists_ThenThrow() + public void GivenExistingRegionAndMissingOperatingSystem_WhenEnsurePriceExists_ThenThrow() { // Arrange var vms = new List { InputVmBuilder.AsUsWestLinuxD2V3Equivalent() }; - var prices = new List + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3() + VmPriceBuilder.AsUsWestWindowsD2V3() }; // Act & Assert @@ -64,16 +64,16 @@ public void GivenExistingRegionAndMissingOperatingSystem_WhenEnsurePricingExists } [Fact] - public void GivenMissingRegionAndExistingOperatingSystem_WhenEnsurePricingExists_ThenThrow() + public void GivenMissingRegionAndExistingOperatingSystem_WhenEnsurePriceExists_ThenThrow() { // Arrange var vms = new List { InputVmBuilder.AsUsEastWindowsD2V3Equivalent() }; - var prices = new List + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3() + VmPriceBuilder.AsUsWestWindowsD2V3() }; // Act & Assert @@ -81,16 +81,16 @@ public void GivenMissingRegionAndExistingOperatingSystem_WhenEnsurePricingExists } [Fact] - public void GivenEmptyExcludeList_WhenFilterPricing_ThenNoPriceRemoved() + public void GivenEmptyExcludeList_WhenFilterPrices_ThenNoPriceRemoved() { // Arrange var vms = new List { InputVmBuilder.AsUsWestWindowsD2V3Equivalent() }; - var prices = new List + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3() + VmPriceBuilder.AsUsWestWindowsD2V3() }; var configuration = new CosterConfiguration { ExcludedVms = new List() }; @@ -103,19 +103,19 @@ public void GivenEmptyExcludeList_WhenFilterPricing_ThenNoPriceRemoved() } [Fact] - public void GivenExcludeList_WhenFilterPricing_ThenRemoveInstanceWithSameName() + public void GivenExcludeList_WhenFilterPrices_ThenRemoveInstanceWithSameName() { // Arrange var vms = new List { InputVmBuilder.AsUsWestWindowsD2V3Equivalent() }; - var d4V3 = VmPricingBuilder.AsUsWestWindowsD4V3(); - var d2V3Linux = VmPricingBuilder.AsUsWestLinuxD2V3(); - var d2V3UsEast = VmPricingBuilder.AsUsEastWindowsD2V3(); - var prices = new List + var d4V3 = VmPriceBuilder.AsUsWestWindowsD4V3(); + var d2V3Linux = VmPriceBuilder.AsUsWestLinuxD2V3(); + var d2V3UsEast = VmPriceBuilder.AsUsEastWindowsD2V3(); + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3(), + VmPriceBuilder.AsUsWestWindowsD2V3(), d4V3, d2V3Linux, d2V3UsEast @@ -131,17 +131,17 @@ public void GivenExcludeList_WhenFilterPricing_ThenRemoveInstanceWithSameName() } [Fact] - public void GivenExcludeList_WhenFilterPricing_ThenRemoveInstanceWithSameNameCaseInsensitive() + public void GivenExcludeList_WhenFilterPrices_ThenRemoveInstanceWithSameNameCaseInsensitive() { // Arrange var vms = new List { InputVmBuilder.AsUsWestWindowsD2V3Equivalent() }; - var d4V3 = VmPricingBuilder.AsUsWestWindowsD4V3(); - var prices = new List + var d4V3 = VmPriceBuilder.AsUsWestWindowsD4V3(); + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3(), + VmPriceBuilder.AsUsWestWindowsD2V3(), d4V3 }; var configuration = new CosterConfiguration { ExcludedVms = new List { "d2 V3" } }; @@ -162,9 +162,9 @@ public void GivenMatchingPrice_WhenPrice_ThenPriceVm() { InputVmBuilder.AsUsWestWindowsD2V3Equivalent() }; - var prices = new List + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3() + VmPriceBuilder.AsUsWestWindowsD2V3() }; // Act @@ -183,9 +183,9 @@ public void GivenNoMatchingPrice_WhenPrice_ThenHandleVmAsNoPrice() { InputVmBuilder.AsUsWestWindowsD4V3Equivalent() }; - var prices = new List + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3() + VmPriceBuilder.AsUsWestWindowsD2V3() }; // Act @@ -214,13 +214,13 @@ public void GivenVmWithoutCpuAndWithoutRam_WhenPrice_ThenUseMedianCpuAndRam() InputVmBuilder.AsUsWestWindowsD16V3Equivalent(), vmWithoutCpuWithoutRam }; - var medianPrice = VmPricingBuilder.AsUsWestWindowsD8V3(); - var prices = new List + var medianPrice = VmPriceBuilder.AsUsWestWindowsD8V3(); + var prices = new List { - VmPricingBuilder.AsUsWestWindowsD2V3(), - VmPricingBuilder.AsUsWestWindowsD4V3(), + VmPriceBuilder.AsUsWestWindowsD2V3(), + VmPriceBuilder.AsUsWestWindowsD4V3(), medianPrice, - VmPricingBuilder.AsUsWestWindowsD16V3() + VmPriceBuilder.AsUsWestWindowsD16V3() }; // Act diff --git a/coster/tests/AzureVmCosterTests/Services/VmPricingParserTests.cs b/coster/tests/AzureVmCosterTests/Services/VmPriceParserTests.cs similarity index 84% rename from coster/tests/AzureVmCosterTests/Services/VmPricingParserTests.cs rename to coster/tests/AzureVmCosterTests/Services/VmPriceParserTests.cs index d998fab..d57d083 100644 --- a/coster/tests/AzureVmCosterTests/Services/VmPricingParserTests.cs +++ b/coster/tests/AzureVmCosterTests/Services/VmPriceParserTests.cs @@ -2,19 +2,19 @@ namespace AzureVmCosterTests.Services; -public class VmPricingParserTests +public class VmPriceParserTests { [Fact] public async Task GivenValidPrice_ThenParseVm() { // Arrange - var parser = new VmPricingParser(new PriceDirectory("TestFiles/Pricing/")); + var parser = new VmPriceParser(new PriceDirectory("TestFiles/Price/")); // Act var actualPrices = await parser.ParseAsync(); // Assert - var expectedPrices = new List + var expectedPrices = new List { new() { @@ -44,7 +44,7 @@ public async Task GivenValidPrice_ThenParseVm() public async Task GivenEmptyPriceFile_ThenHandleGracefully() { // Arrange - var parser = new VmPricingParser(new PriceDirectory("TestFiles/EmptyPricing/")); + var parser = new VmPriceParser(new PriceDirectory("TestFiles/EmptyPrice/")); // Act var prices = await parser.ParseAsync(); diff --git a/coster/tests/AzureVmCosterTests/TestFiles/EmptyPricing/vm-pricing_germany-west-central_windows.json b/coster/tests/AzureVmCosterTests/TestFiles/EmptyPrice/vm-pricing_germany-west-central_windows.json similarity index 100% rename from coster/tests/AzureVmCosterTests/TestFiles/EmptyPricing/vm-pricing_germany-west-central_windows.json rename to coster/tests/AzureVmCosterTests/TestFiles/EmptyPrice/vm-pricing_germany-west-central_windows.json diff --git a/coster/tests/AzureVmCosterTests/TestFiles/Pricing/vm-pricing_germany-west-central_windows.json b/coster/tests/AzureVmCosterTests/TestFiles/Price/vm-pricing_germany-west-central_windows.json similarity index 100% rename from coster/tests/AzureVmCosterTests/TestFiles/Pricing/vm-pricing_germany-west-central_windows.json rename to coster/tests/AzureVmCosterTests/TestFiles/Price/vm-pricing_germany-west-central_windows.json diff --git a/coster/tests/AzureVmCosterTests/TestInfrastructure/PricedVmBuilder.cs b/coster/tests/AzureVmCosterTests/TestInfrastructure/PricedVmBuilder.cs index b0d0fb9..9345546 100644 --- a/coster/tests/AzureVmCosterTests/TestInfrastructure/PricedVmBuilder.cs +++ b/coster/tests/AzureVmCosterTests/TestInfrastructure/PricedVmBuilder.cs @@ -2,13 +2,13 @@ namespace AzureVmCosterTests.TestInfrastructure; internal static class PricedVmBuilder { - public static PricedVm From(InputVm vm, VmPricing price) + public static PricedVm From(InputVm vm, VmPrice price) { return new PricedVm(vm, price); } public static PricedVm WithoutPrice(InputVm vm) { - return new PricedVm(vm, vmPricing: null); + return new PricedVm(vm, vmPrice: null); } } diff --git a/coster/tests/AzureVmCosterTests/TestInfrastructure/VmPricingBuilder.cs b/coster/tests/AzureVmCosterTests/TestInfrastructure/VmPriceBuilder.cs similarity index 89% rename from coster/tests/AzureVmCosterTests/TestInfrastructure/VmPricingBuilder.cs rename to coster/tests/AzureVmCosterTests/TestInfrastructure/VmPriceBuilder.cs index 51096c0..24cdfeb 100644 --- a/coster/tests/AzureVmCosterTests/TestInfrastructure/VmPricingBuilder.cs +++ b/coster/tests/AzureVmCosterTests/TestInfrastructure/VmPriceBuilder.cs @@ -1,10 +1,10 @@ namespace AzureVmCosterTests.TestInfrastructure; -internal static class VmPricingBuilder +internal static class VmPriceBuilder { - public static VmPricing AsUsWestWindowsD2V3() + public static VmPrice AsUsWestWindowsD2V3() { - return new VmPricing + return new VmPrice { Instance = "D2 v3", OperatingSystem = "windows", @@ -26,9 +26,9 @@ public static VmPricing AsUsWestWindowsD2V3() }; } - public static VmPricing AsUsEastWindowsD2V3() + public static VmPrice AsUsEastWindowsD2V3() { - return new VmPricing + return new VmPrice { Instance = "D2 v3", OperatingSystem = "windows", @@ -50,9 +50,9 @@ public static VmPricing AsUsEastWindowsD2V3() }; } - public static VmPricing AsUsWestLinuxD2V3() + public static VmPrice AsUsWestLinuxD2V3() { - return new VmPricing + return new VmPrice { Instance = "D2 v3", OperatingSystem = "linux", @@ -68,9 +68,9 @@ public static VmPricing AsUsWestLinuxD2V3() }; } - public static VmPricing AsUsWestWindowsD4V3() + public static VmPrice AsUsWestWindowsD4V3() { - return new VmPricing + return new VmPrice { Instance = "D4 v3", OperatingSystem = "windows", @@ -92,9 +92,9 @@ public static VmPricing AsUsWestWindowsD4V3() }; } - public static VmPricing AsUsWestWindowsD8V3() + public static VmPrice AsUsWestWindowsD8V3() { - return new VmPricing + return new VmPrice { Instance = "D8 v3", OperatingSystem = "windows", @@ -116,9 +116,9 @@ public static VmPricing AsUsWestWindowsD8V3() }; } - public static VmPricing AsUsWestWindowsD16V3() + public static VmPrice AsUsWestWindowsD16V3() { - return new VmPricing + return new VmPrice { Instance = "D16 v3", OperatingSystem = "windows",