diff --git a/Cisco.Api.Test/EoxTests.cs b/Cisco.Api.Test/EoxTests.cs index ea21a87..fb8eb0d 100644 --- a/Cisco.Api.Test/EoxTests.cs +++ b/Cisco.Api.Test/EoxTests.cs @@ -1,8 +1,9 @@ -using Cisco.Api.Data.Eox; -using FluentAssertions; using System; using System.Globalization; using System.Linq; +using System.Threading.Tasks; +using Cisco.Api.Data.Eox; +using FluentAssertions; using Xunit; using Xunit.Abstractions; @@ -15,7 +16,7 @@ public EoxTests(ITestOutputHelper iTestOutputHelper) : base(iTestOutputHelper) } [Fact] - public async void GetByDatesAsync_Succeeds() + public async Task GetByDatesAsync_Succeeds() { var eoxInfoPage = await CiscoClient .Eox @@ -27,7 +28,7 @@ public async void GetByDatesAsync_Succeeds() } [Fact] - public async void GetByProductIdAsync_Succeeds() + public async Task GetByProductIdAsync_Succeeds() { var eoxInfoPage = await CiscoClient .Eox @@ -37,7 +38,7 @@ public async void GetByProductIdAsync_Succeeds() } [Fact] - public async void GetBySerialNumberAsync_Succeeds() + public async Task GetBySerialNumberAsync_Succeeds() { var eoxInfoPage = await CiscoClient .Eox @@ -47,7 +48,7 @@ public async void GetBySerialNumberAsync_Succeeds() } [Fact] - public async void GetBySoftwareReleaseStringAsync_Succeeds() + public async Task GetBySoftwareReleaseStringAsync_Succeeds() { var eoxInfoPage = await CiscoClient .Eox diff --git a/Cisco.Api.Test/FieldNoticesTests.cs b/Cisco.Api.Test/FieldNoticesTests.cs index 5c9cf98..bf3252c 100644 --- a/Cisco.Api.Test/FieldNoticesTests.cs +++ b/Cisco.Api.Test/FieldNoticesTests.cs @@ -1,5 +1,6 @@ -using Cisco.Api.Data.Pss; -using System.Threading; +using System.Threading; +using System.Threading.Tasks; +using Cisco.Api.Data.Pss; using Xunit; using Xunit.Abstractions; @@ -12,9 +13,9 @@ public FieldNoticesTests(ITestOutputHelper iTestOutputHelper) : base(iTestOutput } [Fact] - public async void Get_Succeeds() + public async Task Get_Succeeds() { - var _ = + _ = await CiscoClient.Pss.GetFieldNoticesAsync( new FieldNoticesRequest { diff --git a/Cisco.Api.Test/HelloTests.cs b/Cisco.Api.Test/HelloTests.cs index 11c4764..a29e791 100644 --- a/Cisco.Api.Test/HelloTests.cs +++ b/Cisco.Api.Test/HelloTests.cs @@ -1,4 +1,5 @@ -using Cisco.Api.Data.Hello; +using System.Threading.Tasks; +using Cisco.Api.Data.Hello; using FluentAssertions; using Xunit; using Xunit.Abstractions; @@ -12,7 +13,7 @@ public HelloTests(ITestOutputHelper iTestOutputHelper) : base(iTestOutputHelper) } [Fact] - public async void Hello_Succeeds() + public async Task Hello_Succeeds() { var response = await CiscoClient .Hello diff --git a/Cisco.Api.Test/ProductInformationTests.cs b/Cisco.Api.Test/ProductInformationTests.cs index c751f1d..a4b2b8d 100644 --- a/Cisco.Api.Test/ProductInformationTests.cs +++ b/Cisco.Api.Test/ProductInformationTests.cs @@ -1,5 +1,6 @@ -using FluentAssertions; using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; using Xunit; using Xunit.Abstractions; @@ -12,7 +13,7 @@ public ProductInformationTests(ITestOutputHelper iTestOutputHelper) : base(iTest } [Fact] - public async void GetBySerialNumberAsync_Fails() + public async Task GetBySerialNumberAsync_Fails() { // Note: If no serials are found, then Products will have 1 empty record (yet totals say 0) that also has ErrorResponse set var productInformationPage = await CiscoClient @@ -33,7 +34,7 @@ public async void GetBySerialNumberAsync_Fails() } [Fact] - public async void GetBySerialNumberAsync_Succeeds() + public async Task GetBySerialNumberAsync_Succeeds() { // Note: Serial numbers can be up to 40 chars long. var productInformationPage = await CiscoClient @@ -73,7 +74,7 @@ public async void GetBySerialNumberAsync_Succeeds() } [Fact] - public async void GetBySerialNumberMultipleAsync_Succeeds() + public async Task GetBySerialNumberMultipleAsync_Succeeds() { // Note: Serial numbers can be up to 40 chars long. var productInformationPage = await CiscoClient @@ -111,94 +112,5 @@ public async void GetBySerialNumberMultipleAsync_Succeeds() productInformationPage.Products.Select(productInformation => productInformation.VisioStencilUrl).Should().NotBeNull(); productInformationPage.Products.Select(productInformation => productInformation.Weight).Should().NotBeNull(); } - - //[Fact] - //public async void GetBySerialNumberMultipleAsync_Succeeds() - //{ - // try - // { - // // serial numbers is limited to 40 characters! - // var serialNumbers = new[] { - // "FCW2234L10F", - // "FCW2234L12V", - // "FCW2408P0LF", - // "FCW2408P0LP", - // "FCW2408P0LR", - // "FCW2408P0LS", - // "FCW2408P0LT", - // "FCW2408P0LW", - // "FCW2408P0M0", - // "FCW2408P0M2", - // "FCW2408P0M6", - // "FCW2408P0M9", - // "FCW2408P0MA", - // "FCW2408P0MC", - // "FCW2408P0MD", - // "FCW2408P0MF", - // "FCW2408P0MG", - // "FCW2408P0MJ", - // "FCW2408P0MK", - // "FCW2408P0ML", - // "FCW2234L10E", - // "FCW2234G122", - // "FCW2408P0MN", - // "FCW2408P0MP", - // "FCW2408P0MQ", - // "FCW2408P0MR", - // "FCW2408P0MS", - // "FCW2408P0MT", - // "FCW2408P0MU", - // "FCW2408P0MW", - // "FCW2408P0MX", - // "FCW2408P0MY", - // "FCW2408P0MZ", - // "FCW2408P0N0", - // "FCW2408P0N2", - // "FCW2408P0N3", - // "FCW2408P0N4", - // "FCW2408P0N5", - // "FCW2408P0N7", - // "FCW2408P0N8", - // "FOC2308U19E", - // "FCW2311L110", - // "FCW2408P0N9", - // "FCW2408P0NA", - // "FCW2408P0NB", - // "FCW2408P0NC", - // "FCW2408P0ND", - // "FCW2408P0NE", - // "FCW2408P0NF", - // "FCW2408P0NG", - // "FCW2408P0NH", - // "FCW2408P0NJ", - // "FCW2408P0NK", - // "FCW2408P0NL", - // "FCW2408P0NN", - // "FCW2408P0NP", - // "FCW2408P0NQ", - // "FCW2408P0NR", - // "FCW2408P0NS", - // "FCW2408P0NT" - // }; - - // ProductInformationPage productInformationPage; - // var basePids = new List(); - // foreach (var serialNumber in serialNumbers) - // { - // productInformationPage = await CiscoClient - // .ProductInfo - // .GetBySerialNumbersAsync(new[] { serialNumber }) - // .ConfigureAwait(false); - - // basePids.Add(productInformationPage.Products.First().BasePid); - // } - - // basePids = basePids.Distinct().ToList(); - // } - // catch (Exception ex) - // { - - // } - //} } } \ No newline at end of file diff --git a/Cisco.Api.Test/PsirtTests.cs b/Cisco.Api.Test/PsirtTests.cs index e161ba1..ca18659 100644 --- a/Cisco.Api.Test/PsirtTests.cs +++ b/Cisco.Api.Test/PsirtTests.cs @@ -1,6 +1,7 @@ +using System.Threading; +using System.Threading.Tasks; using Cisco.Api.Data.Psirt; using FluentAssertions; -using System.Threading; using Xunit; using Xunit.Abstractions; @@ -13,7 +14,7 @@ public PsirtTests(ITestOutputHelper iTestOutputHelper) : base(iTestOutputHelper) } [Fact] - public async void GetPsirtByCveId() + public async Task GetPsirtByCveId() { var advisoryResponse = await CiscoClient .Psirt @@ -27,7 +28,7 @@ public async void GetPsirtByCveId() } [Fact] - public async void GetAllPsirts() + public async Task GetAllPsirts() { var advisoryResponse = await CiscoClient .Psirt diff --git a/Cisco.Api.Test/PssTests.cs b/Cisco.Api.Test/PssTests.cs index bbe2b83..a0f337a 100644 --- a/Cisco.Api.Test/PssTests.cs +++ b/Cisco.Api.Test/PssTests.cs @@ -1,384 +1,361 @@ -using Cisco.Api.Data.Pss; -using FluentAssertions; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Cisco.Api.Data.Pss; +using FluentAssertions; using Xunit; using Xunit.Abstractions; namespace Cisco.Api.Test { - [Collection("PssTests")] - public class PssTests : Test - { - public PssTests(ITestOutputHelper iTestOutputHelper) : base(iTestOutputHelper) - { - } - - [Fact] - public async void GetCustomersInventoryIdsAsync_Succeeds() - { - var response = await CiscoClient - .Pss - .GetCustomersInventoryIdsAsync(new CustomersInventoryRequest(), CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - response.CustomerInventories.Should().NotBeEmpty(); - response.CustomerInventories.Select(ci => ci.Inventory).Should().NotBeNull(); - response.CustomerInventories.Select(ci => ci.Customer).Should().NotBeNull(); - - response.ResponseTimestamp.Should().NotBe(new DateTime()); - - response.Message.Should().NotBeNull(); - response.Message.MessageType.Should().NotBeNull(); - response.Message.MessageDetail.Should().NotBeNull(); - } - - [Fact] - public async void GetCustomerInventoryAsync_OneCustomer_Succeeds() - { - var response = await CiscoClient - .Pss - .GetCustomersInventoryIdsAsync(new CustomersInventoryRequest - { - CustomerIds = new List - { - Config.TestCustomerId - } - }, CancellationToken.None) - .ConfigureAwait(false); - - response.CustomerInventories.Should().HaveCount(1); - } - - [Fact] - public async void GetCustomerInventoryDetails_Succeeds() - { - var response = await CiscoClient - .Pss - .GetCustomerInventoryDetailsAsync( - new CustomerInventoryDetailsRequest - { - CustomerId = Config.TestCustomerId, - InventoryId = Config.TestInventoryId - }, - CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetExtendedCustomerInventoryDetails_FirstPage_Succeeds() - { - var response = await CiscoClient - .Pss - .GetCustomerExtendedInventoryDetailsAsync( - new CustomerExtendedInventoryDetailsRequest - { - CustomerId = Config.TestCustomerId, - InventoryId = Config.TestInventoryId, - PageStart = 1 - }, - CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetAllExtendedDeviceDetail_Succeeds() - { - var deviceDetails = await GetAllExtendedDeviceDetail( - CiscoClient, - Config.TestCustomerId, - Config.TestInventoryId, - CancellationToken.None) - .ConfigureAwait(false); - - deviceDetails.Should().NotBeNullOrEmpty(); - } - - // Example implementation of getting all ExtendedDeviceDetails - private static async Task> GetAllExtendedDeviceDetail( - CiscoClient client, - string CustomerId, - string InventoryId, - CancellationToken cancellationToken) - { - var deviceDetails = new List(); - var page = 0; - int pageTotal; - do - { - page++; - var response = await client - .Pss - .GetCustomerExtendedInventoryDetailsAsync( - new CustomerExtendedInventoryDetailsRequest - { - CustomerId = CustomerId, - InventoryId = InventoryId, - PageStart = page - }, - cancellationToken) - .ConfigureAwait(false); - deviceDetails.AddRange(response.DeviceDetails); - pageTotal = response.Pages.PageTotal; - } while (page < pageTotal); - return deviceDetails; - } - - [Fact] - public async void GetCustomerInventoryPaginatedDetails_Succeeds() - { - var response = await CiscoClient - .Pss - .GetCustomerInventoryPaginatedDetailsAsync(new CustomerInventoryDetailPaginatedRequest - { - CustomerId = Config.TestCustomerId, - InventoryId = Config.TestInventoryId - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetContractCoverageDetailsAsync_Succeeds() - { - var response = await CiscoClient - .Pss - .GetContractCoverageAsync(new ContractCoverageRequest - { - CustomerId = Config.TestCustomerId, - InventoryId = Config.TestInventoryId - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetContractCoverageDetailsOneCardIdAsync_Succeeds() - { - var response = await CiscoClient - .Pss - .GetContractCoverageAsync(new ContractCoverageRequest - { - CustomerId = Config.TestCustomerId, - InventoryId = Config.TestInventoryId, - DeviceIds = new List { Config.TestDeviceId } - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - // Test disabled as TestDeviceId not always set, so enable if needed - //[Fact] - //public async void GetContractCoverageDetailsForDeviceIdsAsync_Succeeds() - //{ - // // Query upto 100 devices at a time - // var deviceIds = new List { Config.TestDeviceId }; - - // var response = await CiscoClient - // .Pss - // .GetContractCoverageAsync(new ContractCoverageRequest - // { - // CustomerId = Config.TestCustomerId, - // InventoryId = Config.TestInventoryId, - // DeviceIds = deviceIds - // }, CancellationToken.None) - // .ConfigureAwait(false); - - // response.Should().BeOfType(); - // response.Should().NotBeNull(); - - // // TODO - property tests - //} - - [Fact] - public async void GetSoftwareEoxAsync_Succeeds() - { - var response = await CiscoClient - .Pss - .GetSoftwareEoxAsync(new SoftwareEoxRequest - { - CustomerId = Config.TestCustomerId, - InventoryId = Config.TestInventoryId - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetSoftwareEoxBulletinAsync_Succeeds() - { - var response = await CiscoClient - .Pss - .GetSoftwareEoxBulletinAsync(new SoftwareEoxBulletinRequest - { - SoftwareEoxIds = new SoftwareEoxIds - { - Ids = new List - { - Config.TestSoftwareEoxId - } - } - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetHwEoxAsync_Succeeds() - { - var response = await CiscoClient - .Pss - .GetHardwareEoxAsync(new HardwareEoxRequest - { - CustomerId = Config.TestCustomerId, - InventoryId = Config.TestInventoryId - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetHwEoxBulletinAsync_Succeeds() - { - var response = await CiscoClient - .Pss - // Responses seem to be duplicated per HardwareEoxId - .GetHardwareEoxBulletinAsync(new HardwareEoxBulletinRequest - { - HardwareEoxIds = new HardwareEoxIds - { - Ids = new List - { - Config.TestHardwareEoxId - } - } - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetPsirtAsync_Succeeds() - { - var response = await CiscoClient - .Pss - .GetPsirtAsync(new PsirtRequest - { - CustomerId = "PSS_3151974", // Config.TestCustomerId, - InventoryId = "3232417", // Config.TestInventoryId - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetPsirtDetailsAsync_Succeeds() - { - var ids = new List - { - Config.TestPsirtId1, - Config.TestPsirtId2 - }; - - var response = await CiscoClient - .Pss - .GetPsirtDetailsAsync(new PsirtDetailsRequest - { - Ids = ids - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - response.Details.Count.Should().Be(ids.Count); - // TODO - property tests - } - - [Fact] - public async void GetFieldNoticesAsync_Succeeds() - { - var response = await CiscoClient - .Pss - .GetFieldNoticesAsync(new FieldNoticesRequest - { - CustomerId = Config.TestCustomerId, - InventoryId = Config.TestInventoryId - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - - [Fact] - public async void GetFieldNoticesDetailsAsync_Succeeds() - { - var response = await CiscoClient - .Pss - .GetFieldNoticesDetailsAsync(new FieldNoticesDetailsRequest - { - Ids = new List - { - Config.TestFieldNoticesId1, - Config.TestFieldNoticesId2 - } - }, CancellationToken.None) - .ConfigureAwait(false); - - response.Should().BeOfType(); - response.Should().NotBeNull(); - - // TODO - property tests - } - } + [Collection("PssTests")] + public class PssTests : Test + { + public PssTests(ITestOutputHelper iTestOutputHelper) : base(iTestOutputHelper) + { + } + + [Fact] + public async Task GetCustomersInventoryIdsAsync_Succeeds() + { + var response = await CiscoClient + .Pss + .GetCustomersInventoryIdsAsync(new CustomersInventoryRequest(), CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + response.CustomerInventories.Should().NotBeEmpty(); + response.CustomerInventories.Select(ci => ci.Inventory).Should().NotBeNull(); + response.CustomerInventories.Select(ci => ci.Customer).Should().NotBeNull(); + + response.ResponseTimestamp.Should().NotBe(new DateTime()); + + response.Message.Should().NotBeNull(); + response.Message.MessageType.Should().NotBeNull(); + response.Message.MessageDetail.Should().NotBeNull(); + } + + [Fact] + public async Task GetCustomerInventoryAsync_OneCustomer_Succeeds() + { + var response = await CiscoClient + .Pss + .GetCustomersInventoryIdsAsync(new CustomersInventoryRequest + { + CustomerIds = new List + { + Config.TestCustomerId + } + }, CancellationToken.None) + .ConfigureAwait(false); + + response.CustomerInventories.Should().HaveCount(1); + } + + [Fact] + public async Task GetCustomerInventoryDetails_Succeeds() + { + var response = await CiscoClient + .Pss + .GetCustomerInventoryDetailsAsync( + new CustomerInventoryDetailsRequest + { + CustomerId = Config.TestCustomerId, + InventoryId = Config.TestInventoryId + }, + CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetExtendedCustomerInventoryDetails_FirstPage_Succeeds() + { + var response = await CiscoClient + .Pss + .GetCustomerExtendedInventoryDetailsAsync( + new CustomerExtendedInventoryDetailsRequest + { + CustomerId = Config.TestCustomerId, + InventoryId = Config.TestInventoryId, + PageStart = 1 + }, + CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetAllExtendedDeviceDetail_Succeeds() + { + var deviceDetails = await GetAllExtendedDeviceDetail( + CiscoClient, + Config.TestCustomerId, + Config.TestInventoryId, + CancellationToken.None) + .ConfigureAwait(false); + + deviceDetails.Should().NotBeNullOrEmpty(); + } + + // Example implementation of getting all ExtendedDeviceDetails + private static async Task> GetAllExtendedDeviceDetail( + CiscoClient client, + string CustomerId, + string InventoryId, + CancellationToken cancellationToken) + { + var deviceDetails = new List(); + var page = 0; + int pageTotal; + do + { + page++; + var response = await client + .Pss + .GetCustomerExtendedInventoryDetailsAsync( + new CustomerExtendedInventoryDetailsRequest + { + CustomerId = CustomerId, + InventoryId = InventoryId, + PageStart = page + }, + cancellationToken) + .ConfigureAwait(false); + deviceDetails.AddRange(response.DeviceDetails); + pageTotal = response.Pages.PageTotal; + } while (page < pageTotal); + return deviceDetails; + } + + [Fact] + public async Task GetCustomerInventoryPaginatedDetails_Succeeds() + { + var response = await CiscoClient + .Pss + .GetCustomerInventoryPaginatedDetailsAsync(new CustomerInventoryDetailPaginatedRequest + { + CustomerId = Config.TestCustomerId, + InventoryId = Config.TestInventoryId + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetContractCoverageDetailsAsync_Succeeds() + { + var response = await CiscoClient + .Pss + .GetContractCoverageAsync(new ContractCoverageRequest + { + CustomerId = Config.TestCustomerId, + InventoryId = Config.TestInventoryId + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetContractCoverageDetailsOneCardIdAsync_Succeeds() + { + var response = await CiscoClient + .Pss + .GetContractCoverageAsync(new ContractCoverageRequest + { + CustomerId = Config.TestCustomerId, + InventoryId = Config.TestInventoryId, + DeviceIds = new List { Config.TestDeviceId } + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetSoftwareEoxAsync_Succeeds() + { + var response = await CiscoClient + .Pss + .GetSoftwareEoxAsync(new SoftwareEoxRequest + { + CustomerId = Config.TestCustomerId, + InventoryId = Config.TestInventoryId + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetSoftwareEoxBulletinAsync_Succeeds() + { + var response = await CiscoClient + .Pss + .GetSoftwareEoxBulletinAsync(new SoftwareEoxBulletinRequest + { + SoftwareEoxIds = new SoftwareEoxIds + { + Ids = new List + { + Config.TestSoftwareEoxId + } + } + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetHwEoxAsync_Succeeds() + { + var response = await CiscoClient + .Pss + .GetHardwareEoxAsync(new HardwareEoxRequest + { + CustomerId = Config.TestCustomerId, + InventoryId = Config.TestInventoryId + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetHwEoxBulletinAsync_Succeeds() + { + var response = await CiscoClient + .Pss + // Responses seem to be duplicated per HardwareEoxId + .GetHardwareEoxBulletinAsync(new HardwareEoxBulletinRequest + { + HardwareEoxIds = new HardwareEoxIds + { + Ids = new List + { + Config.TestHardwareEoxId + } + } + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetPsirtAsync_Succeeds() + { + var response = await CiscoClient + .Pss + .GetPsirtAsync(new PsirtRequest + { + CustomerId = "PSS_3151974", // Config.TestCustomerId, + InventoryId = "3232417", // Config.TestInventoryId + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetPsirtDetailsAsync_Succeeds() + { + var ids = new List + { + Config.TestPsirtId1, + Config.TestPsirtId2 + }; + + var response = await CiscoClient + .Pss + .GetPsirtDetailsAsync(new PsirtDetailsRequest + { + Ids = ids + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + response.Details.Count.Should().Be(ids.Count); + // TODO - property tests + } + + [Fact] + public async Task GetFieldNoticesAsync_Succeeds() + { + var response = await CiscoClient + .Pss + .GetFieldNoticesAsync(new FieldNoticesRequest + { + CustomerId = Config.TestCustomerId, + InventoryId = Config.TestInventoryId + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + + [Fact] + public async Task GetFieldNoticesDetailsAsync_Succeeds() + { + var response = await CiscoClient + .Pss + .GetFieldNoticesDetailsAsync(new FieldNoticesDetailsRequest + { + Ids = new List + { + Config.TestFieldNoticesId1, + Config.TestFieldNoticesId2 + } + }, CancellationToken.None) + .ConfigureAwait(false); + + response.Should().BeOfType(); + response.Should().NotBeNull(); + + // TODO - property tests + } + } } diff --git a/Cisco.Api.Test/SerialNumberToInfoTests.cs b/Cisco.Api.Test/SerialNumberToInfoTests.cs index d0282b6..1176fd2 100644 --- a/Cisco.Api.Test/SerialNumberToInfoTests.cs +++ b/Cisco.Api.Test/SerialNumberToInfoTests.cs @@ -1,5 +1,6 @@ -using FluentAssertions; using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; using Xunit; using Xunit.Abstractions; @@ -12,7 +13,7 @@ public SerialNumberToInfoTests(ITestOutputHelper iTestOutputHelper) : base(iTest } [Fact] - public async void GetCoverageStatusBySerialNumber() + public async Task GetCoverageStatusBySerialNumber() { var coverageStatusCollection = await CiscoClient .SerialNumberToInfo @@ -26,7 +27,7 @@ public async void GetCoverageStatusBySerialNumber() } [Fact] - public async void GetCoverageSummaryBySerialNumber() + public async Task GetCoverageSummaryBySerialNumber() { var coverageSummaryCollection = await CiscoClient .SerialNumberToInfo @@ -52,7 +53,7 @@ public async void GetCoverageSummaryBySerialNumber() } [Fact] - public async void GetOrderableProductIdentifierBySerialNumber() + public async Task GetOrderableProductIdentifierBySerialNumber() { var serialNumberOrderablePids = await CiscoClient .SerialNumberToInfo diff --git a/Cisco.Api/CiscoClient.cs b/Cisco.Api/CiscoClient.cs index 233b01a..b97305c 100644 --- a/Cisco.Api/CiscoClient.cs +++ b/Cisco.Api/CiscoClient.cs @@ -1,17 +1,17 @@ -using Cisco.Api.Interfaces; +using System; +using System.Collections.Generic; +using System.Net.Http; +using Cisco.Api.Interfaces; using Cisco.Api.Security; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Refit; -using System; -using System.Collections.Generic; -using System.Net.Http; namespace Cisco.Api { - public partial class CiscoClient : IDisposable + public class CiscoClient : IDisposable { private readonly ILogger _logger; private readonly HttpClient _restHttpClient; diff --git a/Cisco.Api/Data/Psirt/Advisory.cs b/Cisco.Api/Data/Psirt/Advisory.cs index 40d3652..6b3cda0 100644 --- a/Cisco.Api/Data/Psirt/Advisory.cs +++ b/Cisco.Api/Data/Psirt/Advisory.cs @@ -5,7 +5,7 @@ namespace Cisco.Api.Data.Psirt { [DataContract] - public partial class Advisory + public class Advisory { [DataMember(Name = "advisoryId")] public string AdvisoryId { get; set; } = null!; diff --git a/Cisco.Api/Data/Pss/DeviceDetail.cs b/Cisco.Api/Data/Pss/DeviceDetail.cs index ce638a1..3acebec 100644 --- a/Cisco.Api/Data/Pss/DeviceDetail.cs +++ b/Cisco.Api/Data/Pss/DeviceDetail.cs @@ -87,13 +87,13 @@ public class DeviceDetail /// Date the original inventory was performed. /// [XmlElement("originalInventoryDate")] - public DateTime? OriginalInventoryDate; + private DateTime? _originalInventoryDate; /// /// The date the last inventory was performed. /// [XmlElement("lastInventoryDate")] - public DateTime? LastInventoryDate; + private DateTime? _lastInventoryDate; /// /// Base product id of the device. diff --git a/Cisco.Api/Data/Pss/PssResponseMessageDetails.cs b/Cisco.Api/Data/Pss/PssResponseMessageDetails.cs index e544168..043f3d3 100644 --- a/Cisco.Api/Data/Pss/PssResponseMessageDetails.cs +++ b/Cisco.Api/Data/Pss/PssResponseMessageDetails.cs @@ -1,8 +1,8 @@ namespace Cisco.Api.Data.Pss { - public static class PssResponseMessageDetails - { - public const string NoAlertsPresent = "No alerts present for the given input parameters"; - public const string NoDataAvailable = "No data available for given input parameters."; - } + public static class PssResponseMessageDetails + { + public static readonly string NoAlertsPresent = "No alerts present for the given input parameters"; + public static readonly string NoDataAvailable = "No data available for given input parameters."; + } } diff --git a/Cisco.Api/Data/Pss/PssResponseMessageType.cs b/Cisco.Api/Data/Pss/PssResponseMessageType.cs index 71b411c..a61ecd4 100644 --- a/Cisco.Api/Data/Pss/PssResponseMessageType.cs +++ b/Cisco.Api/Data/Pss/PssResponseMessageType.cs @@ -1,8 +1,8 @@ namespace Cisco.Api.Data.Pss { - public static class PssResponseMessageType - { - public const string Success = "SUCCESS"; - public const string Failure = "FAILURE"; - } + public static class PssResponseMessageType + { + public static readonly string Success = "SUCCESS"; + public static readonly string Failure = "FAILURE"; + } } diff --git a/Cisco.Api/Exceptions/ConfigurationException.cs b/Cisco.Api/Exceptions/ConfigurationException.cs index 1a18306..4b94a2e 100644 --- a/Cisco.Api/Exceptions/ConfigurationException.cs +++ b/Cisco.Api/Exceptions/ConfigurationException.cs @@ -4,7 +4,7 @@ namespace Cisco.Api.Exceptions { [Serializable] - internal class ConfigurationException : Exception + public class ConfigurationException : Exception { public ConfigurationException() { diff --git a/Cisco.Api/Interfaces/IPss.cs b/Cisco.Api/Interfaces/IPss.cs index b060898..10a2979 100644 --- a/Cisco.Api/Interfaces/IPss.cs +++ b/Cisco.Api/Interfaces/IPss.cs @@ -1,154 +1,150 @@ -using Cisco.Api.Data.Pss; -using System.Threading; +using System.Threading; using System.Threading.Tasks; +using Cisco.Api.Data.Pss; namespace Cisco.Api.Interfaces { - /// - /// PSS calls - /// - public interface IPss - { - /// - /// This service call provides all the various contract information - /// (contract details, coverage, and siteaddress info). - /// - /// - /// - /// - Task GetContractCoverageAsync( - ContractCoverageRequest request, - CancellationToken cancellationToken); + /// + /// PSS calls + /// + public interface IPss + { + /// + /// This service call provides all the various contract information + /// (contract details, coverage, and siteaddress info). + /// + /// + /// + /// + Task GetContractCoverageAsync( + ContractCoverageRequest request, + CancellationToken cancellationToken); - /// - /// This API call fetches a list of Customer ID’s, and Inventory ID’s. - /// This is the second step in a four step process of obtaining service call related information. - /// - /// - /// - /// - Task GetCustomersInventoryIdsAsync( - CustomersInventoryRequest customersInventoryRequest, - CancellationToken cancellationToken); + /// + /// This API call fetches a list of Customer ID’s, and Inventory ID’s. + /// This is the second step in a four step process of obtaining service call related information. + /// + /// + /// + /// + Task GetCustomersInventoryIdsAsync( + CustomersInventoryRequest customersInventoryRequest, + CancellationToken cancellationToken); - /// - /// This API service call returns a collection of Inventory elements - /// (device details, chassis details) for a given Inventory. - /// This is the third step in a four step process of obtaining service call related information. - /// - /// - /// - /// - Task GetCustomerInventoryDetailsAsync( - CustomerInventoryDetailsRequest request, - CancellationToken cancellationToken); + /// + /// This API service call returns a collection of Inventory elements + /// (device details, chassis details) for a given Inventory. + /// This is the third step in a four step process of obtaining service call related information. + /// + /// + /// + /// + Task GetCustomerInventoryDetailsAsync( + CustomerInventoryDetailsRequest request, + CancellationToken cancellationToken); - /// - /// This API service call returns a collection of Inventory elements - /// (device details, chassis details) for a given Inventory. - /// This is the third step in a four step process of obtaining service call related information. - /// - /// - /// - /// - Task GetCustomerExtendedInventoryDetailsAsync( - CustomerExtendedInventoryDetailsRequest request, - CancellationToken cancellationToken); + /// + /// This API service call returns a collection of Inventory elements + /// (device details, chassis details) for a given Inventory. + /// This is the third step in a four step process of obtaining service call related information. + /// + /// + /// + /// + Task GetCustomerExtendedInventoryDetailsAsync( + CustomerExtendedInventoryDetailsRequest request, + CancellationToken cancellationToken); - /// - /// This operation will return (in addition to what is returned by getCustomerInventoryDetails) - /// a new section at the beginning of the response called 'pages'. This section has four parts: - /// pageSize, pageCurrent, pageTotal, pidCount - /// - /// - /// - /// - Task GetCustomerInventoryPaginatedDetailsAsync( - CustomerInventoryDetailPaginatedRequest request, - CancellationToken cancellationToken); + /// + /// This operation will return (in addition to what is returned by getCustomerInventoryDetails) + /// a new section at the beginning of the response called 'pages'. This section has four parts: + /// pageSize, pageCurrent, pageTotal, pidCount + /// + /// + /// + /// + Task GetCustomerInventoryPaginatedDetailsAsync( + CustomerInventoryDetailPaginatedRequest request, + CancellationToken cancellationToken); - //Task GetEoswmLifecycleAsync( - // EoswmLifecycleRequest request, - // CancellationToken cancellationToken); + /// + /// This API service call gets all Field Notices for the specified customer, inventory and devices. + /// + /// + /// + /// + Task GetFieldNoticesAsync( + FieldNoticesRequest request, + CancellationToken cancellationToken); - /// - /// This API service call gets all Field Notices for the specified customer, inventory and devices. - /// - /// - /// - /// - Task GetFieldNoticesAsync( - FieldNoticesRequest request, - CancellationToken cancellationToken); + /// + /// This API call fetches details about specified Field Notices. + /// + /// + /// + /// + Task GetFieldNoticesDetailsAsync( + FieldNoticesDetailsRequest request, + CancellationToken cancellationToken); - /// - /// This API call fetches details about specified Field Notices. - /// - /// - /// - /// - Task GetFieldNoticesDetailsAsync( - FieldNoticesDetailsRequest request, - CancellationToken cancellationToken); + /// + /// This API call returns the hardware end-of-life id and product id information. + /// + /// + /// + /// + Task GetHardwareEoxAsync( + HardwareEoxRequest request, + CancellationToken cancellationToken); - /// - /// This API call returns the hardware end-of-life id and product id information. - /// - /// - /// - /// - Task GetHardwareEoxAsync( - HardwareEoxRequest request, - CancellationToken cancellationToken); + /// + /// This API call fetches descriptive details for the given HWEoxId(s). + /// + /// + /// + /// + Task GetHardwareEoxBulletinAsync( + HardwareEoxBulletinRequest request, + CancellationToken cancellationToken); - /// - /// This API call fetches descriptive details for the given HWEoxId(s). - /// - /// - /// - /// - Task GetHardwareEoxBulletinAsync( - HardwareEoxBulletinRequest request, - CancellationToken cancellationToken); + /// + /// This API service call gets all PSIRT Alerts for the specified customer, inventory and devices. + /// + /// + /// + /// + Task GetPsirtAsync( + PsirtRequest request, + CancellationToken cancellationToken); - /// - /// This API service call gets all PSIRT Alerts for the specified customer, inventory and devices. - /// - /// - /// - /// - Task GetPsirtAsync( - PsirtRequest request, - CancellationToken cancellationToken); + /// + /// This API call fetches details about specified PSIRTs. + /// + /// + /// + /// + Task GetPsirtDetailsAsync( + PsirtDetailsRequest request, + CancellationToken cancellationToken); - /// - /// This API call fetches details about specified PSIRTs. - /// - /// - /// - /// - Task GetPsirtDetailsAsync( - PsirtDetailsRequest request, - CancellationToken cancellationToken); + /// + /// This API call fetches software end-of-life id and product id information. + /// + /// + /// + /// + Task GetSoftwareEoxAsync( + SoftwareEoxRequest request, + CancellationToken cancellationToken); - /// - /// This API call fetches software end-of-life id and product id information. - /// - /// - /// - /// - Task GetSoftwareEoxAsync( - SoftwareEoxRequest request, - CancellationToken cancellationToken); - - /// - /// This API call fetches various software end-of-life bulletins information. - /// - /// - /// - /// - Task GetSoftwareEoxBulletinAsync( - SoftwareEoxBulletinRequest request, - CancellationToken cancellationToken); - } + /// + /// This API call fetches various software end-of-life bulletins information. + /// + /// + /// + /// + Task GetSoftwareEoxBulletinAsync( + SoftwareEoxBulletinRequest request, + CancellationToken cancellationToken); + } } \ No newline at end of file diff --git a/Cisco.Api/Security/AuthenticatedHttpClientHandler.cs b/Cisco.Api/Security/AuthenticatedHttpClientHandler.cs index 6a83235..46fd479 100644 --- a/Cisco.Api/Security/AuthenticatedHttpClientHandler.cs +++ b/Cisco.Api/Security/AuthenticatedHttpClientHandler.cs @@ -1,7 +1,4 @@ -using Cisco.Api.Exceptions; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using System; +using System; using System.Net; using System.Net.Http; using System.Net.Http.Headers; @@ -9,6 +6,9 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using Cisco.Api.Exceptions; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace Cisco.Api.Security { @@ -106,22 +106,6 @@ await Task.Delay(_options.RetryDelay, cancellationToken) var expireInSeconds = accessTokenResponse.ExpiresInSeconds; - /* - _logger.LogDebug($"Access token will expire in {expireInSeconds} seconds."); - // If there is an expiry, try to take 1 minute off it unless it is already less than a minute - if (accessTokenResponse.ExpiresInSeconds is not null && accessTokenResponse.ExpiresInSeconds - 60 > 0) - { - expireInSeconds -= 60; - //_logger.LogDebug("Since expiry > 60 seconds, it has been reduced further by 1 minute to give time to trigger refresh of token."); - } - // If not yet set, set expiry to default timeout of the 1 hour max limit, minus a minute. - if (expireInSeconds is null) - { - //_logger.LogDebug("The access token 'ExpiresInSeconds' was null, setting to 3540 seconds."); - expireInSeconds = 3540; - } - */ - // Set expiry, defaulting to 1 hour if not set _accessTokenExpiryDateTimeOffset = DateTimeOffset.UtcNow.AddSeconds(expireInSeconds ?? 3600); _logger.LogDebug( @@ -154,8 +138,6 @@ protected override async Task SendAsync( _authenticationHeaderValue = new AuthenticationHeaderValue("Bearer", _accessToken); } - //_logger.LogDebug($"SendAsync(): About to send query. The access token expiry date time is '{_accessTokenExpiryDateTimeOffset}'."); - request.Headers.Authorization = _authenticationHeaderValue; request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*")); @@ -223,7 +205,7 @@ await Task.Delay(_options.RetryDelay, cancellationToken) if (!httpResponseMessage.IsSuccessStatusCode) { #if !DEBUG - var message = await GetResponseContent(statusCode, content).ConfigureAwait(false); + var message = await GetResponseContent(statusCode, content).ConfigureAwait(false); #endif switch (httpResponseMessage.StatusCode)