public void CallGetAllAndReturnExistResultIfAlreadyExists() { //Arrange List <Genres> genres = new List <Genres>(); var genre = new Genres { Name = "name1" }; var genre2 = new Genres { Name = "name2" }; genres.Add(genre); genres.Add(genre2); genresRepo.Setup(x => x.All()).Returns(genres.AsQueryable()); var sut = new GenreService(movies.Object, genresRepo.Object, commentsRepo.Object, userRepo.Object, likesRepo.Object, dislikesRepo.Object, saver.Object); //Act var result = sut.AddGenre(genre); //Assert Assert.AreEqual(result.ErrorMsg, "Already Exists"); Assert.AreEqual(result.ResulType, ResultType.AlreadyExists); }
void AddGenre() { try { Genre g = new Genre(); Console.Write("Enter Name => "); g.Name = Console.ReadLine(); int res = genreService.AddGenre(g); if (res > 0) { Console.WriteLine("Genre added successfully"); } else { Console.WriteLine("Some error occurs"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void ThrowArgumentNullException_WhenPassedGenreIsNull() { // Arrange var genreRepositoryMock = new Mock <IRepository <Genre> >(); var genreService = new GenreService(genreRepositoryMock.Object); // Act && Assert Assert.Throws <ArgumentNullException>(() => genreService.AddGenre(null)); }
public void CallUnitOfWorkCommit_WhenInvoked() { var repositoryMock = new Mock <IEfRepository <Genre> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); var datetimeMock = new Mock <IDateTimeProvider>(); var service = new GenreService(repositoryMock.Object, unitOfWorkMock.Object, datetimeMock.Object); string name = "Rock"; //Genre genre = new Genre(name); service.AddGenre(name); unitOfWorkMock.Verify(s => s.Commit(), Times.Once); }
void AddGenre() { Genre g = new Genre(); Console.Write(" Enter Genre Name = "); g.Name = Console.ReadLine(); if (genreService.AddGenre(g) > 0) { Console.WriteLine("Genre added successfully"); } else { Console.WriteLine("Some error has occurred"); } }
public void ThrowInvalidOperationException_WhenPassedGenreExists() { // Arrange var genreMock = new Mock <Genre>(); var genreRepositoryMock = new Mock <IRepository <Genre> >(); var genreService = new GenreService(genreRepositoryMock.Object); ICollection <Genre> filteredGenres = new List <Genre>(); filteredGenres.Add(genreMock.Object); genreRepositoryMock.Setup(gr => gr.GetAllFiltered(It.IsAny <Expression <Func <Genre, bool> > >())) .Returns(filteredGenres); // Act && Assert Assert.Throws <InvalidOperationException>(() => genreService.AddGenre(genreMock.Object)); }
public void AddGenreTest() { int expectedCount = 4; Genre genre = new Genre() { id = 4, name = "Trance" }; GenreService service = new GenreService(_genreRepository); service.AddGenre(genre); List <Genre> genres = service.GetAllGenres(); Assert.AreEqual(expectedCount, genres.Count); }
public void CallAddMethodOfRepositoryOnce_WhenPassedGenreDoesNotExists() { // Arrange var genreMock = new Mock <Genre>(); var genreRepositoryMock = new Mock <IRepository <Genre> >(); var genreService = new GenreService(genreRepositoryMock.Object); IEnumerable <Genre> filteredGenres = new List <Genre>(); genreRepositoryMock.Setup(gr => gr.GetAllFiltered(It.IsAny <Expression <Func <Genre, bool> > >())) .Returns(filteredGenres); // Act genreService.AddGenre(genreMock.Object); // Assert genreRepositoryMock.Verify(gr => gr.Add(genreMock.Object), Times.Once); }
public ActionResult Create([Bind(Include = "Id,Title,YearOfMeaning,Description")] Genre genre) { var genreVM = new GenreViewModel { Id = genre.Id, Title = genre.Title, YearOfMeaning = genre.YearOfMeaning, Description = genre.Description }; if (ModelState.IsValid) { ss.AddGenre(genre); return(RedirectToAction("Index")); } return(View(genreVM)); }
public void DoNotAddGenreIfItExistsAlready() { // Arrange IGenreService genreService = new GenreService(movies, genresRepo, commentsRepo, userRepo, likesRepo, dislikesRepo, saver); var genreToAdd = new Genres() { Name = "Action", IsDeleted = false }; // Act genreService.AddGenre(genreToAdd); var result = context.Genres.Where(x => x.Name.ToLower() == genreToAdd.Name.ToLower()).ToList(); //Assert Assert.AreEqual(result.Count, 1); Assert.AreEqual(genreToAdd.Name, result[0].Name); }
public void AddGenreToDataBaseIfNoModleWithSameNameExists() { // Arrange IGenreService genreService = new GenreService(movies, genresRepo, commentsRepo, userRepo, likesRepo, dislikesRepo, saver); var genreToAdd = new Genres() { Name = "genreToAdd", IsDeleted = false }; // Act genreService.AddGenre(genreToAdd); var result = context.Genres.Where(x => x.Name.ToLower() == genreToAdd.Name.ToLower()).FirstOrDefault(); //Assert Assert.IsNotNull(result); Assert.AreEqual(genreToAdd.Name, result.Name); }
public ActionResult Add(GenreDto model) { _genreService.AddGenre(model); return(RedirectToAction("Index")); }
protected override async void OnStartup(StartupEventArgs e) { base.OnStartup(e); string fpath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "mix.db"); if (System.IO.File.Exists(fpath)) { System.IO.File.Delete(fpath); } FilmService filmservice = new FilmService(); GenreService genreservice = new GenreService(); AmiService amiservice = new AmiService(); await genreservice.AddGenre("Drame"); await genreservice.AddGenre("Aventure"); await genreservice.AddGenre("Science-fiction"); await genreservice.AddGenre("Action"); await genreservice.AddGenre("Fantasy"); await filmservice.AddFilm("Fight Club", "La vie d'un employé de bureau est bouleversée lorsqu'il rencontre Tyler Durden. Ils forment ensemble le Fight Club, un club de lutte clandestine.", 18, 1); await filmservice.AddFilm("Pulp Fiction", "'odyssée sanglante, burlesque et cocasse de petits malfrats dans la jungle de Hollywood à travers trois histoires qui s'entremêlent.", 18, 1); await filmservice.AddFilm("2001 : L'Odyssée de l'espace", "action", 10, 2); await filmservice.AddFilm("Blade Runner", "Après avoir massacré un équipage et pris le contrôle d'un vaisseau, quatre androïdes ultra perfectionnés parviennent à s'introduire dans Los Angeles.", 14, 3); await filmservice.AddFilm("Interstellar", "Un groupe d'explorateurs exploite une faille dans l'espace-temps afin de parcourir des distances incroyables dans le but de sauver l'humanité.", 12, 3); await filmservice.AddFilm("Le Parrain", "Suite à une tentative d'assassinat sur la personne de Don Vito Corleone, deux puissantes familles de la mafia New-Yorkaise s'affrontent, en quête de vengeance.", 10, 1); await filmservice.AddFilm("Forrest Gump", "Forrest raconte sa fabuleuse histoire, celle d'un simple d'esprit se laissant porter par les événements américains les plus marquants du XXe siècle.", 10, 2); await filmservice.AddFilm("Le Seigneur des Anneaux : Le Retour du roi", "Guidés par Gollum, Frodon et Sam continuent leur périple vers la montagne du destin, tandis que Gandalf et ses compagnons se retrouvent à Isengard.", 12, 5); await filmservice.AddFilm("Le Seigneur des Anneaux : La Communauté de l'anneau", "Frodon reçoit l'Anneau de son oncle Bilbo. Sa vie et son monde sont pourtant en danger, car cet anneau appartient à Sauron, le maître des ténèbres.", 10, 5); await filmservice.AddFilm("L'Empire contre-attaque", "Après la destruction de l'Etoile noire, l'Empire fait tout pour traquer et anéantir les rebelles qui se sont réfugiés sur la planète Hoth.", 12, 4); await filmservice.RateFilm(1, 5, ""); Random random = new Random(); for (int i = 1; i < 11; i++) { int randomnumber = random.Next(0, 6); if (randomnumber > 5) { randomnumber = 5; } await filmservice.RateFilm(i, randomnumber, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum suscipit quam quis elit bibendum ultrices. Ut volutpat diam sed tempus viverra. Praesent malesuada feugiat est, in finibus nisi pretium sed. Nam vitae mi ut augue sodales lobortis in nec enim. Sed eget tincidunt purus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. "); } await amiservice.AddAmi("Sacripant", "Garceau", "*****@*****.**"); await amiservice.AddAmi("Monique", "Gamelin", "*****@*****.**"); await amiservice.AddAmi("Curtis", "Poirier", "*****@*****.**"); await amiservice.AddAmi("Robert", "Garceau", "*****@*****.**"); await amiservice.AddAmi("Searlait", "Fontaine", "*****@*****.**"); }
public async Task <GenreDTO> Post([FromBody] GenreDTO value) { return(await genreService.AddGenre(value)); }
static void Main(string[] args) { GenreService genreService = new GenreService(); BookService bookService = new BookService(); GenreHelper genreHelper = new GenreHelper(); BookHelper bookHelper = new BookHelper(); string[] idAndPass = HelperMethods.ReadLinesFromFile(); string id = idAndPass[0]; string password = idAndPass[1]; string connString = "Server=127.0.0.1;port=5433;User Id=" + id + ";Password="******";Database=BookGenre;"; do { Console.Clear(); Console.WriteLine("1 - Kitap Listele"); Console.WriteLine("2 - Kitap Sil"); Console.WriteLine("3 - Kitap Ekle"); Console.WriteLine("4 - Kitap Güncelle"); Console.WriteLine("5 - Tür Listele"); Console.WriteLine("6 - Tür Sil"); Console.WriteLine("7 - Tür Ekle"); Console.WriteLine("8 - Tür Güncelle"); Console.WriteLine("0 - Çıkış"); var userSelection = Console.ReadKey(); if (userSelection.Key == ConsoleKey.D1) { var books = bookService.GetAllBooks(connString); bookHelper.ListBooks(books); var willBeDeletedBookId = Console.ReadLine().ToInt(); } else if (userSelection.Key == ConsoleKey.D2) { var idCheckBook = false; var willBeDeletedBookId = 0; do { Console.WriteLine("Choose a book for delete"); var books = bookService.GetAllBooks(connString); bookHelper.ListBooks(books); willBeDeletedBookId = Console.ReadLine().ToInt(); idCheckBook = HelperMethods.IsThereBookId(willBeDeletedBookId, books); if (idCheckBook == true) { Console.WriteLine("Non ID you have chosen !"); Console.WriteLine("Please try again."); } }while (idCheckBook); bookService.DeleteBook(willBeDeletedBookId, connString); Console.WriteLine("The Book you choose has been deleted !"); } else if (userSelection.Key == ConsoleKey.D3) { Console.WriteLine("Enter Book Genre"); Console.WriteLine(""); var genres = genreService.GetAllGenres(connString); genreHelper.ListGenres(genres); var newBookGenreId = Console.ReadLine().ToInt(); Console.WriteLine("Enter Book Title"); var newBookTitle = Console.ReadLine(); Console.WriteLine("Enter Author Name"); var newAuthor = Console.ReadLine(); bookService.AddBook(newBookGenreId, newBookTitle, newAuthor, connString); Console.WriteLine("New Book Added !"); } else if (userSelection.Key == ConsoleKey.D4) { bool idCheckBook = false; var willBeUpdatedBookId = 0; do { Console.WriteLine("Choose a book for update"); var books = bookService.GetAllBooks(connString); bookHelper.ListBooks(books); willBeUpdatedBookId = Console.ReadLine().ToInt(); idCheckBook = HelperMethods.IsThereBookId(willBeUpdatedBookId, books); if (idCheckBook == true) { Console.WriteLine("Non ID you have chosen !"); Console.WriteLine("Please try again."); } }while (idCheckBook); bool idCheckGenre = false; var willBeUpdatedGenreId = 0; do { Console.WriteLine("Choose a genre"); var genres = genreService.GetAllGenres(connString); genreHelper.ListGenres(genres); willBeUpdatedGenreId = Console.ReadLine().ToInt(); idCheckGenre = HelperMethods.IsThereGenreId(willBeUpdatedGenreId, genres); if (idCheckGenre == false) { Console.WriteLine("Non ID you have chosen !"); Console.WriteLine("Please try again."); } }while (idCheckGenre); Console.WriteLine("Enter new title"); var newTitle = Console.ReadLine(); Console.WriteLine("Enter new author"); var newAuthor = Console.ReadLine(); bookService.UpdateBook(willBeUpdatedBookId, willBeUpdatedGenreId, newTitle, newAuthor, connString); Console.WriteLine("Update has been done successfully !"); } else if (userSelection.Key == ConsoleKey.D5) { var genres = genreService.GetAllGenres(connString); genreHelper.ListGenres(genres); } else if (userSelection.Key == ConsoleKey.D6) { var idCheckGenre = false; var canBeDeleted = false; var willBeDeletedGenreId = 0; do { Console.WriteLine("Choose a genre for delete"); var genres = genreService.GetAllGenres(connString); genreHelper.ListGenres(genres); willBeDeletedGenreId = Console.ReadLine().ToInt(); idCheckGenre = HelperMethods.IsThereGenreId(willBeDeletedGenreId, genres); if (idCheckGenre == true) { Console.WriteLine("Non ID you have chosen !"); Console.WriteLine("Please try again."); } canBeDeleted = HelperMethods.CanBeDeleted(willBeDeletedGenreId, connString); if (canBeDeleted == false) { Console.WriteLine("The Genre you selected could not be deleted because there are books of that genre"); Console.WriteLine("Please try again!"); } }while (idCheckGenre || !canBeDeleted); genreService.DeleteGenre(willBeDeletedGenreId, connString); Console.WriteLine("The Genre you choose has been deleted !"); } else if (userSelection.Key == ConsoleKey.D7) { Console.WriteLine("Enter Genre Name"); var newGenreName = Console.ReadLine(); genreService.AddGenre(newGenreName, connString); Console.WriteLine("New Genre Added !"); } else if (userSelection.Key == ConsoleKey.D8) { bool idCheckGenre = false; var willBeUpdatedGenreId = 0; do { Console.WriteLine("Choose a genre for update"); var genres = genreService.GetAllGenres(connString); genreHelper.ListGenres(genres); willBeUpdatedGenreId = Console.ReadLine().ToInt(); idCheckGenre = HelperMethods.IsThereGenreId(willBeUpdatedGenreId, genres); if (idCheckGenre == true) { Console.WriteLine("Non ID you have chosen !"); Console.WriteLine("Please try again."); } }while (idCheckGenre); Console.WriteLine("Enter a genre name"); var genresNewName = Console.ReadLine(); genreService.UpdateGenre(willBeUpdatedGenreId, genresNewName, connString); Console.WriteLine("Update has been done successfully !"); } Console.ReadKey(); }while (true); }