public async void Get_ShallReturnAllClaraAets()
        {
            var data = new List <SourceApplicationEntity>();

            for (int i = 1; i <= 5; i++)
            {
                data.Add(new SourceApplicationEntity()
                {
                    AeTitle = $"AET{i}",
                    HostIp  = "host"
                });
            }

            _repository.Setup(p => p.ToListAsync()).Returns(Task.FromResult(data));

            var result = await _controller.Get();

            Assert.Equal(data.Count, result.Value.Count());
            _repository.Verify(p => p.ToListAsync(), Times.Once());
        }
Esempio n. 2
0
        public async void Get_ShallReturnAvailableCrds()
        {
            var claraAeTitles = new SourceApplicationEntityCustomResourceList
            {
                Items = new List <SourceApplicationEntityCustomResource>
                {
                    new SourceApplicationEntityCustomResource
                    {
                        Spec = new SourceApplicationEntity
                        {
                            AeTitle = "AETITLE",
                            HostIp  = "localhost"
                        },
                        Status = new AeTitleStatus {
                            Enabled = true
                        },
                        Metadata = new V1ObjectMeta {
                            ResourceVersion = "1", Name = "AETITLE"
                        }
                    }
                }
            };

            _kubernetesClient.Setup(p => p.ListNamespacedCustomObjectWithHttpMessagesAsync(CustomResourceDefinition.SourceAeTitleCrd))
            .Returns(Task.FromResult(new HttpOperationResponse <object>
            {
                Body     = new object(),
                Response = new HttpResponseMessage {
                    Content = new StringContent(JsonConvert.SerializeObject(claraAeTitles))
                }
            }));

            var result = await _controller.Get();

            _kubernetesClient.Verify(p => p.ListNamespacedCustomObjectWithHttpMessagesAsync(CustomResourceDefinition.SourceAeTitleCrd), Times.Once());

            var data = JsonConvert.DeserializeObject <SourceApplicationEntityCustomResourceList>((result.Result as ContentResult).Content);

            Assert.Equal(1, data.Items.Count);

            foreach (var item in claraAeTitles.Items)
            {
                var actualItem = data.Items.FirstOrDefault(p => p.Spec.AeTitle.Equals(item.Spec.AeTitle));
                Assert.NotNull(actualItem);
                Assert.Equal(item.Spec.AeTitle, actualItem.Spec.AeTitle);
                Assert.Equal(item.Spec.HostIp, actualItem.Spec.HostIp);
            }
        }