예제 #1
0
        public async Task UpdateActor_WithoutActor_False()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();
            var data  = new List <Actor>()
            {
                actor
            }.AsQueryable();
            var dbSet   = GenerateEnumerableDbSetMock(data);
            var context = GenerateEnumerableContextMock(dbSet);
            //context.Setup(x => x.Actors.FindAsync(It.IsAny<int>())).ReturnsAsync(null);
            var service = new ActorsService(context.Object);

            var updatedActor = new ActorBuilder()
                               .WithId(1)
                               .WithFirstname("John")
                               .WithFirstname("Smith")
                               .Build();

            //Act
            var result = await service.UpdateActor(updatedActor);

            //Assert
            Assert.False(result);
        }
예제 #2
0
        public async Task UpdateActor_HasActor_SaveChanges()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();
            var data  = new List <Actor>()
            {
                actor
            }.AsQueryable();
            var dbSet   = GenerateEnumerableDbSetMock(data);
            var context = GenerateEnumerableContextMock(dbSet);

            context.Setup(x => x.Actors.FindAsync(It.IsAny <int>())).ReturnsAsync(actor);
            var service = new ActorsService(context.Object);

            var updatedActor = new ActorBuilder()
                               .WithId(1)
                               .WithFirstname("John")
                               .WithFirstname("Smith")
                               .Build();

            //Act
            await service.UpdateActor(updatedActor);

            //Assert
            context.Verify(x => x.SaveChangesAsync(default(CancellationToken)), Times.Once);
        }
        public async Task DeleteEntityTest()
        {
            var fakeRepositoryMock = new Mock <IActorsContext>();

            fakeRepositoryMock.Setup(x => x.GetActorsList()).ReturnsAsync(vars);


            var actorService = new ActorsService(fakeRepositoryMock.Object);

            await actorService.DeleteActor(2);
        }
예제 #4
0
        public async Task GetById_WithInvalidInput_ShouldReturnInvalidResult(int id)
        {
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.SeedData(dbContext);

            var actorsRepository = new EfDeletableEntityRepository <Actor>(dbContext);

            var service = new ActorsService(actorsRepository);

            Assert.Null(service.GetById <ActorViewModel>(id));
        }
예제 #5
0
        public async Task RemoveActor_WithoutActor_False()
        {
            //Arrange
            var context = GenerateEnumerableEmptyContextMock();
            //context.Setup(x => x.Actors.FindAsync(It.IsAny<int>())).ReturnsAsync(null);
            var service = new ActorsService(context.Object);

            //Act
            var result = await service.RemoveActor(1);

            //Assert
            Assert.False(result);
        }
예제 #6
0
        public async Task GetAllByQuery_WithValidInput_ShouldReturnValidResult()
        {
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.SeedData(dbContext);

            var actorsRepository = new EfDeletableEntityRepository <Actor>(dbContext);

            var service = new ActorsService(actorsRepository);

            var result = service.GetAllByQuery <ActorViewModel>("1").ToList();

            Assert.Single(result);
        }
예제 #7
0
        public async Task GetByName_WithValidInput_ShouldReturnValidResult()
        {
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.SeedData(dbContext);

            var actorsRepository = new EfDeletableEntityRepository <Actor>(dbContext);

            var service = new ActorsService(actorsRepository);

            var result = service.GetByTitle <ActorViewModel>("1");

            Assert.Equal("1", result.FirstName);
        }
예제 #8
0
        public async Task GetActorsCount_WithValidInput_ShouldReturnValidResult()
        {
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.SeedData(dbContext);

            var actorsRepository = new EfDeletableEntityRepository <Actor>(dbContext);

            var service = new ActorsService(actorsRepository);

            var result = service.GetActorsCount();

            Assert.Equal(2, result);
        }
예제 #9
0
        public async Task GetActorById_ActorWithIdExists_ActorWithId()
        {
            //Arrange
            var expected = new ActorBuilder().WithId(2).Build();
            var context  = GenerateEnumerableEmptyContextMock();
            var service  = new ActorsService(context.Object);

            context.Setup(x => x.Actors.FindAsync(2)).ReturnsAsync(expected);

            //Act
            var actor = await service.GetActorById(2);

            //Assert
            Assert.Equal(expected.Id, actor.Id);
        }
예제 #10
0
        public async Task Delete_WithValidInput_ShouldReturnValidResult()
        {
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.SeedData(dbContext);

            var actorsRepository = new EfDeletableEntityRepository <Actor>(dbContext);
            var service          = new ActorsService(actorsRepository);

            var actor = service.GetById <ActorEditModel>(1);

            var result = service.Delete(actor);

            Assert.Equal(1, dbContext.Actors.Count());
        }
예제 #11
0
        public async Task AddNewActor_NewActor_AddAndSaveChanges()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();

            var dbSet   = GenerateEnumerableDbSetMock(new List <Actor>().AsQueryable());
            var context = GenerateEnumerableContextMock(dbSet);
            var service = new ActorsService(context.Object);

            //Act
            await service.AddNewActor(actor);

            //Assert
            dbSet.Verify(x => x.Add(It.IsAny <Actor>()), Times.Once);
            context.Verify(x => x.SaveChangesAsync(default(CancellationToken)), Times.Once);
        }
예제 #12
0
        public void CreateActorShouldCreateActor()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Actors_CreateActor_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            IActorsService actorsService = new ActorsService(db);

            actorsService.CreateActor("Test Actor");
            actorsService.CreateActor("Test Actor 2");
            actorsService.CreateActor("Test Actor 3");

            int actorsCount = db.Actors.ToList().Count();

            Assert.Equal(3, actorsCount);
        }
예제 #13
0
        public async Task GetAllActors_ActorCountIs3_ListWith3Actors()
        {
            //Arrange
            var data = new List <Actor>()
            {
                new ActorBuilder().Build(),
                new ActorBuilder().Build(),
                new ActorBuilder().Build(),
            }.AsQueryable();
            var dbSet   = GenerateEnumerableDbSetMock(data);
            var context = GenerateEnumerableContextMock(dbSet);
            var service = new ActorsService(context.Object);

            //Act
            var resultList = await service.GetAllActors();

            //Assert
            Assert.Equal(3, resultList.Count);
        }
예제 #14
0
        public async Task Edit_WithValidInput_ShouldReturnValidResult()
        {
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.SeedData(dbContext);

            var actorsRepository = new EfDeletableEntityRepository <Actor>(dbContext);
            var service          = new ActorsService(actorsRepository);

            var viewModel = new ActorEditModel()
            {
                Id        = 1,
                FirstName = "Edited",
            };

            var result = service.Edit(viewModel);

            Assert.Equal("Edited", viewModel.FirstName);
        }
예제 #15
0
        public void GetAllActorsShouldReturnAllActors()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Actors_GetAllActors_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            IActorsService actorsService = new ActorsService(db);

            actorsService.CreateActor("Name 1");
            actorsService.CreateActor("Name 2");
            actorsService.CreateActor("Name 3");
            actorsService.CreateActor("Name 4");

            List <Actor> actors = actorsService.GetAllActors().ToList();

            int actorsCount = actors.Count();

            Assert.Equal(4, actorsCount);
        }
예제 #16
0
        public void GetActorShouldReturnActor()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Actors_GetActor_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            IActorsService actorsService = new ActorsService(db);

            db.Actors.Add(new Actor
            {
                Name = "Mark Hamill"
            });

            db.SaveChanges();

            Actor actor = actorsService.GetActor(db.Actors.Last().Id);

            Assert.Equal("Mark Hamill", actor.Name);
        }
예제 #17
0
        public async Task RemoveActor_HasActor_True()
        {
            //Arrange
            var actor = new ActorBuilder().WithId(1).Build();
            var data  = new List <Actor>()
            {
                actor
            }.AsQueryable();
            var dbSet   = GenerateEnumerableDbSetMock(data);
            var context = GenerateEnumerableContextMock(dbSet);

            context.Setup(x => x.Actors.FindAsync(It.IsAny <int>())).ReturnsAsync(actor);
            var service = new ActorsService(context.Object);

            //Act
            var result = await service.RemoveActor(1);

            //Assert
            Assert.True(result);
        }
예제 #18
0
        public void GetActorsMoviesAndPostersShouldReturnAListOfMovies()
        {
            DbContextOptions <UltimateMoviesDbContext> options = new DbContextOptionsBuilder <UltimateMoviesDbContext>()
                                                                 .UseInMemoryDatabase(databaseName: "Actors_GetActorsMoviesAndPosters_Database")
                                                                 .Options;
            UltimateMoviesDbContext db = new UltimateMoviesDbContext(options);

            IActorsService actorsService = new ActorsService(db);

            db.Movies.Add(new Movie
            {
                Name      = "Test Name",
                PosterUrl = "https://imdb.com/"
            });

            db.SaveChanges();

            db.Actors.Add(new Actor
            {
                Name = "Test Actor"
            });

            db.SaveChanges();

            db.ActorsMovies.Add(new ActorMovie
            {
                ActorId = db.Actors.Last().Id,
                MovieId = db.Movies.Last().Id
            });

            db.SaveChanges();

            List <Movie> movies = actorsService.GetActorsMoviesAndPosters(db.Actors.Last().Id).ToList();

            int moviesCount = movies.Count();

            Assert.Equal(1, moviesCount);
            Assert.Equal(db.Movies.Last().Id, movies[0].Id);
            Assert.Equal("Test Name", movies[0].Name);
            Assert.Equal("https://imdb.com/", movies[0].PosterUrl);
        }
        public async Task GetEntityListTest()
        {
            var fakeRepositoryMock = new Mock <IActorsContext>();

            fakeRepositoryMock.Setup(x => x.GetActorsList()).ReturnsAsync(vars);


            var actorService = new ActorsService(fakeRepositoryMock.Object);


            var result = await actorService.GetActorsList();

            Assert.Collection(result, var =>
            {
                Assert.Equal("Seb Seb", var.Name);
            },
                              car =>
            {
                Assert.Equal("Ham Ham", var.Name);
            });
        }
예제 #20
0
        public async Task Create_WithValidInput_ShouldReturnValidResult()
        {
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            var actorsRepository = new EfDeletableEntityRepository <Actor>(dbContext);

            var service = new ActorsService(actorsRepository);

            var input = new ActorCreateModel()
            {
                FirstName = "Bob",
                LastName  = "Ross",
                Gender    = "Male",
            };

            var actor  = service.Create(input);
            var result = service.GetByTitle <ActorViewModel>("Bob");

            Assert.Equal("Ross", result.LastName);
            Assert.Equal("Male", result.Gender);
        }
예제 #21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            movieName = Request.QueryString["getMovieName"].ToString(); //קבלת קוד המשחק דרך GET
        }
        catch
        {
            Response.Redirect("Home.aspx");
        }
        if (!Page.IsPostBack)
        {
            MoviesService movieService = new MoviesService();
            ActorsService actorService = new ActorsService();
            localMoviesWebService.MoviesWebService moviesWeb = new localMoviesWebService.MoviesWebService();

            movieID = moviesWeb.GetIDbyName(movieName);
            actors  = moviesWeb.ActorsInMovie(movieID);
            PopulatePage(moviesWeb.GetMovieByID(movieID));
        }
        PopulateRating();
    }
예제 #22
0
    public DataSet GetActors()
    {
        ActorsService act = new ActorsService();

        return(act.GetActors());
    }
예제 #23
0
    public void InsertActorInMovie(int movieID, int actorID)
    {
        ActorsService act = new ActorsService();

        act.InsertActorInMovie(movieID, actorID);
    }
예제 #24
0
    public int ActorGetIDbyName(string name)
    {
        ActorsService act = new ActorsService();

        return(act.GetIDbyName(name));
    }
예제 #25
0
    public void InsertActor(localMoviesWebService.ActorsDetails actor)
    {
        ActorsService act = new ActorsService();

        act.InsertActor(actor);
    }
예제 #26
0
    public string[] ActorsInMovie(int movieID)
    {
        ActorsService act = new ActorsService();

        return(act.ActorsInMovie(movieID));
    }
예제 #27
0
    public void InsertActor(ActorsDetails actor)
    {
        ActorsService act = new ActorsService();

        act.InsertActor(actor);
    }
 public MyFilmRecommendService()
 {
     actorsservice = new ActorsService();
 }
 public async Task SetEntityTest()
 {
     var fakeRepository = Mock.Of <IActorsContext>();
     var actorService   = new ActorsService(fakeRepository);
     await actorService.SetActor(var);
 }