示例#1
0
        public void DeleteHallShouldThrowIfInvalidId()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            Assert.Throws <ArgumentNullException>(() => service.DeleteAsync(1).GetAwaiter().GetResult());
        }
 public static HallsService GetService()
 {
     if (hallsService == null)
     {
         hallsService = new HallsServiceImpl();
     }
     return(hallsService);
 }
示例#3
0
        public async Task AddHallShouldAddCorrectCount()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            await service.AddAsync(this.hall);

            Assert.Equal(1, repository.All().Count());
        }
示例#4
0
        public void GetByIdShouldReturnNullIfInvalidId()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            var result = service.GetById <TestHallViewModel>(2);

            Assert.Null(result);
        }
示例#5
0
        public void GetAllShouldReturnEmptyList()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            var result = service.GetAll <TestHallViewModel>();

            Assert.Empty(result);
        }
示例#6
0
        public async Task AddHallShouldAddCorrectData()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            await service.AddAsync(this.hall);

            var dbHall = await repository.GetByIdWithDeletedAsync(1);

            Assert.Equal(ProjectionType.TwoD, dbHall.ProjectionType);
            Assert.Equal(50, dbHall.Seats.Count());
        }
示例#7
0
        public async Task DeleteHallShouldWorkCorrectly()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            await service.AddAsync(this.hall);

            await service.DeleteAsync(1);

            var dbHall = await repository.GetByIdWithDeletedAsync(1);

            Assert.True(dbHall.IsDeleted);
        }
示例#8
0
        public async Task GetAllShouldReturnCorrectData()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            await service.AddAsync(this.hall);

            await service.AddAsync(this.hall);

            var result = service.GetAll <TestHallViewModel>();

            Assert.Equal(2, result.Count());
            Assert.Equal(ProjectionType.TwoD, result.FirstOrDefault().ProjectionType);
        }
示例#9
0
        public async Task GetByIdShouldReturnCorrectData()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            var diffHall = new AddHallInputModel
            {
                ProjectionType = "FourDx",
                Seats          = 100,
            };

            await service.AddAsync(this.hall);

            await service.AddAsync(diffHall);

            var result = service.GetById <TestHallViewModel>(2);

            Assert.Equal(ProjectionType.FourDx, result.ProjectionType);
        }
示例#10
0
        public HallsServiceTests()
        {
            var         mockRepo      = new Mock <IHallsRepository>();
            var         mockRepoEmpty = new Mock <IHallsRepository>();
            List <Hall> _hallsEmpty   = new List <Hall>();

            _halls = new List <Hall>()
            {
                new Hall()
                {
                    Id      = "123456789012345678901234",
                    TitleBe = "Be",
                    TitleEn = "En",
                    TitleRu = "Ru",
                    Photo   = new PhotoInfo(),
                    Stands  = new List <Stand>()
                    {
                        new Stand()
                        {
                            Id            = "123456789012345678901111",
                            TitleRu       = "TitleRu",
                            TitleEn       = "TitleEn",
                            TitleBe       = "TitleBe",
                            DescriptionBe = "Be1",
                            DescriptionEn = "En",
                            DescriptionRu = "Ru1",
                            Photo         = new PhotoInfo(),
                            Exhibits      = new List <Exhibit>()
                            {
                                new Exhibit()
                                {
                                    Id      = "123456789012345678901212",
                                    TitleRu = "TitleRu",
                                    TitleEn = "TitleEn",
                                    TitleBe = "TitleBe",
                                    TextBe  = "Be1",
                                    TextEn  = "En1",
                                    TextRu  = "Ru1",
                                    Photos  = new List <PhotoInfo>()
                                },
                                new Exhibit()
                                {
                                    Id      = "123456789012345678901213",
                                    TitleRu = "TitleRu2",
                                    TitleEn = "TitleEn2",
                                    TitleBe = "TitleBe2",
                                    TextBe  = "Be12",
                                    TextEn  = "En2",
                                    TextRu  = "Ru12",
                                    Photos  = new List <PhotoInfo>()
                                }
                            }
                        },
                        new Stand()
                        {
                            Id            = "123456789012345678901112",
                            TitleRu       = "TitleRu",
                            TitleEn       = "TitleEn",
                            TitleBe       = "TitleBe",
                            DescriptionBe = "Be1",
                            DescriptionEn = "En",
                            DescriptionRu = "Ru1",
                            Photo         = new PhotoInfo(),
                            Exhibits      = new List <Exhibit>()
                            {
                                new Exhibit()
                                {
                                    Id      = "123456789012345678901313",
                                    TitleRu = "TitleRu3",
                                    TitleBe = "TitleBe3",
                                    TextBe  = "Be13",
                                    TextEn  = "En13",
                                    TextRu  = "Ru13",
                                    Photos  = new List <PhotoInfo>()
                                }
                            }
                        },
                        new Stand()
                        {
                            Id            = "123456789012345678903111",
                            TitleRu       = "TitleRu",
                            TitleEn       = "TitleEn",
                            TitleBe       = "TitleBe",
                            DescriptionBe = "Be1",
                            DescriptionEn = "En",
                            DescriptionRu = "Ru1",
                            Photo         = new PhotoInfo(),
                            Exhibits      = new List <Exhibit>()
                            {
                                new Exhibit()
                                {
                                    Id      = "123456789012345678901415",
                                    TitleRu = "TitleRu24",
                                    TitleEn = "TitleEn24",
                                    TitleBe = "TitleBe24",
                                    TextBe  = "Be124",
                                    TextRu  = "Ru124",
                                    Photos  = new List <PhotoInfo>()
                                }
                            }
                        },
                    }
                },
                new Hall()
                {
                    Id      = "123456789012345678901235",
                    TitleBe = "Be",
                    TitleEn = "En",
                    TitleRu = "Ru",
                    Photo   = new PhotoInfo(),
                    Stands  = new List <Stand>()
                }
            };
            mockRepo.Setup(repo =>
                           repo.GetAllAsync()).ReturnsAsync(()
                                                            => _halls.ToList());

            mockRepoEmpty.Setup(repo =>
                                repo.GetAllAsync()).ReturnsAsync(()
                                                                 => _hallsEmpty.ToList());

            mockRepo.Setup(repo =>
                           repo.GetAsync(It.IsAny <string>())).ReturnsAsync((string id)
                                                                            => _halls.FirstOrDefault(h => h.Id.Equals(id)));

            var mockRepoExhibit       = new Mock <IExhibitsRepository>();
            var mockRepoEmptyExhibits = new Mock <IExhibitsRepository>();

            mockRepoExhibit.Setup(repo =>
                                  repo.GetAllAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync((string hallId, string standId)
                                                                                                           => _halls.FirstOrDefault(h => h.Id.Equals(hallId)).Stands.FirstOrDefault(s => s.Id.Equals(standId)).Exhibits.ToList());

            mockRepoEmptyExhibits.Setup(repo =>
                                        repo.GetAllAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync((string hallId, string standId)
                                                                                                                 => _hallsEmpty.FirstOrDefault(h => h.Id.Equals(hallId)).Stands.FirstOrDefault(s => s.Id.Equals(standId)).Exhibits.ToList());

            mockRepoExhibit.Setup(repo =>
                                  repo.GetAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync((string hallId, string standId, string id)
                                                                                                                             => _halls.FirstOrDefault(h => h.Id.Equals(hallId)).Stands.FirstOrDefault(s => s.Id.Equals(standId)).Exhibits?.Where(e => e.Id.Equals(id)).FirstOrDefault());


            var mockRepoStands      = new Mock <IStandsRepository>();
            var mockRepoEmptyStands = new Mock <IStandsRepository>();

            mockRepoStands.Setup(repo =>
                                 repo.GetAllAsync(It.IsAny <string>())).ReturnsAsync((string hallId)
                                                                                     => _halls.FirstOrDefault(h => h.Id.Equals(hallId)).Stands.ToList());

            mockRepoEmptyStands.Setup(repo =>
                                      repo.GetAllAsync(It.IsAny <string>())).ReturnsAsync((string hallId)
                                                                                          => _hallsEmpty.FirstOrDefault(h => h.Id.Equals(hallId)).Stands.ToList());

            mockRepoStands.Setup(repo =>
                                 repo.GetAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync((string hallId, string id)
                                                                                                       => _halls.FirstOrDefault(h => h.Id.Equals(hallId)).Stands.Where(s => s.Id.Equals(id)).FirstOrDefault());

            mockRepo.SetupAllProperties();
            mockRepoEmpty.SetupAllProperties();

            _exhibitsService = new ExhibitsService(mockRepoExhibit.Object);
            _standsService   = new StandsService(mockRepoStands.Object, _exhibitsService);
            _service         = new HallsService(mockRepo.Object, _standsService);

            _exhibitsServiceEmptyRepo = new ExhibitsService(mockRepoEmptyExhibits.Object);
            _standsServiceEmptyRepo   = new StandsService(mockRepoEmptyStands.Object, _exhibitsServiceEmptyRepo);
            _serviceEmptyRepo         = new HallsService(mockRepoEmpty.Object, _standsServiceEmptyRepo);
        }