public void TestIndex()
        {
            // Arrange
            ExhibitsController controller = new ExhibitsController(Scope.Resolve <ExhibitsService>());

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        public void TestDetails()
        {
            // Arrange
            ExhibitsController controller = new ExhibitsController(Scope.Resolve <ExhibitsService>());
            Exhibit            ex         = DbFactory.CreateExhibit();

            // Act
            ViewResult result = controller.Details(ex.ExhibitID) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Exemple #3
0
        public void Events_ReturnExhbitView()
        {
            // Arrange
            var dbContext  = _serviceProvider.GetRequiredService <ApplicationDbContext>();
            var controller = new ExhibitsController(dbContext);

            // Act
            var result = controller.Exhibits("exone");

            // Assert
            Assert.IsAssignableFrom <ViewResult>(result);
        }
Exemple #4
0
        public void Events_ReturnView_NotNull_ViewData_Notnull()
        {
            // Arrange
            var dbContext  = _serviceProvider.GetRequiredService <ApplicationDbContext>();
            var controller = new ExhibitsController(dbContext);

            // Act
            var result = controller.Exhibits("exone");

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.NotNull(viewResult.ViewData);
        }
Exemple #5
0
        public void Events_ReturnView_WithViewData()
        {
            // Arrange
            var dbContext  = _serviceProvider.GetRequiredService <ApplicationDbContext>();
            var controller = new ExhibitsController(dbContext);

            // Act
            var result = controller.Exhibits("exone");

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsAssignableFrom <ViewDataDictionary>(viewResult.ViewData);
            //Assert.Same("exone", viewResult.ViewData["key"]);
            //Assert.Same("Your contact page.", viewResult.ViewData["Message"]);
        }
Exemple #6
0
        public void Events_ReturnView_ViewData_CorrectValue()
        {
            // Arrange
            var dbContext  = _serviceProvider.GetRequiredService <ApplicationDbContext>();
            var controller = new ExhibitsController(dbContext);

            // Act
            var result = controller.Exhibits("exone");

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Same("exone", viewResult.ViewData["key"]);
            var data = viewResult.GetType();

            Console.WriteLine(data + " I'm here");
            //Assert.Same("Your contact page.", viewResult.ViewData["Message"]);
        }
Exemple #7
0
        public ExhibitsControllerTests()
        {
            var         mockRepo      = new Mock <IExhibitsRepository>();
            var         mockRepoEmpty = new Mock <IExhibitsRepository>();
            List <Hall> _hallsEmpty   = new List <Hall>()
            {
                new Hall()
                {
                    Id      = HallId,
                    TitleBe = "Be",
                    TitleEn = "En",
                    TitleRu = "Ru",
                    Stands  = new List <Stand>()
                    {
                        new Stand()
                        {
                            Id            = StandId,
                            TitleRu       = "TitleRu",
                            TitleEn       = "TitleEn",
                            TitleBe       = "TitleBe",
                            DescriptionBe = "Be1",
                            DescriptionEn = "En",
                            DescriptionRu = "Ru1",
                            Exhibits      = new List <Exhibit>()
                        }
                    }
                }
            };

            _halls = new List <Hall>()
            {
                new Hall()
                {
                    Id      = HallId,
                    TitleBe = "Be",
                    TitleEn = "En",
                    TitleRu = "Ru",
                    Stands  = new List <Stand>()
                    {
                        new Stand()
                        {
                            Id            = StandId,
                            TitleRu       = "TitleRu",
                            TitleEn       = "TitleEn",
                            TitleBe       = "TitleBe",
                            DescriptionBe = "Be1",
                            DescriptionEn = "En",
                            DescriptionRu = "Ru1",
                            Exhibits      = new List <Exhibit>()
                            {
                                new Exhibit()
                                {
                                    Id      = "123456789012345678901212",
                                    TitleRu = "TitleRu",
                                    TitleEn = "TitleEn",
                                    TitleBe = "TitleBe",
                                    TextBe  = "Be1",
                                    TextEn  = "En1",
                                    TextRu  = "Ru1",
                                },
                                new Exhibit()
                                {
                                    Id      = "123456789012345678901213",
                                    TitleRu = "TitleRu2",
                                    TitleEn = "TitleEn2",
                                    TitleBe = "TitleBe2",
                                    TextBe  = "Be12",
                                    TextEn  = "En2",
                                    TextRu  = "Ru12",
                                }
                            }
                        },
                        new Stand()
                        {
                            Id            = "123456789012345678901112",
                            TitleRu       = "TitleRu",
                            TitleEn       = "TitleEn",
                            TitleBe       = "TitleBe",
                            DescriptionBe = "Be1",
                            DescriptionEn = "En",
                            DescriptionRu = "Ru1",
                            Exhibits      = new List <Exhibit>()
                            {
                                new Exhibit()
                                {
                                    Id      = "123456789012345678901313",
                                    TitleRu = "TitleRu3",
                                    TitleBe = "TitleBe3",
                                    TextBe  = "Be13",
                                    TextEn  = "En13",
                                    TextRu  = "Ru13",
                                },
                                new Exhibit()
                                {
                                    Id      = "123456789012345678901415",
                                    TitleRu = "TitleRu24",
                                    TitleEn = "TitleEn24",
                                    TitleBe = "TitleBe24",
                                    TextBe  = "Be124",
                                    TextRu  = "Ru124",
                                }
                            }
                        }
                    }
                }
            };
            mockRepo.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());

            mockRepoEmpty.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());

            mockRepo.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());

            mockRepo.Setup(repo => repo.CreateAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Exhibit>()))
            .Callback((string hallId, string standId, Exhibit exhibit) =>
            {
                _halls.FirstOrDefault(h => h.Id.Equals(hallId)).Stands.FirstOrDefault(s => s.Id.Equals(standId)).Exhibits.Add(exhibit);
            })
            .ReturnsAsync(() => "123456789072345377401865");

            mockRepo.Setup(repo => repo.UpdateAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Exhibit>()))
            .Callback((string hallId, string standId, string id, Exhibit exhibitIn) =>
            {
                var exhibit = _halls.FirstOrDefault(h => h.Id.Equals(hallId)).Stands
                              .FirstOrDefault(s => s.Id.Equals(standId)).Exhibits
                              .FirstOrDefault(e => e.Id.Equals(id));
                exhibit.TextBe  = exhibitIn.TextBe;
                exhibit.TextEn  = exhibitIn.TextEn;
                exhibit.TextRu  = exhibitIn.TextRu;
                exhibit.TitleBe = exhibitIn.TitleBe;
                exhibit.TitleEn = exhibitIn.TitleEn;
                exhibit.TitleRu = exhibitIn.TitleRu;
            });

            mockRepo.Setup(repo => repo.RemoveAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Callback((string hallId, string standId, string id) =>
            {
                var exhibit = _halls.FirstOrDefault(h => h.Id.Equals(hallId)).Stands.FirstOrDefault(s => s.Id.Equals(standId)).Exhibits.FirstOrDefault(e => e.Id.Equals(id));
                _halls.FirstOrDefault(h => h.Id.Equals(hallId)).Stands
                .FirstOrDefault(s => s.Id.Equals(standId)).Exhibits.Remove(exhibit);
            });

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

            _service            = new ExhibitsService(mockRepo.Object);
            _exhibitsController = new ExhibitsController(mockRepo.Object, _service, new CompareService());

            _serviceEmptyRepo    = new ExhibitsService(mockRepoEmpty.Object);
            _exhibitsController2 = new ExhibitsController(mockRepoEmpty.Object, _serviceEmptyRepo, new CompareService());
        }