From f4a638b1fe1102bef638fa9815fc5231a341d6ec Mon Sep 17 00:00:00 2001 From: Boshi Lian Date: Wed, 21 Sep 2022 12:11:18 -0700 Subject: [PATCH] shortcut for iitem (#883) * shortcut for iitem * syntax guard --- src/KubernetesClient.Models/IItems.cs | 8 +++++++ .../KubernetesClient.Tests/ItemsEnumTests.cs | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/KubernetesClient.Tests/ItemsEnumTests.cs diff --git a/src/KubernetesClient.Models/IItems.cs b/src/KubernetesClient.Models/IItems.cs index 408f77cb..58f4a629 100644 --- a/src/KubernetesClient.Models/IItems.cs +++ b/src/KubernetesClient.Models/IItems.cs @@ -12,4 +12,12 @@ public interface IItems /// IList Items { get; set; } } + + public static class ItemsExt + { + public static IEnumerator GetEnumerator(this IItems items) + { + return items.Items.GetEnumerator(); + } + } } diff --git a/tests/KubernetesClient.Tests/ItemsEnumTests.cs b/tests/KubernetesClient.Tests/ItemsEnumTests.cs new file mode 100644 index 00000000..2fd4098c --- /dev/null +++ b/tests/KubernetesClient.Tests/ItemsEnumTests.cs @@ -0,0 +1,22 @@ +using Xunit; +using k8s.Models; + +namespace k8s.Tests; + +public class ItemsEnumTests +{ + [Fact] + public void EnsureIItemsEnumerable() + { + var pods = new V1PodList + { + Items = new[] { new V1Pod() }, + }; + + // ensure no sytax err + foreach (var pod in pods) + { + Assert.NotNull(pod); + } + } +}