public void Delete_GivenSongWasNotDeleted_Should_ReturnNotFound()
        {
            _songService.Delete(Arg.Any <Guid>()).Returns(false);

            var actionResult = _songsController.Delete(Guid.NewGuid());

            Assert.IsType <NotFoundResult>(actionResult.Result);
        }
        public void DeleteViewLoads()
        {
            //Act
            ViewResult result = songController.Delete(900) as ViewResult;

            //Assert
            Assert.IsNotNull(result);
        }
示例#3
0
        public void SongsDelete()
        {
            var testSubject = new SongsController(_testRepo);
            var testObject  = _testRepo.Get(0);

            testSubject.Delete(testObject.Id);
            Assert.IsTrue(_testRepo.GetAll().Count < 20);
        }
        public void Delete()
        {
            // Arrange
            SongsController controller = new SongsController();

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

            // Assert
            Assert.IsNotNull(result);
        }
示例#5
0
        public async Task Delete_GivenSongExists_DeletesSongFromDatabase()
        {
            var song = new Song
            {
                Artist     = "artist",
                Difficulty = "difficulty",
                Level      = 5,
                Name       = "name"
            };
            var songEntity = await _fixture._context.Songs.AddAsync(song);

            await _fixture._context.SaveChangesAsync();

            song = songEntity.Entity;

            var actionResult = await _songsController.Delete(song.Id);

            var songFromDatabase = _fixture._context.Songs.FirstOrDefault(s => s.Id == song.Id);

            Assert.IsType <OkResult>(actionResult);
            Assert.Null(songFromDatabase);
        }
示例#6
0
        public void Run()
        {
            songsController.Seed();

            input = Console.ReadLine();

            while (input != "stop")
            {
                var    arguments = input.Split(',').ToList();
                string command   = arguments[0];

                arguments.RemoveAt(0);

                switch (command)
                {
                case "CreateSong":
                    if (IsAdmin())
                    {
                        if (arguments.Count == 3)
                        {
                            songsController.Create(arguments);
                        }
                        else
                        {
                            Console.WriteLine(Messages.AddSongWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.AddSongNoAdmin);
                    }

                    break;

                case "ReadSongs":
                    if (IsAdmin())
                    {
                        if (arguments.Count == 0)
                        {
                            songsController.Read();
                        }
                        else
                        {
                            Console.WriteLine(Messages.NoArgumentsExpected);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.ReadSongsNoAdmin);
                    }

                    break;

                case "UpdateSong":
                    if (IsAdmin())
                    {
                        if (1 < arguments.Count && arguments.Count <= 4)
                        {
                            songsController.Update(arguments);
                        }
                        else
                        {
                            Console.WriteLine(Messages.UpdateSongWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.UpdateSongNoAdmin);
                    }

                    break;

                case "DeleteSong":
                    if (IsAdmin())
                    {
                        if (arguments.Count == 1)
                        {
                            songsController.Delete(arguments);
                        }
                        else
                        {
                            Console.WriteLine(Messages.DeleteSongWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.DeleteSongNoAdmin);
                    }

                    break;

                case "CreatePlaylist":
                    if (IsLoggedIn())
                    {
                        if (arguments.Count == 2)
                        {
                            playlistsController.Create(arguments, usersController.CurrentUser.Id);
                        }
                        else
                        {
                            Console.WriteLine(Messages.AddPlaylistWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.AddPlaylistNoLogin);
                    }

                    break;

                case "ReadPlaylist":
                    if (IsLoggedIn())
                    {
                        if (arguments.Count == 1)
                        {
                            playlistsController.Read(arguments);
                        }
                        else
                        {
                            Console.WriteLine(Messages.ReadPlaylistWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.ReadPlaylistsNoLogin);
                    }

                    break;

                case "UpdatePlaylist":
                    if (IsLoggedIn())
                    {
                        if (1 < arguments.Count && arguments.Count <= 3)
                        {
                            playlistsController.Update(arguments, usersController.CurrentUser.Id);
                        }
                        else
                        {
                            Console.WriteLine(Messages.UpdatePlaylistWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.UpdatePlaylistNoLogin);
                    }

                    break;

                case "DeletePlaylist":
                    if (IsLoggedIn())
                    {
                        if (arguments.Count == 1)
                        {
                            playlistsController.Delete(arguments, usersController.CurrentUser.Id);
                        }
                        else
                        {
                            Console.WriteLine(Messages.DeletePlaylistWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.DeletePlaylistNoLogin);
                    }

                    break;

                case "SharePlaylist":
                    if (IsLoggedIn())
                    {
                        if (arguments.Count == 1)
                        {
                            playlistsController.Share(arguments, usersController.CurrentUser.Id);
                        }
                        else
                        {
                            Console.WriteLine(Messages.SharePlaylistWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.SharePlaylistNoLogin);
                    }


                    break;

                case "AddSongToPlaylist":
                    if (IsLoggedIn())
                    {
                        if (arguments.Count == 2)
                        {
                            playlistsController.AddSong(arguments, usersController.CurrentUser.Id);
                        }
                        else
                        {
                            Console.WriteLine(Messages.AddSongToPlaylistWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.AddSongToPlaylistNoLogin);
                    }

                    break;

                case "RemoveSongFromPlaylist":
                    if (IsLoggedIn())
                    {
                        if (arguments.Count == 2)
                        {
                            playlistsController.RemoveSong(arguments, usersController.CurrentUser.Id);
                        }
                        else
                        {
                            Console.WriteLine(Messages.RemoveSongFromPlaylistWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.RemoveSongFromPlaylistNoLogin);
                    }

                    break;

                case "Register":
                    if (!IsLoggedIn())
                    {
                        if (arguments.Count == 3)
                        {
                            usersController.Register(arguments);
                        }
                        else
                        {
                            Console.WriteLine(Messages.RegisterWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.SomeoneAlreadyLoggedIn);
                    }

                    break;

                case "Login":
                    if (!IsLoggedIn())
                    {
                        if (arguments.Count == 2)
                        {
                            usersController.Login(arguments);
                        }
                        else
                        {
                            Console.WriteLine(Messages.LoginWrongNumberOfArguments);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.SomeoneAlreadyLoggedIn);
                    }

                    break;

                case "Logout":
                    if (IsLoggedIn())
                    {
                        if (arguments.Count == 0)
                        {
                            usersController.Logout();
                        }
                        else
                        {
                            Console.WriteLine(Messages.NoArgumentsExpected);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.NooneLoggedIn);
                    }

                    break;

                case "CurrentUser":
                    if (IsLoggedIn())
                    {
                        if (arguments.Count == 0)
                        {
                            Console.WriteLine(usersController.CurrentUser.Email);
                        }
                        else
                        {
                            Console.WriteLine(Messages.NoArgumentsExpected);
                        }
                    }
                    else
                    {
                        Console.WriteLine(Messages.NooneLoggedIn);
                    }

                    break;

                default:
                    Console.WriteLine(Messages.CommandNotSupported(command));

                    break;
                }

                input = Console.ReadLine();
            }
        }