Example #1
0
        public async Task Create_ValidRequest_ReturnsJsonResponseAndCreated(string characterName, CrewRoles crewRole, int movieID, int personID)
        {
            #region Arrange
            await DeleteDbContent();

            var client = GetHttpClient();

            var data = await CreatePersonAndMovie();

            var movie  = data[0] as Domain.Movie;
            var person = data[1] as Domain.Person;

            var newCrewMember = new AdminCrewMemberModel
            {
                CharacterName = characterName,
                Role          = crewRole,
                MovieID       = movieID,
                PersonID      = personID
            };

            var expectedCrewMember = new CrewMemberModel
            {
                ID            = 1,
                CharacterName = characterName,
                Role          = crewRole.ToString(),
                Movie         = new MovieModel
                {
                    ID   = movie.ID,
                    Name = movie.Name
                },
                Person = new PersonModel
                {
                    ID        = person.ID,
                    FirstName = person.FirstName,
                    LastName  = person.LastName
                }
            };
            #endregion

            #region Act
            var response = await client.PostAsJsonAsync("/api/crewmember", newCrewMember);

            var responseBody = await response.Content.ReadAsStreamAsync();

            var actualCrewMember = await JsonSerializer.DeserializeAsync <CrewMemberModel>(responseBody);

            #endregion

            #region Assert
            Assert.Equal(HttpStatusCode.Created, response.StatusCode);
            Assert.Equal(expectedCrewMember.ID, actualCrewMember.ID);
            Assert.Equal(expectedCrewMember.CharacterName, actualCrewMember.CharacterName);
            Assert.Equal(expectedCrewMember.Role, actualCrewMember.Role);
            Assert.Equal(expectedCrewMember.Movie.ID, actualCrewMember.Movie.ID);
            Assert.Equal(expectedCrewMember.Movie.Name, actualCrewMember.Movie.Name);
            Assert.Equal(expectedCrewMember.Person.ID, actualCrewMember.Person.ID);
            Assert.Equal(expectedCrewMember.Person.FirstName, actualCrewMember.Person.FirstName);
            Assert.Equal(expectedCrewMember.Person.LastName, actualCrewMember.Person.LastName);
            #endregion
        }
Example #2
0
        public async Task Read_ValidInput_ReturnsCorrectData(int id)
        {
            #region Arrange
            var dbContext = new ApplicationDbContext(_dbContextOptions);
            await dbContext.Database.EnsureDeletedAsync();

            var data = await CreateMovieAndPerson(dbContext);

            var movie  = data[0] as Domain.Movie;
            var person = data[1] as Domain.Person;

            var crewMember = new Domain.CrewMember
            {
                CharacterName = "Character Name",
                Role          = CrewRoles.Actor,
                MovieID       = movie.ID,
                PersonID      = person.ID
            };

            dbContext.CrewMembers.Add(crewMember);
            await dbContext.SaveChangesAsync();

            var expectedCrewMember = new CrewMemberModel
            {
                ID            = id,
                CharacterName = crewMember.CharacterName,
                Role          = crewMember.Role.ToString(),
                Movie         = new MovieModel
                {
                    ID   = movie.ID,
                    Name = movie.Name
                },
                Person = new PersonModel
                {
                    ID        = person.ID,
                    FirstName = person.FirstName,
                    LastName  = person.LastName
                }
            };

            var appCrewMember = new CrewMember(dbContext);
            #endregion

            #region Act
            var actualCrewMember = await appCrewMember.Read(id);

            #endregion

            #region Assert
            Assert.Equal(expectedCrewMember.ID, actualCrewMember.ID);
            Assert.Equal(expectedCrewMember.CharacterName, actualCrewMember.CharacterName);
            Assert.Equal(expectedCrewMember.Role, actualCrewMember.Role);
            Assert.Equal(expectedCrewMember.Movie.ID, actualCrewMember.Movie.ID);
            Assert.Equal(expectedCrewMember.Movie.Name, actualCrewMember.Movie.Name);
            Assert.Equal(expectedCrewMember.Person.ID, actualCrewMember.Person.ID);
            Assert.Equal(expectedCrewMember.Person.FirstName, actualCrewMember.Person.FirstName);
            Assert.Equal(expectedCrewMember.Person.LastName, actualCrewMember.Person.LastName);
            #endregion
        }
Example #3
0
        public async Task Create_ValidInput_ReturnsCorrectData(string characterName, CrewRoles crewRole, int movieID, int personID)
        {
            #region Arrange
            var dbContext = new ApplicationDbContext(_dbContextOptions);
            await dbContext.Database.EnsureDeletedAsync();

            var data = await CreateMovieAndPerson(dbContext);

            var movie  = data[0] as Domain.Movie;
            var person = data[1] as Domain.Person;

            var newCrewMember = new AdminCrewMemberModel
            {
                CharacterName = characterName,
                Role          = crewRole,
                MovieID       = movieID,
                PersonID      = personID
            };

            var expectedCrewMember = new CrewMemberModel
            {
                ID            = 1,
                CharacterName = characterName,
                Role          = crewRole.ToString(),
                Movie         = new MovieModel
                {
                    ID   = movie.ID,
                    Name = movie.Name
                },
                Person = new PersonModel
                {
                    ID        = person.ID,
                    FirstName = person.FirstName,
                    LastName  = person.LastName
                }
            };

            var appCrewMember = new CrewMember(dbContext);
            #endregion

            #region Act
            var actualCrewMember = await appCrewMember.Create(newCrewMember);

            #endregion

            #region Assert
            Assert.Equal(expectedCrewMember.ID, actualCrewMember.ID);
            Assert.Equal(expectedCrewMember.CharacterName, actualCrewMember.CharacterName);
            Assert.Equal(expectedCrewMember.Role, actualCrewMember.Role);
            Assert.Equal(expectedCrewMember.Movie.ID, actualCrewMember.Movie.ID);
            Assert.Equal(expectedCrewMember.Movie.Name, actualCrewMember.Movie.Name);
            Assert.Equal(expectedCrewMember.Person.ID, actualCrewMember.Person.ID);
            Assert.Equal(expectedCrewMember.Person.FirstName, actualCrewMember.Person.FirstName);
            Assert.Equal(expectedCrewMember.Person.LastName, actualCrewMember.Person.LastName);
            #endregion
        }
        public async Task <CrewMember> Update(int id, CrewMemberModel model)
        {
            var crewMember = await _dbContext.CrewMembers.FindAsync(id);

            crewMember.Name           = model.Name;
            crewMember.Picture        = model.Picture;
            crewMember.Age            = model.Age;
            crewMember.Email          = model.Email;
            crewMember.Role           = model.Role;
            crewMember.CertifiedUntil = model.CertifiedUntil;

            return(await base.Update(crewMember));
        }
        public Task <CrewMember> Create(int boatId, CrewMemberModel model)
        {
            var crewMember = new CrewMember()
            {
                Name           = model.Name,
                Picture        = model.Picture,
                Age            = model.Age,
                Email          = model.Email,
                Role           = model.Role,
                CertifiedUntil = model.CertifiedUntil,
                BoatId         = boatId,
            };

            return(base.Create(crewMember));
        }
Example #6
0
        private List <CrewMemberModel> ParseJson(string content)
        {
            var crewList = new List <CrewMemberModel>();


            dynamic json = JToken.Parse(content);

            foreach (var j in json.RelatedTopics)
            {
                var crew = new CrewMemberModel();
                crew.Description = j.Text.ToString();
                crew.FirstUrl    = j.FirstURL.ToString();
                crew.Icon        = new IconModel
                {
                    Url    = j.Icon.URL.ToString(),
                    Height = j.Icon.Height.ToString(),
                    Width  = j.Icon.Width.ToString()
                };

                crewList.Add(crew);
            }
            return(crewList);
        }
Example #7
0
        public async Task Update_ValidRequest_ReturnsJsonResponseAndOk(int id, string characterName, CrewRoles crewRole, int movieID, int personID)
        {
            #region Arrange
            await DeleteDbContent();

            var client    = GetHttpClient();
            var dbContext = GetDbContext();

            var data = await CreatePersonAndMovie();

            var movie  = data[0] as Domain.Movie;
            var person = data[1] as Domain.Person;

            var data2 = await CreatePersonAndMovie();

            var movie2  = data2[0] as Domain.Movie;
            var person2 = data2[1] as Domain.Person;

            dbContext.CrewMembers.Add(new Domain.CrewMember
            {
                Role     = CrewRoles.Writer,
                MovieID  = movie.ID,
                PersonID = person.ID
            });
            await dbContext.SaveChangesAsync();

            var newCrewMember = new AdminCrewMemberModel
            {
                ID            = id,
                CharacterName = characterName,
                Role          = crewRole,
                MovieID       = movieID,
                PersonID      = personID
            };

            var expectedCrewMember = new CrewMemberModel
            {
                ID            = 1,
                CharacterName = characterName,
                Role          = crewRole.ToString(),
                Movie         = new MovieModel
                {
                    ID   = movie2.ID,
                    Name = movie2.Name
                },
                Person = new PersonModel
                {
                    ID        = person2.ID,
                    FirstName = person2.FirstName,
                    LastName  = person2.LastName
                }
            };
            #endregion

            #region Act
            var response = await client.PutAsJsonAsync($"/api/crewmember/{id}", newCrewMember);

            var responseBody = await response.Content.ReadAsStreamAsync();

            var actualCrewMember = await JsonSerializer.DeserializeAsync <CrewMemberModel>(responseBody);

            #endregion

            #region Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.Equal(expectedCrewMember.ID, actualCrewMember.ID);
            Assert.Equal(expectedCrewMember.CharacterName, actualCrewMember.CharacterName);
            Assert.Equal(expectedCrewMember.Role, actualCrewMember.Role);
            Assert.Equal(expectedCrewMember.Movie.ID, actualCrewMember.Movie.ID);
            Assert.Equal(expectedCrewMember.Movie.Name, actualCrewMember.Movie.Name);
            Assert.Equal(expectedCrewMember.Person.ID, actualCrewMember.Person.ID);
            Assert.Equal(expectedCrewMember.Person.FirstName, actualCrewMember.Person.FirstName);
            Assert.Equal(expectedCrewMember.Person.LastName, actualCrewMember.Person.LastName);
            #endregion
        }