public void ExecuteCommand(ICommand command) { //var commandName = command.GetType().Name; //var handler = GetType().Assembly.GetTypes().FirstOrDefault(f => f.Name == $"{commandName}Handler"); //if (handler != null) //{ // var handlerInstace = Activator.CreateInstance(handler, command, null); // var handlerMethod = handler.GetMethods().FirstOrDefault(f => f.Name == "Execute"); // if (handlerMethod != null) // handlerMethod.Invoke(handlerInstace, new object[] { }); //} if (command.GetType() == typeof(LoginCommand)) { var authCommand = (LoginCommand)command; var handler = new LoginCommandHandler(authCommand, UserRepository); handler.Execute(); } if (command.GetType() == typeof(CreateMovieCommand)) { var createMovieCommand = (CreateMovieCommand)command; var handler = new CreateMovieCommandHandler(createMovieCommand, MovieRepository); handler.Execute(); } if (command.GetType() == typeof(EditMovieCommand)) { var editCommand = (EditMovieCommand)command; var handler = new EditMovieCommandHandler(editCommand, Context, MovieRepository); handler.Execute(); } if (command.GetType() == typeof(DeleteMovieCommand)) { var deleteCommand = (DeleteMovieCommand)command; var handler = new DeleteMovieCommandHandler(deleteCommand, MovieRepository); handler.Execute(); } }
public async Task InputDataIsok_Executed_ReturnMovieId() { var fixture = new Fixture(); var movieRepository = new Mock <IMovieRepository>(); var movieGenreRepository = new Mock <IMovieGenreRepository>(); var movieProductionRepository = new Mock <IMovieProductionCompanyRepository>(); var movieActorRepository = new Mock <IMovieActorRepository>(); var movieDirectorRepository = new Mock <IMovieDirectorRepository>(); var createMovieCommand = fixture.Create <CreateMovieCommand>(); var createMovieCommandHandler = new CreateMovieCommandHandler(movieRepository.Object, movieGenreRepository.Object, movieProductionRepository.Object, movieActorRepository.Object, movieDirectorRepository.Object); var id = await createMovieCommandHandler.Handle(createMovieCommand, new System.Threading.CancellationToken()); Assert.True(id >= 0); Assert.True(createMovieCommand.Genres.Count > 0); movieRepository.Verify(m => m.AddMovieAsync(It.IsAny <Movie>()), Times.Once); }