public void OwnerIdAndRepoIdReturnsListView()
        {
            var ownerId = "owner-1";
            var repoId  = "repo-1";

            var datasets = GetDummyDatasets(ownerId, repoId, 10);

            _mockDatasetsStore.Setup(m => m.GetDatasetsForRepositoryAsync("owner-1", "repo-1", It.IsAny <int>(), It.IsAny <int>()))
            .Returns(Task.FromResult <IEnumerable <DatasetInfo> >(datasets));

            var vc          = new DatasetsViewComponent(_mockDatasetsStore.Object, _uriService);
            var asyncResult = vc.InvokeAsync(ownerId, repoId);

            Assert.NotNull(asyncResult.Result);
            var result = asyncResult.Result as ViewViewComponentResult;

            Assert.NotNull(result);

            _mockDatasetsStore.Verify(m => m.GetDatasetsForRepositoryAsync(ownerId, repoId, 0, 20), Times.Once);

            var model = result.ViewData?.Model as List <DatasetViewModel>;

            Assert.NotNull(model);
            Assert.Equal(10, model.Count);

            Assert.Equal("Default", result.ViewName);
        }
        public void OwnerIdAndRepoIdNoDatasetsFoundReturnsEmptyListView()
        {
            var ownerId = "owner-1";
            var repoId  = "repo-1";

            _mockDatasetsStore.Setup(m =>
                                     m.GetDatasetsForRepositoryAsync(ownerId, repoId, It.IsAny <int>(), It.IsAny <int>()))
            .Throws(new DatasetNotFoundException($"No datasets found for owner '{ownerId}', repository: '{repoId}'"));

            var vc          = new DatasetsViewComponent(_mockDatasetsStore.Object, _uriService);
            var asyncResult = vc.InvokeAsync(ownerId, repoId);

            Assert.NotNull(asyncResult.Result);
            var result = asyncResult.Result as ViewViewComponentResult;

            Assert.NotNull(result);

            _mockDatasetsStore.Verify(m => m.GetDatasetsForRepositoryAsync(ownerId, repoId, 0, 20), Times.Once);

            var model = result.ViewData?.Model as List <DatasetViewModel>;

            Assert.NotNull(model);
            Assert.Empty(model);
            Assert.Equal("Default", result.ViewName);
        }
        public void NoOwnerIdReturnsEmptyView()
        {
            var vc          = new DatasetsViewComponent(_mockDatasetsStore.Object, _uriService);
            var asyncResult = vc.InvokeAsync(string.Empty, string.Empty);

            Assert.NotNull(asyncResult.Result);
            var result = asyncResult.Result as ViewViewComponentResult;

            Assert.NotNull(result);
            Assert.Equal("Empty", result.ViewName);
        }
        public void ExceptionsDisplaysErrorView()
        {
            var ownerId = "owner-1";
            var repoId  = "repo-1";

            _mockDatasetsStore.Setup(m =>
                                     m.GetDatasetsForRepositoryAsync(ownerId, repoId, It.IsAny <int>(), It.IsAny <int>()))
            .Throws(new NullReferenceException("OOPS!"));

            var vc          = new DatasetsViewComponent(_mockDatasetsStore.Object, _uriService);
            var asyncResult = vc.InvokeAsync(ownerId, repoId);

            Assert.NotNull(asyncResult.Result);
            var result = asyncResult.Result as ViewViewComponentResult;

            Assert.NotNull(result);

            _mockDatasetsStore.Verify(m => m.GetDatasetsForRepositoryAsync(ownerId, repoId, 0, 20), Times.Once);
            Assert.Equal("Error", result.ViewName);
        }