public void SetUp()
        {

            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://dragonapi.devjakobsen.dk/api/game");
            var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "game" } });


            gameController = new GameController();
            UrlHelper urlHelper = new UrlHelper(request);
            gameController.ControllerContext = new HttpControllerContext(config, routeData, request);
            gameController.Request = request;
            gameController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            gameController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
            gameController.Url = urlHelper;
            genreController = new GenreController();
            var response = genreController.Get(1);
            var contentResult = response as OkNegotiatedContentResult<DTOGenre>;

            DTOGenre DtoGenre = contentResult.Content;
            genrefromDb = new Genre();
            genrefromDb.Name = DtoGenre.Name;
            genrefromDb.Id = DtoGenre.Id;
            game = new Game() { Name = "Integration Test Game", Genre = genrefromDb };
        }
        // POST: api/Genre
        public HttpResponseMessage Post(Genre genre)
        {
            genre = GenreRepository.Create(genre);
            var response = Request.CreateResponse<Genre>(HttpStatusCode.Created, genre);
            string uri = Url.Link("DefaultApi", new { id = genre.Id });
            response.Headers.Location = new Uri(uri);
            return response;

        }
Beispiel #3
0
 public void Test_if_a_game_has_a_genre()
 {
     Genre genre1 = new Genre() {Id = 1, Name = "Figure Game"};
     Genre genre2 = new Genre() { Id = 2, Name = "Card Game" };
     game.Genre = genre1;
     Assert.IsNotNull(game.Genre);
     Assert.AreNotSame(genre2, game.Genre);
     Assert.AreSame(genre1, game.Genre);
 }
 public void Test_if_genre_can_be_created_without_game()
 {
     List<Game> games = null;
     Genre genre = new Genre() { Id = 1, Name = "Figur", Games = games };
     DTOGenreConverter dtoGenreConverter = new DTOGenreConverter();
     DTOGenre dtoGenre = dtoGenreConverter.Convert(genre);
     Assert.IsNull(games);
     Assert.NotNull(dtoGenre);
     Assert.AreEqual(dtoGenre.Id, genre.Id);
 }
 public void Test_if_Genre_with_games_can_be_converted_to_DTO()
 {
     Game game1 = new Game() {Id = 1, Name = "Warhammer"};
     Game game2 = new Game() { Id = 1, Name = "Warhammer 40k" };
     List<Game> games = new List<Game>();
     games.Add(game1);
     games.Add(game2);
     Genre genre = new Genre() { Id = 1, Name = "Figur", Games = games };
     DTOGenreConverter dtoGenreConverter = new DTOGenreConverter();
     DTOGenre dtoGenre = dtoGenreConverter.Convert(genre);
     Assert.IsNotNull(games);         
     Assert.AreEqual(dtoGenre.Id, genre.Id);
     Assert.AreSame(game1.Name, dtoGenre.DtoGames[0].Name);
     Assert.Greater(dtoGenre.DtoGames.Count, 0);
 }
        public void SetUp()
        {

            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://dragonapi.devjakobsen.dk/api/genre");
            var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "Genre" } });


            genreController = new GenreController();
            UrlHelper urlHelper = new UrlHelper(request);
            genreController.ControllerContext = new HttpControllerContext(config, routeData, request);
            genreController.Request = request;
            genreController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            genreController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
            genreController.Url = urlHelper;

            Genre = new Genre() { Name = "Integration Test Genre" };

        }
 public void Test_if_tournament_can_be_converted_with_groups_and_type_and_a_game()
 {
     DTOTournament dtoTournament = new DTOTournament();
     TournamentType tournamentType = new TournamentType() { Id = 1, Type = "2vs2" };
     Genre genre = new Genre() { Id = 1, Name = "wars"};
     Player player1 = new Player() { Id = 1, Name = "Hans"};
     Player player2 = new Player() {Id = 2, Name = "Ole"};
     Player player3 = new Player() { Id = 3, Name = "Lars" };
     Player player4 = new Player() { Id = 4, Name = "Peter" };
     List<Player> players1 = new List<Player>() {player1, player2};
     List<Player> players2 = new List<Player>() { player3, player4 };
     Team team1 = new Team() {Id = 1, Name = "team1", Players = players1, Win = 2, Draw = 2, Loss = 1};
     Team team2 = new Team() { Id = 1, Name = "team2", Players = players2, Win = 3, Draw = 0, Loss = 1 };
     List<Team> teams1 = new List<Team>() {team1, team2};
     Group group1 = new Group() { Id = 1, Name = "Hans og Ole", Teams = teams1};
     Group group2 = new Group() { Id = 1, Name = "Lars og Peter", Teams = teams1};
     List<Group> groups = new List<Group>() {group1, group2};
     Game game = new Game() { Id = 1, Name = "Warhammer", Genre = genre};
     Match match = new Match() {Id = 1, AwayTeam = team1, HomeTeam = team2, Round = "blabla"};
     DTOTournamentConverter dtoTournamentConverter = new DTOTournamentConverter();
     Tournament tournament = new Tournament()
     {
         Id = 1,
         Name = "Tournament One",
         StartDate = DateTime.Today,
         TournamentType = tournamentType,
         Groups = groups,
         Game = game,
         Matches = new List<Match>() { match}
     };
     
     dtoTournament = dtoTournamentConverter.Convert(tournament);
     Assert.IsNotNull(tournament.TournamentType);
     Assert.AreEqual(tournament.Id, dtoTournament.Id);
     Assert.AreEqual(tournamentType.Id, dtoTournament.DTOTournamentType.Id);
     Assert.IsNotNull(groups);
     Assert.IsNotNull(dtoTournament.DtoGroups);
     Assert.AreEqual(groups.Count, dtoTournament.DtoGroups.Count);
     Assert.IsNotNull(dtoTournament.DtoGame);
     Assert.AreEqual(dtoTournament.DtoGame.Id, game.Id);
 }
Beispiel #8
0
        protected override void Seed(DataLayer.Entities.Model1 context)
        {
            Authors author1 = new Entities.Authors {
                Id = 1, FirstName = "Alexander", LastName = "Pishkin"
            };
            Authors author2 = new Entities.Authors {
                Id = 2, FirstName = "Lev", LastName = "Tolstoy"
            };

            context.Authors.AddOrUpdate(author1);
            context.Authors.AddOrUpdate(author2);
            Genre genre1 = new Entities.Genre {
                Id = 1, Name = "Action"
            };
            Genre genre2 = new Entities.Genre {
                Id = 2, Name = "Detective"
            };

            context.Genre.AddOrUpdate(genre1);
            context.Genre.AddOrUpdate(genre2);
            Books book1 = new Entities.Books {
                Id = 1, AuthorId = 1, Title = "TestBook1", GenreId = 1, Price = 1000, Pages = 150
            };
            Books book2 = new Entities.Books {
                Id = 2, AuthorId = 2, Title = "TestBook2", GenreId = 2, Price = 3000, Pages = 200
            };

            context.Books.AddOrUpdate(book1);
            context.Books.AddOrUpdate(book2);
            Users user1 = new Entities.Users {
                Id = 1, Email = "*****@*****.**", Name = "TestUser1"
            };
            Users user2 = new Entities.Users {
                Id = 2, Email = "*****@*****.**", Name = "TestUser2"
            };

            context.Users.AddOrUpdate(user1);
            context.Users.AddOrUpdate(user2);
        }
 // PUT: api/Genre/5
 public void Put(int id, Genre genre)
 {
     genre.Id = id;
     if (!GenreRepository.Update(genre)) throw new HttpResponseException(HttpStatusCode.NotFound);
 }
Beispiel #10
0
 public void TearDown()
 {
     genre = null;
 }
Beispiel #11
0
 public void SetUp()
 {
     genre = new Genre() { Id = 1, Name = "Figure Game" };
 }
Beispiel #12
0
        public Genre GetOrCreateGenre(string genre)
        {
            var dbGenre = DbEntities.Genres.FirstOrDefault(el => el.Name == genre);
            if (dbGenre == null)
            {
                dbGenre = new Genre() { Name = genre };
                DbEntities.AddToGenres(dbGenre);
            }

            return dbGenre;
        }
 public void TearDown()
 {
     genre = null;
     apiService = null;
     genreController = null;
 }
 public void SetUp()
 {
     genre = new Genre() {Name = "TestGenre"};
     apiService = new WebApiService();
     genreController = new GenreController();
 }