Пример #1
0
        public void GetAllReturnsAllProjecitons()
        {
            // Arrange
            var projections = new List <FilmProjection>
            {
                new FilmProjection {
                    Id = "1"
                },
                new FilmProjection {
                    Id = "2"
                },
            }.AsQueryable();

            var mockSet = new Mock <DbSet <FilmProjection> >();

            mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.Provider).Returns(projections.Provider);
            mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.Expression).Returns(projections.Expression);
            mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.ElementType).Returns(projections.ElementType);
            mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.GetEnumerator()).Returns(projections.GetEnumerator());

            var mockContext = new Mock <CinemaDbContext>();

            mockContext.Setup(c => c.FilmProjections).Returns(mockSet.Object);
            mockContext.Setup(c => c.FilmProjections.FindAsync(It.IsAny <string>())).
            Returns(new ValueTask <FilmProjection>(projections.First()));

            var projectionBusiness = new FilmProjectionBusiness(mockContext.Object,
                                                                new EmailSender("TestAPIKey",
                                                                                "TestSender",
                                                                                "TestSenderName"));

            // Act
            var resultProjecitonsCount = projectionBusiness.GetAll().Count();

            // Assert
            Assert.AreEqual(projections.Count(), resultProjecitonsCount, "Doesn't return all projections from the database.");
        }
Пример #2
0
        public void GetAllReturnsAllProjecitonsMapped()
        {
            // Arrange
            var projections = new List <FilmProjection>
            {
                new FilmProjection
                {
                    Id     = "1",
                    Cinema = new Cinema
                    {
                        Name = "Best1", City = "Sliven", Country = "Bulgaria"
                    },
                    ProjectionType = ProjectionType._4D,
                    Date           = DateTime.Now,
                    Film           = new Film
                    {
                        FilmData = new FilmData {
                            Title = "FilmTitle"
                        }
                    }
                },
                new FilmProjection
                {
                    Id     = "2",
                    Cinema = new Cinema
                    {
                        Name = "Best2", City = "Sliven", Country = "Bulgaria"
                    },
                    ProjectionType = ProjectionType._4D,
                    Date           = DateTime.Now,
                    Film           = new Film
                    {
                        FilmData = new FilmData {
                            Title = "FilmNewTitle"
                        }
                    }
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <FilmProjection> >();

            mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.Provider).Returns(projections.Provider);
            mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.Expression).Returns(projections.Expression);
            mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.ElementType).Returns(projections.ElementType);
            mockSet.As <IQueryable <FilmProjection> >().Setup(m => m.GetEnumerator()).Returns(projections.GetEnumerator());

            var mockContext = new Mock <CinemaDbContext>();

            mockContext.Setup(c => c.FilmProjections).Returns(mockSet.Object);
            mockContext.Setup(c => c.FilmProjections.FindAsync(It.IsAny <string>())).
            Returns(new ValueTask <FilmProjection>(projections.First()));

            var projectionBusiness = new FilmProjectionBusiness(mockContext.Object,
                                                                new EmailSender("TestAPIKey",
                                                                                "TestSender",
                                                                                "TestSenderName"));
            var mapper = new Mapper();

            // Act
            var resultProjecitonsCount = projectionBusiness.GetAll(mapper.MapToProjectionCardViewModel).Count();

            // Assert
            Assert.AreEqual(projections.Count(), resultProjecitonsCount, "Doesn't return all projections data mapped.");
        }