示例#1
0
        public void GetTitles_ShouldReturnArrayOftitles_WhenTheRepositoryPassWatchedMoviesData()
        {
            var viewModelsRepositoryMock = MockRepository.GenerateMock <IViewModelsRepository>();

            //Arrange
            List <WatchedMovies> watchedMovies = new List <WatchedMovies>();
            WatchedMovies        entity1       = new WatchedMovies {
                Id = 1, Email = "Email1", Title = "Title1"
            };
            WatchedMovies entity2 = new WatchedMovies {
                Id = 2, Email = "Email2", Title = "Title2"
            };

            watchedMovies.Add(entity1);
            watchedMovies.Add(entity2);
            string[] expectedArray = new string[] { "Title1", "Title2" };
            viewModelsRepositoryMock.Expect(dao => dao.GetWatchedMoviesData()).Return(watchedMovies);

            var watcheMoviesStatisticService = new WatcheMoviesStatisticService(viewModelsRepositoryMock);

            //Act
            var resault = watcheMoviesStatisticService.GetTitles();

            //Assert
            Assert.AreEqual(expectedArray[0], resault.ToArray()[0]);
            Assert.AreEqual(expectedArray[1], resault.ToArray()[1]);
        }
示例#2
0
        public void GetData_ShouldReturnListOfAgregatedDataOfWatchedMoviesByUser_WhenSingleUserWatchedOneMovies()
        {
            var viewModelsRepositoryMock = MockRepository.GenerateMock <IViewModelsRepository>();

            //Arrange
            List <WatchedMovies> watchedMovies = new List <WatchedMovies>();
            WatchedMovies        entity1       = new WatchedMovies {
                Id = 1, Email = "Email1", Title = "Title1"
            };;

            watchedMovies.Add(entity1);

            viewModelsRepositoryMock.Expect(dao => dao.GetWatchedMoviesData()).Return(watchedMovies);
            var expectedTitlesList = new List <string> {
                "Title1"
            };

            //Act
            var watcheMoviesStatisticService = new WatcheMoviesStatisticService(viewModelsRepositoryMock);
            var resault = watcheMoviesStatisticService.GetData();

            //Assert
            Assert.AreEqual("Email1", resault[0].UserEmail);
            CollectionAssert.AreEqual(expectedTitlesList, resault[0].MovieTitles);
        }
示例#3
0
        public void GetData_ShouldReturnListOfAgregatedDataOfWatchedMoviesByUser_WhenSingleUserWatchedOneMovies()
        {
            //Arrange
            var viewModelsRepositoryMock = MockRepository.GenerateMock <IViewModelsRepository>();

            List <WatchedMovies> watchedMovies = new List <WatchedMovies>();
            WatchedMovies        entity1       = new WatchedMovies {
                MovieId = 1, UserId = Guid.NewGuid(), UserDisplayName = "User1", MovieTitle = "Title1"
            };

            watchedMovies.Add(entity1);

            viewModelsRepositoryMock.Expect(dao => dao.GetWatchedMoviesData()).Return(watchedMovies);
            var expectedTitlesList = new List <string> {
                "Title1"
            };

            var unitOfWorkMockMock = MockRepository.GenerateStub <IUnitOfWork>();

            unitOfWorkMockMock.Stub(uow => uow.ViewModelsRepository).Return(viewModelsRepositoryMock);

            var watcheMoviesStatisticService = new WatcheMoviesStatisticService(unitOfWorkMockMock);

            //Act
            var resault = watcheMoviesStatisticService.GetData();

            //Assert
            Assert.AreEqual("User1", resault[0].UserDisplayMail);
            CollectionAssert.AreEqual(expectedTitlesList, resault[0].MovieTitles);
        }
示例#4
0
        public void GetData_ShouldReturnListOfAgregatedDataOfWatchedMoviesByUser_WhenMultiplesUsersWatchedMultiplesMovie()
        {
            //Arrange
            var viewModelsRepositoryMock = MockRepository.GenerateMock <IViewModelsRepository>();

            var userId1 = Guid.NewGuid();
            var userId2 = Guid.NewGuid();

            List <WatchedMovies> watchedMovies = new List <WatchedMovies>();
            WatchedMovies        entity1       = new WatchedMovies {
                MovieId = 1, UserId = userId1, UserDisplayName = "User1", MovieTitle = "User1Title1"
            };
            WatchedMovies entity2 = new WatchedMovies {
                MovieId = 2, UserId = userId1, UserDisplayName = "User1", MovieTitle = "User1Title2"
            };
            WatchedMovies entity3 = new WatchedMovies {
                MovieId = 3, UserId = userId2, UserDisplayName = "User2", MovieTitle = "User2Title1"
            };
            WatchedMovies entity4 = new WatchedMovies {
                MovieId = 4, UserId = userId2, UserDisplayName = "User2", MovieTitle = "User2Title2"
            };

            watchedMovies.Add(entity1);
            watchedMovies.Add(entity2);
            watchedMovies.Add(entity3);
            watchedMovies.Add(entity4);

            viewModelsRepositoryMock.Expect(dao => dao.GetWatchedMoviesData()).Return(watchedMovies);

            var firstUserTitlesList = new List <string> {
                "User1Title1", "User1Title2"
            };
            var secondUserTitlesList = new List <string> {
                "User2Title1", "User2Title2"
            };

            var unitOfWorkMockMock = MockRepository.GenerateStub <IUnitOfWork>();

            unitOfWorkMockMock.Stub(uow => uow.ViewModelsRepository).Return(viewModelsRepositoryMock);

            var watcheMoviesStatisticService = new WatcheMoviesStatisticService(unitOfWorkMockMock);

            //Act
            var resault = watcheMoviesStatisticService.GetData();

            //Assert
            Assert.AreEqual("User1", resault[0].UserDisplayMail);
            CollectionAssert.AreEqual(firstUserTitlesList, resault[0].MovieTitles);
            Assert.AreEqual("User2", resault[1].UserDisplayMail);
            CollectionAssert.AreEqual(secondUserTitlesList, resault[1].MovieTitles);
        }
示例#5
0
        public void GetData_ShouldReturnListOfAgregatedDataOfWatchedMoviesByUser_WhenMultiplesUsersWatchedMultiplesMovie()
        {
            var viewModelsRepositoryMock = MockRepository.GenerateMock <IViewModelsRepository>();

            //Arrange
            List <WatchedMovies> watchedMovies = new List <WatchedMovies>();
            WatchedMovies        entity1       = new WatchedMovies {
                Id = 1, Email = "User1", Title = "User1Title1"
            };
            WatchedMovies entity2 = new WatchedMovies {
                Id = 2, Email = "User1", Title = "User1Title2"
            };
            WatchedMovies entity3 = new WatchedMovies {
                Id = 3, Email = "User2", Title = "User2Title1"
            };
            WatchedMovies entity4 = new WatchedMovies {
                Id = 4, Email = "User2", Title = "User2Title2"
            };

            watchedMovies.Add(entity1);
            watchedMovies.Add(entity2);
            watchedMovies.Add(entity3);
            watchedMovies.Add(entity4);

            viewModelsRepositoryMock.Expect(dao => dao.GetWatchedMoviesData()).Return(watchedMovies);

            var firstUserTitlesList = new List <string> {
                "User1Title1", "User1Title2"
            };
            var secondUserTitlesList = new List <string> {
                "User2Title1", "User2Title2"
            };

            var watcheMoviesStatisticService = new WatcheMoviesStatisticService(viewModelsRepositoryMock);

            //Act
            var resault = watcheMoviesStatisticService.GetData();

            //Assert
            Assert.AreEqual("User1", resault[0].UserEmail);
            CollectionAssert.AreEqual(firstUserTitlesList, resault[0].MovieTitles);
            Assert.AreEqual("User2", resault[1].UserEmail);
            CollectionAssert.AreEqual(secondUserTitlesList, resault[1].MovieTitles);
        }
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity <Users>()
        .HasMany(bc => bc.WatchedMovies)
        .WithOne(c => c.Users)
        .HasForeignKey(d => d.UsersId);

        modelBuilder.Entity <Users>()
        .HasMany(bc => bc.WatchLaterMovies)
        .WithOne(c => c.Users)
        .HasForeignKey(d => d.UsersId);

        string[] namesFile         = File.ReadAllLines("Nomes.csv");
        int      _id               = 0;
        Random   rdQtt             = new Random(12541);
        int      iWatchedMoviesId  = 0;
        int      iWatchLaterMovies = 0;

        foreach (string nameLine in namesFile)
        {
            _id++;

            Users user = new Users();
            user.Name    = nameLine;
            user.UsersId = _id;

            modelBuilder.Entity <Users>().HasData(
                user
                );

            int moviesWatched = rdQtt.Next(1, 25);
            List <WatchedMovies> lstWatched = new List <WatchedMovies>();
            for (int i = 1; i <= moviesWatched; i++)
            {
                iWatchedMoviesId++;
                var watched = new WatchedMovies()
                {
                    WatchedMoviesId = iWatchedMoviesId,
                    UsersId         = _id,
                    MovieId         = rdQtt.Next(1, 9200),
                };

                lstWatched.Add(watched);
            }

            modelBuilder.Entity <WatchedMovies>().HasData(
                lstWatched
                );

            int moviesWatchLater = rdQtt.Next(1, 10);
            List <WatchLaterMovies> lstWatchLaterMovies = new List <WatchLaterMovies>();
            for (int i = 1; i <= moviesWatchLater; i++)
            {
                iWatchLaterMovies++;
                var watchLater = new WatchLaterMovies()
                {
                    WatchLaterMoviesId = iWatchLaterMovies,
                    UsersId            = _id,
                    MovieId            = rdQtt.Next(1, 9200),
                };

                lstWatchLaterMovies.Add(watchLater);
            }
            modelBuilder.Entity <WatchLaterMovies>().HasData(
                lstWatchLaterMovies
                );
        }
    }
示例#7
0
 public static void RemoveFromWatchedMovies(int movieId)
 {
     WatchedMovies.Remove(movieId);
     WatchedMovies = watchedMovies;
 }
示例#8
0
 public static void AddToWatchedMovies(int movieId)
 {
     WatchedMovies.Add(movieId);
     WatchedMovies = watchedMovies;
 }