//private static Func<int,Film> getFilmyById = i => new Film { Id = 1, Name = "Pulp Fiction", DirectorId = 1 }; static RouteHandlers() { ListFilmsHandler = () => ListFilmsRoute.Handle(); ListFilmByIdHandler = filmId => ListFilmByIdRoute.Handle(filmId, //Write some SQL to get the film fId => new Film { Id = 1, Name = "Pulp Fiction", DirectorId = 1 }, //Write some SQL to get the director dirId => new Director { Name = "Steven Spielberg" }, //Write some SQL to get the cast fId => new[] { new CastMember { Name = "John Travolta" }, new CastMember { Name = "Samuel L Jackson" } } ); UpdateFilmHandler = (filmId, film) => UpdateFilmRoute.Handle( filmId, film, () => new Random().Next() % 2 == 0, fId => new Film { Id = 1, Name = "Pulp Fiction", DirectorId = 1 } ); CreateFilmHandler = film => CreateFilmRoute.Handle(film, () => new Random().Next() % 2 == 0); DeleteFilmHandler = id => DeleteFilmRoute.Handle(id, () => new Random().Next() % 2 == 0); }
public async Task Should_return_201_when_creating_film() { //Given RouteHandlers.CreateFilmHandler = film => CreateFilmRoute.Handle(film, () => true); var newFilm = new Film { Name = "Shrek" }; //When var response = await this.client.PostAsync("/api/delegate/films", new StringContent(JsonConvert.SerializeObject(newFilm), Encoding.UTF8, "application/json")); //Then Assert.Equal(201, (int)response.StatusCode); }
public async Task Should_return_422_on_invalid_data_when_creating_film() { //Given //No mock library required to fake the UserValidQuery we just invoke a func to return true/false RouteHandlers.CreateFilmHandler = film => CreateFilmRoute.Handle(film, () => true); var newFilm = new Film { Name = "" }; //When var response = await this.client.PostAsync("/api/delegate/films", new StringContent(JsonConvert.SerializeObject(newFilm), Encoding.UTF8, "application/json")); //Then Assert.Equal(422, (int)response.StatusCode); }
static RouteHandlers() { CreateFilmHandler = film => CreateFilmRoute.Handle(film, () => ValidUserQuery.Execute()); DeleteFilmHandler = id => DeleteFilmRoute.Handle(id, () => ValidUserQuery.Execute()); ListFilmByIdHandler = id => ListFilmByIdRoute.Handle( id, filmId => ListFilmsByIdQuery.ListFilmsByIdQuery.Execute(id), dirId => GetDirectorByIdQuery.Execute(dirId), filmId => GetCastByFilmIdQuery.Execute(id) ); ListFilmsHandler = () => ListFilmsRoute.Handle(); UpdateFilmHandler = (id, film) => UpdateFilmRoute.Handle( id, film, () => ValidUserQuery.Execute(), filmId => ListFilmsByIdQuery.ListFilmsByIdQuery.Execute(filmId)); }