public void Get_Returns_3_Albums()
        {
            //Arrange
            var myCollection = new List <Album>()
            {
                new Album(1, "First Album", "columbia records", "img", 1, "Here is a comment", 5),
                new Album(2, "Second Album", "columbia records", "img", 1, "Here is a comment", 5),
                new Album(3, "Third Album", "columbia records", "img", 1, "Here is a comment", 5)
            };

            albumRepo.GetAll().Returns(myCollection);

            //Act
            var result        = underTest.GetAlbum();
            var countOfAlbums = result.Count();

            //Assert
            Assert.Equal(3, countOfAlbums);
        }
示例#2
0
        public void TestGetAlbumById()
        {
            //Arranging
            FakeAlbumBL      fake       = new FakeAlbumBL();
            AlbumsController controller = new AlbumsController(fake);
            int id = 1;

            //Act
            var result = controller.GetAlbum(id) as OkNegotiatedContentResult <Album>;


            //Assert
            Assert.AreEqual(id, result.Content.AlbumId);
            Assert.AreEqual("album 1", result.Content.Title);
        }
示例#3
0
        public async Task GetPhoto()
        {
            // Arrange
            var seedIds = new List <int> {
                new Random().Next(1, 50),
                new Random().Next(51, 100),
                new Random().Next(101, 150),
                new Random().Next(151, 200)
            };
            var               seedAlbums          = SeedAlbums(seedIds);
            string            seed                = Guid.NewGuid().ToString();
            string            expectedUserName    = string.Format("test_{0}@gmail.com", seed);
            ControllerContext controllerContext   = Utilities.SetupCurrentUserForController(expectedUserName);
            var               mockAlbumRepository = new Mock <IAlbumRepository>();
            var               mockUserRepository  = new Mock <IUserRepository>();
            User              expectedUser        = new User()
            {
                Id       = seed,
                UserName = expectedUserName
            };

            mockUserRepository.Setup(m => m.GetOrAdd(It.IsAny <User>())).Returns(expectedUser);
            var mockUnitOfWork          = new Mock <IUnitOfWork>();
            AlbumsController controller = new AlbumsController(this._mapper, mockAlbumRepository.Object, mockUserRepository.Object, mockUnitOfWork.Object);

            controller.ControllerContext = controllerContext;
            foreach (var seedAlbum in seedAlbums)
            {
                var id = seedAlbum.Id;
                var seedAlbumResource = this._mapper.Map <Album, AlbumResource>(seedAlbum);
                mockAlbumRepository.Setup(m => m.GetAsync(id, true)).ReturnsAsync(seedAlbum);
                // Act
                var result = await controller.GetAlbum(id);

                // Assert
                Assert.IsType <OkObjectResult>(result);
                Assert.IsType <AlbumResource>(((OkObjectResult)result).Value);
                AlbumResource returnedAlbumResource = (AlbumResource)((OkObjectResult)result).Value;
                Assert.True(returnedAlbumResource.Equals(seedAlbumResource));
            }
        }