public void TestInitialize()
        {
            // arrange
            mock = new Mock <IStoreManagerRepository>();

            // mock Album data
            albums = new List <Album>
            {
                new Album {
                    AlbumId = 1, Title = "Album 1", Price = 8,
                    Artist  = new Artist {
                        ArtistId = 1, Name = "Artist 1"
                    }
                },
                new Album {
                    AlbumId = 2, Title = "Album 2", Price = 10,
                    Artist  = new Artist {
                        ArtistId = 2, Name = "Artist 2"
                    }
                },
                new Album {
                    AlbumId = 3, Title = "Album 3", Price = 9,
                    Artist  = new Artist {
                        ArtistId = 3, Name = "Artist 3"
                    }
                }
            };

            // add Album data to the mock object
            mock.Setup(m => m.Albums).Returns(albums.AsQueryable());

            // pass the mock to the controller
            controller = new StoreManagerController(mock.Object);
        }
        public void Details_NotFound()
        {
            StoreManagerController controller = new StoreManagerController();
            ViewResult             result     = controller.Details(999) as ViewResult;

            Assert.IsNull(result);
        }
示例#3
0
        public void DetailsPass()
        {
            // Arrange
            Mock <IStoreManagerRepository> mock       = new Mock <IStoreManagerRepository>();
            Mock <IArtistRepository>       artistMock = new Mock <IArtistRepository>();
            Mock <IGenreRepository>        genreMock  = new Mock <IGenreRepository>();

            Album album = new Album
            {
                AlbumId = 1, Title = "Album 1", Price = 9
            };

            mock.Setup(m => m.Get(1)).Returns(album);

            // move this to setup so mock data can be used by all tests
            //mock.Setup(m => m.Albums).Returns(new Album[]
            //{
            //    new Album { AlbumId = 1, Title = "Album 1", Price = 9 },
            //    new Album { AlbumId = 2, Title = "Album 2", Price = 10 },
            //    new Album { AlbumId = 2, Title = "Album 3", Price = 8 }
            //}.AsQueryable());

            StoreManagerController controller = new StoreManagerController(mock.Object);

            // Act
            Album actual = (Album)controller.Details(1).Model;

            // Assert
            Assert.AreEqual(album, actual);
        }
        public void TestInitialize()
        {
            // instantiate mock
            mock       = new Mock <IStoreManagerRepository>();
            artistMock = new Mock <IArtistRepository>();
            genreMock  = new Mock <IGenreRepository>();

            // mock data
            albums = new List <Album>
            {
                new Album {
                    AlbumId = 1, Title = "Album 1", Price = 9
                },
                new Album {
                    AlbumId = 2, Title = "Album 2", Price = 10
                },
                new Album {
                    AlbumId = 3, Title = "Album 3", Price = 8
                }
            };

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

            // pass repo with data to controller
            controller = new StoreManagerController(mock.Object);
        }
示例#5
0
        public void TestInitialize()
        {
            // Arrange
            mock = new Mock <IStoreManagerRepository>();

            // Mock the Album Data
            albums = new List <Album>
            {
                new Album {
                    AlbumId = 1, Title = "Album 1", Price = 9, Artist = new Artist {
                        ArtistId = 1, Name = "Artist 1"
                    }
                },
                new Album {
                    AlbumId = 2, Title = "Album 2", Price = 10, Artist = new Artist {
                        ArtistId = 2, Name = "Artist 2"
                    }
                },
                new Album {
                    AlbumId = 3, Title = "Album 3", Price = 9, Artist = new Artist {
                        ArtistId = 3, Name = "Artist 3"
                    }
                }
            };

            // populate the mock object with our sample data
            mock.Setup(m => m.Albums).Returns(albums.AsQueryable());

            // Pass the mock to 2nd constructor
            controller = new StoreManagerController(mock.Object);
        }
示例#6
0
        public void IndexFails()
        {
            Mock <IStoreManagerRepository> mock       = new Mock <IStoreManagerRepository>();
            StoreManagerController         controller = new StoreManagerController(mock.Object);

            ViewResult result = controller.Index() as ViewResult;

            Assert.IsNotNull(result);
        }
        public void Details_Found()
        {
            // Arrange
            StoreManagerController controller = new StoreManagerController();

            // Act
            ViewResult result = controller.Details(388) as ViewResult;

            // Assert
            Assert.IsNotNull(result, "Details Passed");
        }
        public void Index()
        {
            // Arrange
            StoreManagerController controller = new StoreManagerController();

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

            // Assert
            Assert.IsNotNull(result);
        }
示例#9
0
        public void Edit_Miss_Required_Album()
        {
            FakeDataStore dataStore = MusicStoreEntitiesFactory.GetEmpty();

            dataStore.GenerateAndAddGenre(1);
            dataStore.GenerateAndAddArtist(10);
            Album test = dataStore.GenerateAndAddAlbum(100, 10, 1, 19.99M);
            StoreManagerController controller = ControllerFactory.GetWiredUpController((s) => new StoreManagerController(s), store: dataStore);

            test.Title = null;
            RedirectToRouteResult result = controller.Edit(test) as RedirectToRouteResult;

            Assert.IsTrue(result.RouteValues.ContainsValue("InvalidRequest"));
        }
示例#10
0
        public void Delete()
        {
            createTestObject();

            // Arrange
            StoreManagerController controller = new StoreManagerController();

            // Act
            ViewResult result = controller.Delete(beanBag.id) as ViewResult;

            // Assert
            Assert.IsNotNull(result);

            deleteTestObject(beanBag.id);
        }
示例#11
0
        public void Edit_Valid_Album()
        {
            FakeDataStore dataStore = MusicStoreEntitiesFactory.GetEmpty();

            dataStore.GenerateAndAddGenre(1, "Nhe nhang");
            dataStore.GenerateAndAddArtist(10);
            // Generate a new album before updating
            Album test = dataStore.GenerateAndAddAlbum(100, 10, 1, 19.99M);
            StoreManagerController controller = ControllerFactory.GetWiredUpController((s) => new StoreManagerController(s), store: dataStore);

            test.Title = "Tình khúc vượt thời gian";
            test.Price = 10M;
            RedirectToRouteResult result = controller.Edit(test) as RedirectToRouteResult;

            Assert.IsTrue(result.RouteValues.ContainsValue("Index"));
        }
示例#12
0
        public void Create_Miss_Required_Album()
        {
            FakeDataStore dataStore = MusicStoreEntitiesFactory.GetEmpty();

            dataStore.GenerateAndAddGenre(1);
            dataStore.GenerateAndAddArtist(10);
            StoreManagerController controller = ControllerFactory.GetWiredUpController((s) => new StoreManagerController(s), store: dataStore);
            Album album = new Album {
                Genre = new Genre {
                    Name = "Rock"
                }, Artist = new Artist {
                    Name = "Men At Work"
                },
                AlbumArtUrl = "/Content/Images/placeholder.gif"
            };
            RedirectToRouteResult result = controller.Create(album) as RedirectToRouteResult;

            Assert.IsTrue(result.RouteValues.ContainsValue("InvalidRequest"));
        }
示例#13
0
        public void Edit_NotExsiting_Album()
        {
            FakeDataStore dataStore = MusicStoreEntitiesFactory.GetEmpty();

            dataStore.GenerateAndAddGenre(1);
            dataStore.GenerateAndAddArtist(10);
            StoreManagerController controller = ControllerFactory.GetWiredUpController((s) => new StoreManagerController(s), store: dataStore);
            Album album = new Album {
                Title = "Tình khúc vượt thời gian", Genre = new Genre {
                    Name = "Rock"
                },
                Price = 10M, Artist = new Artist {
                    Name = "Men At Work"
                }, AlbumArtUrl = "/Content/Images/placeholder.gif"
            };
            RedirectToRouteResult result = controller.Edit(album) as RedirectToRouteResult;

            Assert.IsTrue(result.RouteValues.ContainsValue("InvalidRequest"));
        }
示例#14
0
        public void IndexPass()
        {
            // Arrange
            Mock <IStoreManagerRepository> mock       = new Mock <IStoreManagerRepository>();
            Mock <IArtistRepository>       artistMock = new Mock <IArtistRepository>();
            Mock <IGenreRepository>        genreMock  = new Mock <IGenreRepository>();

            List <Album> albums = new List <Album>
            {
                new Album {
                    AlbumId = 1, Title = "Album 1", Price = 9
                },
                new Album {
                    AlbumId = 2, Title = "Album 2", Price = 10
                },
                new Album {
                    AlbumId = 2, Title = "Album 3", Price = 8
                }
            };

            mock.Setup(m => m.Albums).Returns(albums.AsQueryable());

            // move this to setup so mock data can be used by all tests
            //mock.Setup(m => m.Albums).Returns(new Album[]
            //{
            //    new Album { AlbumId = 1, Title = "Album 1", Price = 9 },
            //    new Album { AlbumId = 2, Title = "Album 2", Price = 10 },
            //    new Album { AlbumId = 2, Title = "Album 3", Price = 8 }
            //}.AsQueryable());

            StoreManagerController controller = new StoreManagerController(mock.Object);

            // Act
            var actual = (List <Album>)controller.Index().Model;

            // Assert

            CollectionAssert.AreEqual(albums, actual);

            //Assert.IsInstanceOfType(actual, List<Album>);
        }