public HallsControllerTests()
 {
     context    = new UnitTestSportHallContext();
     controller = new HallsController(context.Repo.Object, new Mock <IActivityRepository>().Object);
 }
Exemplo n.º 2
0
        public HallsControllerTests()
        {
            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)));

            mockRepo.Setup(repo => repo.CreateAsync(It.IsAny <Hall>()))
            .Callback((Hall hall) =>
            {
                _halls.Add(hall);
            });

            mockRepo.Setup(repo => repo.UpdateAsync(It.IsAny <string>(), It.IsAny <Hall>()))
            .Callback((string id, Hall hallIn) =>
            {
                var hall     = _halls.FirstOrDefault(h => h.Id.Equals(id));
                hall.TitleBe = hallIn.TitleBe;
                hall.TitleEn = hallIn.TitleEn;
                hall.TitleRu = hallIn.TitleRu;
                hall.Stands  = hallIn.Stands;
            });

            mockRepo.Setup(repo => repo.RemoveAsync(It.IsAny <string>()))
            .Callback((string id) =>
            {
                var hall = _halls.FirstOrDefault(h => h.Id.Equals(id));
                _halls.Remove(hall);
            });

            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);
            _hallsController = new HallsController(mockRepo.Object, _service, new CompareService());

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