public async Task Get_AnySearchCriteria_ReturnOkResult()
        {
            _mockDiscogsRepository.Setup(r => r.GetCollectionAsync(It.IsAny <SearchCriteria>())).ReturnsAsync(() => new());

            var result = await _collectionController.Get(new SearchCriteriaDTO()) as ObjectResult;

            var actionResult = result.Should().BeOfType <OkObjectResult>().Subject;
        }
        public void Get()
        {
            // Act
            var collectionList = _collectionController.Get().ToList();

            // Assert
            Assert.IsNotNull(collectionList);
            Assert.AreEqual(4, collectionList.Count());
            Assert.IsTrue(collectionList.Contains(Collection1));
            Assert.IsTrue(collectionList.Contains(Collection2));
        }
        public async Task Get_ShouldReturnList()
        {
            // Arrange
            var controller = new CollectionController();

            // Act
            var actionResult = await controller.Get();

            var contentResult = actionResult as OkNegotiatedContentResult <List <Aggregate> >;
            var actual        = contentResult?.Content;

            // Assert
            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(actual);
            Assert.AreEqual(30, actual.Count());

            // make sure all 30 records contain valid objects
            Assert.IsTrue(actual.All(m => m.Album != null));
            Assert.IsTrue(actual.All(m => m.Post != null));
            Assert.IsTrue(actual.All(m => m.User != null));

            // make sure randomness has been applied
            Assert.AreNotEqual(30, actual.Count(m => m.Album.Id == actual.First().Album.Id));
            Assert.AreNotEqual(30, actual.Count(m => m.Post.Id == actual.First().Post.Id));
            Assert.AreNotEqual(30, actual.Count(m => m.User.Id == actual.First().User.Id));
        }
Exemplo n.º 4
0
        public void Collection()
        {
            ILogger <CollectionController> _testlogger = null;

            using (var context = new AppDbContext(options, null))
            {
                var controller = new CollectionController(context, _testlogger);

                // Get all
                var result = controller.Get();
                // Assert
                var okResult = Assert.IsAssignableFrom <IEnumerable <Collection> >(result);
                var pgcount  = okResult.ToList().Count;
                Assert.Equal(2, pgcount);
                // Get by ID
                var result1   = controller.Get(1);
                var okResult1 = Assert.IsAssignableFrom <Collection>(result1);
                //var thisresult1 = okResult1.FirstOrDefault();
                Assert.Equal("collection type 1", result1.CollectionName);

                // test update
                var pg1 = new Collection {
                    CollectionID = 1, CollectionName = "collection type 1 upd"
                };
                controller.UpdateEntry(pg1);
                var result3 = controller.Get(1);
                //var thisresult3 = result3.FirstOrDefault();
                Assert.NotEqual("collection type 1", result3.CollectionName);
                Assert.Equal("collection type 1 upd", result3.CollectionName);

                // test delete
                var result4 = controller.Get(2);
                //var thisresult4 = result4.FirstOrDefault();
                Assert.Equal("collection type 2", result4.CollectionName);

                IActionResult result5    = controller.Delete(2);
                var           viewResult = Assert.IsType <Microsoft.AspNetCore.Mvc.OkResult>(result5);
                var           result6    = controller.Get(2);
                Assert.Null(result6);
            }
        }