public async Task InitialListGetsAddedToCache()
        {
            var resource1 = new Mock1Resource(TestNamespace, "1");
            var resource2 = new Mock1Resource(TestNamespace, "2");

            _items.Add(resource1);
            _items.Add(resource2);
            await _watcher.StartAsync();

            _watcher.Should().BeEquivalentTo(resource1, resource2);
        }
        public async Task ModifiedResourceGetsUpdatedInCache()
        {
            var resource1A = new Mock1Resource(TestNamespace, "1", spec: 1);
            var resource1B = new Mock1Resource(TestNamespace, "1", spec: 2);

            _items.Add(resource1A);
            await _watcher.StartAsync();

            _events.OnNext(Modified(resource1B));

            _watcher.Should().BeEquivalentTo(resource1B);
        }
        public async Task DeletedResourceGetsRemovedFromCache()
        {
            var resource1 = new Mock1Resource(TestNamespace, "1");
            var resource2 = new Mock1Resource(TestNamespace, "2");

            _items.Add(resource1);
            _items.Add(resource2);
            await _watcher.StartAsync();

            _events.OnNext(Deleted(resource2));

            _watcher.Should().BeEquivalentTo(resource1);
        }
        public async Task DeletesSuperfluousItems()
        {
            const string labelSelector = "a=b";
            const string @namespace    = "ns";

            var item1 = new Mock1Resource(@namespace, "item1", 1);
            var item2 = new Mock1Resource(@namespace, "item2", 2);

            _clientMock.Setup(x => x.ListAsync(labelSelector, @namespace, CancellationToken.None)).ReturnsAsync(new CustomResourceList <Mock1Resource>
            {
                Items = { item1, item2 }
            });

            _clientMock.Setup(x => x.DeleteAsync(item2.Metadata.Name, item2.Metadata.Namespace, CancellationToken.None)).ReturnsAsync(item2);

            await _client.RealizeStateAsync(new[] { item1 }, labelSelector, @namespace);
        }
        public async Task UpdatesExistingItems()
        {
            const string labelSelector = "a=b";
            const string @namespace    = "ns";

            var item1         = new Mock1Resource(@namespace, "item1", 1);
            var item2         = new Mock1Resource(@namespace, "item2", 2);
            var item2Mismatch = new Mock1Resource(@namespace, "item2", 3);

            _clientMock.Setup(x => x.ListAsync(labelSelector, @namespace, CancellationToken.None)).ReturnsAsync(new CustomResourceList <Mock1Resource>
            {
                Items = { item1, item2Mismatch }
            });

            _clientMock.Setup(x => x.UpdateAsync(item2.Metadata.Name, It.IsAny <Action <JsonPatchDocument <Mock1Resource> > >(), @namespace, CancellationToken.None)).ReturnsAsync(item2);

            await _client.RealizeStateAsync(new[] { item1, item2 }, labelSelector, @namespace);
        }
 private static IResourceEventV1 <Mock1Resource> Deleted(Mock1Resource resource)
 => new ResourceEventV1 <Mock1Resource>
 {
     EventType = ResourceEventType.Deleted, Resource = resource
 };
 private static IResourceEventV1 <Mock1Resource> Modified(Mock1Resource resource)
 => new ResourceEventV1 <Mock1Resource>
 {
     EventType = ResourceEventType.Modified, Resource = resource
 };