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); }
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); }
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); }
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); }
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); }
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"); }
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); }
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); } }
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); }
public void AlbumControllerEdit() { var albumController = new AlbumsController(null, null); var result = albumController.Edit(1); Assert.IsNotNull(result); }
public void AlbumsSearchedTest_SearchingAlbumThatDoesntExists() { AlbumsController controller = new AlbumsController(); var result = controller.AlbumsSearched("XXXXXXXXXXXXXXX") as ViewResult; var restultCastedToList = (List <Album>)result.Model; Assert.IsEmpty(restultCastedToList); }
public void AlbumControllerDeleteConfirmed() { var albumController = new AlbumsController(null, null); var result = albumController.DeleteConfirmed(1); Assert.IsNotNull(result); }
public void AlbumControllerIndexNotNull() { var albumController = new AlbumsController(null, null); var result = albumController.Index(1, "aaa", 1, 5); Assert.IsNotNull(result); }
public void AlbumControllerCreateNotNull() { var albumController = new AlbumsController(null, null); var result = albumController.Create(); Assert.IsNotNull(result); }
public void AlbumControllerReturnNull() { var albumController = new AlbumsController(null, null); var result = albumController.HttpContext; Assert.IsNull(result); }
public void AlbumControllerAlbumsAll() { var albumController = new AlbumsController(null, null); var result = albumController.AllAlbums(1, "aaa"); Assert.IsNotNull(result); }
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); }
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); }
public void Get_ReturnsNonNullResponse() { var mockClient = new Mock <ITypicodeClient>(); var controller = new AlbumsController(mockClient.Object); var result = controller.Get().GetAwaiter().GetResult(); result.Should().NotBeNull(); }
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); }
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(); }
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); }
public void IsIndexNotNull() { // Arrange AlbumsController controller = new AlbumsController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public void AlbumsCreateTest() { // Arrange AlbumsController controller2 = new AlbumsController(); // Act var result2 = controller2.Create(); // Assert Assert.IsNotNull(result2); }
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(); }
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; }