Esempio n. 1
0
        public void AlbumsIndexTest()
        {
            AlbumsController controller = new AlbumsController(new StagingMusicsRepository());

            // Act
            ViewResult result = controller.Index("", "", "", 0) as ViewResult;

            PagedList.PagedList <Album> model = (PagedList.PagedList <Album>)result.ViewData.Model;
            // Act


            // Assert
            Assert.IsNotNull(result);
            //  Assert.IsTrue(model.Count() == 2);

            //Route
            //Assert.AreEqual("Index", result.RouteValues["action"]);
            //Assert.AreEqual("SomeElse", result.["controller"]);

            ///Search Test
            // Act
            result = controller.Index("", "", "The Best", 0) as ViewResult;
            model  = (PagedList.PagedList <Album>)result.ViewData.Model;
            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(model.TotalItemCount == 1);
        }
Esempio n. 2
0
        public void TestInitialize()
        {
            //creates a new mock-data object to holf fafe data //
            mock = new Mock <IAlbumsMock> ();

            //populate mock list/
            albums = new List <Album>
            {
                new Album {
                    AlbumId = 100, Title = "Test 1 ", Price = 6.99m, Artist = new Artist {
                        ArtistId = 1000, Name = "Singer 1"
                    }
                },
                new Album {
                    AlbumId = 101, Title = "Test 2 ", Price = 7.99m, Artist = new Artist {
                        ArtistId = 1007, Name = "Singer 2"
                    }
                }
            };

            //pass mock lst to albums controller//
            //albums.OrderBy(a => a.Artist.Name).ThenBy(a => a.Title);

            mock.Setup(m => m.Albums).Returns(albums.AsQueryable());
            controller = new AlbumsController(mock.Object);
        }
 public AlbumsControllerTests()
 {
     _service = new Mock <IAlbumService>();
     _service.Setup(x => x.GetAllAsync()).ReturnsAsync(GetTestAlbums());
     _service.Setup(x => x.GetAllAsync()).ReturnsAsync(GetTestAlbums());
     _controller = new AlbumsController(_service.Object);
 }
        public void TestInitialize()
        {
            // this method runs automatically before each individual test

            // create a new mock data object to hold a fake list of albums
            mock = new Mock <IAlbumsMock>();

            // populate mock list
            albums = new List <Album>
            {
                new Album {
                    AlbumId = 100, Title = "One Hundred", Price = 6.99m, Artist = new Artist {
                        ArtistId = 1000, Name = "Singer One"
                    }
                },

                new Album {
                    AlbumId = 300, Title = "Three Hundred", Price = 8.99m, Artist = new Artist {
                        ArtistId = 1001, Name = "Singer Two"
                    }
                },

                new Album {
                    AlbumId = 200, Title = "Two Hundred", Price = 7.99m, Artist = new Artist {
                        ArtistId = 1001, Name = "Singer Two"
                    }
                }
            };

            // put list into mock object and pass it to the albums controller
            // albums.OrderBy(a => a.Artist.Name).ThenBy(a => a.Title);

            mock.Setup(m => m.Albums).Returns(albums.AsQueryable());
            controller = new AlbumsController(mock.Object);
        }
Esempio n. 5
0
        public void Get_ReturnsAlbumsAndPhotosCombined()
        {
            // setup
            var mockClient = new Mock <ITypicodeClient>();

            mockClient.Setup(client => client.GetAlbumsAsync()).Returns(Task.FromResult(GetMockAlbums()));
            mockClient.Setup(client => client.GetPhotosAsync()).Returns(Task.FromResult(GetMockPhotos()));

            var controller = new AlbumsController(mockClient.Object);

            // act
            var actionResult  = controller.Get().GetAwaiter().GetResult();
            var contentResult = actionResult as OkNegotiatedContentResult <List <Album> >;

            // assert
            contentResult.Should().NotBeNull();
            var albums = contentResult.Content as List <Album>;

            albums.Should().NotBeNull();
            albums.Count.Should().Be(2);
            albums[0].Photos.Should().NotBeNull();
            albums[0].Photos.Count().Should().Be(2);
            albums[1].Photos.Should().NotBeNull();
            albums[1].Photos.Count().Should().Be(3);
        }
Esempio n. 6
0
        internal void Setup()
        {
            _mapper = MapperConfiguration();

            getAllAlbumsByFilterResponse            = new GetAllAlbumsByFilterResponse();
            getAllAlbumsByFilterResponse.ListAlbums = new List <AlbumsApp> {
                new AlbumsApp
                {
                    Artist = "artist",
                    Id     = 1,
                    Label  = "label",
                    Name   = "name",
                    Stock  = 1
                },
                new AlbumsApp
                {
                    Artist = "artist 2",
                    Id     = 2,
                    Label  = "label 2",
                    Name   = "name 2",
                    Stock  = 1
                }
            };

            albumAppServiceMock = new Mock <IAlbumsAppService>();


            controller = new AlbumsController(albumAppServiceMock.Object, _mapper);
        }
        public void TestInitialize()
        {
            //arrange mock data for all unit tests
            mock = new Mock <IAlbumsMock>();

            albums = new List <Album>
            {
                new Album {
                    AlbumId = 100, Title = "One Hundred", Price = 6.99m, Artist = new Artist {
                        ArtistId = 4000, Name = "Some One"
                    }
                },
                new Album {
                    AlbumId = 200, Title = "Two Hundred", Price = 7.99m, Artist = new Artist {
                        ArtistId = 4000, Name = "Eminem"
                    }
                },
                new Album {
                    AlbumId = 300, Title = "Three Hundred", Price = 8.99m, Artist = new Artist {
                        ArtistId = 4000, Name = "Drake"
                    }
                }
            };

            //populate interface from the mock data
            mock.Setup(m => m.Albums).Returns(albums.AsQueryable());

            albumsController = new AlbumsController(mock.Object);
        }
Esempio n. 8
0
        public static AlbumsController GetAlbumsController(IRepository <Album> albums, IRepository <User> users, IRepository <Photo> photos, bool validUser = true)
        {
            var controller = new AlbumsController(albums, users, photos);

            SetUser(controller, validUser);
            return(controller);
        }
Esempio n. 9
0
        public void Get_ReturnsAlbumsAndPhotosAllAttributesPopulated()
        {
            // setup
            var mockClient = new Mock <ITypicodeClient>();

            mockClient.Setup(client => client.GetAlbumsAsync()).Returns(Task.FromResult(GetMockAlbums()));
            mockClient.Setup(client => client.GetPhotosAsync()).Returns(Task.FromResult(GetMockPhotos()));
            var controller = new AlbumsController(mockClient.Object);

            // act
            var actionResult  = controller.Get().GetAwaiter().GetResult();
            var contentResult = actionResult as OkNegotiatedContentResult <List <Album> >;

            // assert
            contentResult.Should().NotBeNull();
            var albums = contentResult.Content as List <Album>;

            albums.Should().NotBeNull();
            albums.Count.Should().Be(2);
            albums[0].Id.Should().Be(1);
            albums[0].Title.Should().Be("Album1");
            albums[0].UserId.Should().Be(1);
            albums[0].Photos.Count().Should().Be(2);
            albums[0].Photos[0].Id.Should().Be(1);
            //albums[0].Photos[0].AlbumId.Should().Be(1); // get accessor is internal - property won't be serialized
            albums[0].Photos[0].Title.Should().Be("Photo1");
            albums[0].Photos[0].Url.Should().Be("http://photo1");
            albums[0].Photos[0].ThumbnailUrl.Should().Be("http://thumb1");
        }
Esempio n. 10
0
        public async Task TestAlbumsListAsync()
        {
            List <AlbumDTO> testAlbums = new List <AlbumDTO>
            {
                new AlbumDTO()
                {
                    Id = 1, Title = "TitleTest1"
                },
                new AlbumDTO()
                {
                    Id = 2, Title = "TitleTest2"
                },
            };

            var mockService = new Mock <IAlbumService>();

            mockService.Setup(repo => repo.GetAllAlbums()).Returns(Task.FromResult(testAlbums));

            var mockPhotoService = new Mock <IPhotosService>();

            var controller = new AlbumsController(mockService.Object, mockPhotoService.Object);
            var result     = await controller.Index();

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            CollectionAssert.AllItemsAreNotNull((ICollection)((ViewResult)result).Model);
        }
Esempio n. 11
0
        public async Task DeleteAlbum()
        {
            // Arrange
            var seedIds = new List <int> {
                new Random().Next(1, 50), new Random().Next(51, 100)
            };
            string            expectedUserName  = string.Format("test_{0}@gmail.com", Guid.NewGuid());
            ControllerContext controllerContext = Utilities.SetupCurrentUserForController(expectedUserName);
            var    seedAlbums          = SeedAlbums(seedIds, expectedUserName);
            string seed                = Guid.NewGuid().ToString();
            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;
                mockAlbumRepository.Setup(m => m.GetAsync(id, true)).ReturnsAsync(seedAlbum);
                // Act
                var result = await controller.DeleteAlbum(id);

                // Assert
                Assert.IsType <OkResult>(result);
                mockAlbumRepository.Verify(m => m.Delete(seedAlbum), Times.Once);
            }
        }
Esempio n. 12
0
        public async Task GetAlbums()
        {
            // Arrange
            var               seedAlbums         = SeedAlbums();
            var               seedAlbumResources = this._mapper.Map <IEnumerable <Album>, IEnumerable <AlbumResource> >(seedAlbums);
            string            seed                = Guid.NewGuid().ToString();
            string            expectedUserName    = string.Format("test_{0}@gmail.com", seed);
            ControllerContext controllerContext   = Utilities.SetupCurrentUserForController(expectedUserName);
            var               mockAlbumRepository = new Mock <IAlbumRepository>();

            mockAlbumRepository.Setup(m => m.GetAlbums(It.IsAny <AlbumQuery>())).ReturnsAsync(seedAlbums);
            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;
            var filterResource = new AlbumQueryResource();
            // Act
            var albums = await controller.GetAlbums(filterResource);

            // Assert
            Assert.True(seedAlbumResources.SequenceEqual(albums));
        }
        public void Get_ShouldReturnTheCompleteListOfAlbums()
        {
            var albumList = new List <Album>
            {
                new Album()
                {
                    Title         = "t1",
                    CoverHttpPath = "c1"
                },

                new Album()
                {
                    Title         = "t2",
                    CoverHttpPath = "c2"
                }
            };


            _mockRepository.Setup(x => x.GetAll()).Returns(albumList);

            var controller = new AlbumsController(_mockRepository.Object);

            var albumsResult = controller.Get();

            Assert.AreEqual(albumList, albumsResult.Value);
        }
Esempio n. 14
0
        public void AlbumControllerEdit()
        {
            var albumController = new AlbumsController(null, null);

            var result = albumController.Edit(1);

            Assert.IsNotNull(result);
        }
Esempio n. 15
0
        public void AlbumsSearchedTest_SearchingAlbumThatDoesntExists()
        {
            AlbumsController controller = new AlbumsController();
            var result = controller.AlbumsSearched("XXXXXXXXXXXXXXX") as ViewResult;
            var restultCastedToList = (List <Album>)result.Model;

            Assert.IsEmpty(restultCastedToList);
        }
Esempio n. 16
0
        public void AlbumControllerDeleteConfirmed()
        {
            var albumController = new AlbumsController(null, null);

            var result = albumController.DeleteConfirmed(1);

            Assert.IsNotNull(result);
        }
Esempio n. 17
0
        public void AlbumControllerIndexNotNull()
        {
            var albumController = new AlbumsController(null, null);

            var result = albumController.Index(1, "aaa", 1, 5);

            Assert.IsNotNull(result);
        }
Esempio n. 18
0
        public void AlbumControllerCreateNotNull()
        {
            var albumController = new AlbumsController(null, null);

            var result = albumController.Create();

            Assert.IsNotNull(result);
        }
Esempio n. 19
0
        public void AlbumControllerReturnNull()
        {
            var albumController = new AlbumsController(null, null);

            var result = albumController.HttpContext;

            Assert.IsNull(result);
        }
Esempio n. 20
0
        public void AlbumControllerAlbumsAll()
        {
            var albumController = new AlbumsController(null, null);

            var result = albumController.AllAlbums(1, "aaa");

            Assert.IsNotNull(result);
        }
Esempio n. 21
0
        public void OneTimeSetup()
        {
            var profile       = new AlbumsProfile();
            var configuration = new MapperConfiguration(cfg => cfg.AddProfile(profile));
            var realMapper    = new Mapper(configuration);

            _service = new Mock <IAlbumService>();
            _sut     = new AlbumsController(_service.Object, realMapper);
        }
Esempio n. 22
0
        public void IsAlbumsSerchedInstanceOfList()
        {
            AlbumsController controller = new AlbumsController();
            ViewResult       result     = controller.AlbumsSearched("Rap") as ViewResult;
            var xd  = (List <Album>)result.Model;
            var xd1 = xd[0];

            Assert.IsInstanceOf(typeof(List <Album>), result.Model);
        }
Esempio n. 23
0
        public void Get_ReturnsNonNullResponse()
        {
            var mockClient = new Mock <ITypicodeClient>();
            var controller = new AlbumsController(mockClient.Object);

            var result = controller.Get().GetAwaiter().GetResult();

            result.Should().NotBeNull();
        }
Esempio n. 24
0
        public void InitializeAlbumsConttrollerCorrectly_WhenDependenciesAreNotNull()
        {
            var mapperMock       = new Mock <IMapper>();
            var albumServiceMock = new Mock <IAlbumService>();

            var controller = new AlbumsController(albumServiceMock.Object, mapperMock.Object);

            Assert.IsNotNull(controller);
        }
Esempio n. 25
0
        public void GetByUserId_UserIdNotValid_ReturnsBadRequest()
        {
            var mockClient = new Mock <ITypicodeClient>();
            var controller = new AlbumsController(mockClient.Object);

            var actionResult  = controller.Get(0).GetAwaiter().GetResult();
            var contentResult = actionResult as BadRequestErrorMessageResult;

            contentResult.Should().NotBeNull();
        }
Esempio n. 26
0
        public AlbumsControllerTest()
        {
            _albumService = new AlbumFakeService();
            _photoService = new PhotoFakeService();

            var mock = new Mock <ILogger <AlbumsController> >();
            ILogger <AlbumsController> logger = mock.Object;


            _controller = new AlbumsController(logger, _photoService, _albumService);
        }
Esempio n. 27
0
        public void IsIndexNotNull()
        {
            // Arrange
            AlbumsController controller = new AlbumsController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Esempio n. 28
0
        public void AlbumsCreateTest()
        {
            // Arrange
            AlbumsController controller2 = new AlbumsController();

            // Act
            var result2 = controller2.Create();

            // Assert
            Assert.IsNotNull(result2);
        }
Esempio n. 29
0
        public void Get_NoAlbumsFound_ReturnsInternalServerError()
        {
            var mockClient = new Mock <ITypicodeClient>();

            mockClient.Setup(client => client.GetAlbumsAsync()).Returns(Task.FromResult <List <Album> >(null));
            var controller = new AlbumsController(mockClient.Object);

            var actionResult  = controller.Get().GetAwaiter().GetResult();
            var contentResult = actionResult as ExceptionResult;

            contentResult.Should().NotBeNull();
        }
Esempio n. 30
0
        public void Get_AlbumsFound_ReturnsSuccessResponse()
        {
            var mockClient = new Mock <ITypicodeClient>();

            mockClient.Setup(client => client.GetAlbumsAsync()).Returns(Task.FromResult(new List <Album>()));
            var controller = new AlbumsController(mockClient.Object);

            var actionResult  = controller.Get().GetAwaiter().GetResult();
            var contentResult = actionResult as OkNegotiatedContentResult <List <Album> >;

            contentResult.Should().NotBeNull();
        }
 public static AlbumsController GetAlbumsController(IRepository<Album> albums, IRepository<User> users, IRepository<Photo> photos, bool validUser = true)
 {
     var controller = new AlbumsController(albums, users, photos);
     SetUser(controller, validUser);
     return controller;
 }