Exemple #1
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"));
        }
        /// <summary>
        /// Khởi tạo một controller dùng trong kiểm thử
        /// </summary>
        /// <typeparam name="TController"></typeparam>
        /// <param name="ctor"></param>
        /// <param name="formValues"></param>
        /// <param name="store"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static TController GetWiredUpController <TController>(Func <FakeDataStore, TController> ctor, FormCollection formValues = null, FakeDataStore store = null, FakeUser user = null) where TController : MVCMusicStore.Controllers.ControllerBase
        {
            store = store ?? MusicStoreEntitiesFactory.GetEmpty();
            TController           controller = ctor(store);
            TestControllerBuilder _builder   = new TestControllerBuilder();

            _builder.HttpContext.User = user ?? new FakeUser();
            _builder.InitializeController(controller);
            if (formValues != null)
            {
                controller.ValueProvider = formValues.ToValueProvider();
            }
            return(controller);
        }
Exemple #3
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"));
        }
Exemple #4
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"));
        }
Exemple #5
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"));
        }