public async Task GetLicenseAsync_NoLicense_ReturnsNull_Async() { var client = new Mock <KubernetesClient>(MockBehavior.Strict); var configClient = new Mock <NamespacedKubernetesClient <V1ConfigMap> >(MockBehavior.Strict); client.Setup(c => c.GetClient <V1ConfigMap>()).Returns(configClient.Object); configClient.Setup(c => c.TryReadAsync("kaponata-license", default)).ReturnsAsync((V1ConfigMap)null); var store = new LicenseStore(client.Object, NullLogger <LicenseStore> .Instance); Assert.Null(await store.GetLicenseAsync(default).ConfigureAwait(false));
public async Task AddLicenseAsync_AddsNew_Async() { var client = new Mock <KubernetesClient>(MockBehavior.Strict); var configClient = new Mock <NamespacedKubernetesClient <V1ConfigMap> >(MockBehavior.Strict); client.Setup(c => c.GetClient <V1ConfigMap>()).Returns(configClient.Object); configClient.Setup(c => c.TryReadAsync("kaponata-license", default)).ReturnsAsync((V1ConfigMap)null).Verifiable(); configClient.Setup(c => c.CreateAsync(It.IsAny <V1ConfigMap>(), default)).Returns(Task.FromResult(new V1ConfigMap())).Verifiable(); var store = new LicenseStore(client.Object, NullLogger <LicenseStore> .Instance); var license = new XDocument(); await store.AddLicenseAsync(license, default).ConfigureAwait(false); configClient.Verify(); }
public async Task AddLicenseAsync_UpdatesExisting_Async() { var client = new Mock <KubernetesClient>(MockBehavior.Strict); var configClient = new Mock <NamespacedKubernetesClient <V1ConfigMap> >(MockBehavior.Strict); client.Setup(c => c.GetClient <V1ConfigMap>()).Returns(configClient.Object); var configMap = new V1ConfigMap(); configClient.Setup(c => c.TryReadAsync("kaponata-license", default)).ReturnsAsync(configMap).Verifiable(); configClient.Setup(c => c.PatchAsync(configMap, It.IsAny <JsonPatchDocument <V1ConfigMap> >(), default)).ReturnsAsync(configMap).Verifiable(); var store = new LicenseStore(client.Object, NullLogger <LicenseStore> .Instance); var license = new XDocument(); await store.AddLicenseAsync(license, default).ConfigureAwait(false); configClient.Verify(); }
/// <summary> /// Initializes a new instance of the <see cref="LicenseController"/> class. /// </summary> /// <param name="licenseStore"> /// A <see cref="LicenseStore"/> which is used to store the Kaponata license. /// </param> /// <param name="logger"> /// A logger which is used when logging messages. /// </param> public LicenseController(LicenseStore licenseStore, ILogger <LicenseController> logger) { this.licenseStore = licenseStore ?? throw new ArgumentNullException(nameof(licenseStore)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public async Task AddLicenseAsync_ValidatesArguments_Async() { var store = new LicenseStore(Mock.Of <KubernetesClient>(), NullLogger <LicenseStore> .Instance); await Assert.ThrowsAsync <ArgumentNullException>(() => store.AddLicenseAsync(null, default)).ConfigureAwait(false); }