public void Get_By_Projection_Id_Return_Projection()
        {
            //Assert
            int expectedStatusCode = 200;

            ProjectionDomainModel projectionDomainModel = new ProjectionDomainModel
            {
                Id             = Guid.NewGuid(),
                AuditoriumName = "Auditorium123",
                AuditoriumId   = 2,
                MovieId        = Guid.NewGuid(),
                MovieTitle     = "Film",
                ProjectionTime = new DateTime()
            };

            Task <ProjectionDomainModel> responseTask = Task.FromResult(projectionDomainModel);

            _projectionService = new Mock <IProjectionService>();
            _projectionService.Setup(x => x.GetProjectionByIdAsync(It.IsAny <Guid>())).Returns(responseTask);
            ProjectionsController projectionsController = new ProjectionsController(_projectionService.Object);

            //Act
            var result      = projectionsController.GetById(projectionDomainModel.Id).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultValue = ((OkObjectResult)result).Value;
            var projectionDomainModelResult = (ProjectionDomainModel)resultValue;

            //Assert
            Assert.IsNotNull(projectionDomainModelResult);
            Assert.AreEqual(projectionDomainModel.Id, projectionDomainModelResult.Id);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
        }
        public void Get_By_Projection_Id_Return_Not_Found()
        {
            //Arrange
            int    expectedStatusCode = 404;
            string expectedMessage    = Messages.PROJECTION_DOES_NOT_EXIST;
            ProjectionDomainModel projectionDomainModel = null;


            Task <ProjectionDomainModel> responseTask = Task.FromResult(projectionDomainModel);

            _projectionService = new Mock <IProjectionService>();
            _projectionService.Setup(x => x.GetProjectionByIdAsync(It.IsAny <Guid>())).Returns(responseTask);
            ProjectionsController projectionsController = new ProjectionsController(_projectionService.Object);

            //Act
            var result          = projectionsController.GetById(Guid.NewGuid()).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultValue     = ((NotFoundObjectResult)result).Value;
            var messageReturned = (string)resultValue;

            //Assert
            Assert.IsNotNull(messageReturned);
            Assert.AreEqual(expectedMessage, messageReturned);
            Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult));
            Assert.AreEqual(expectedStatusCode, ((NotFoundObjectResult)result).StatusCode);
        }
        public async Task ReturnViewWithValidModel()
        {
            // Arrange
            var userManager = GetUserManagerMock();

            var projectionService = new Mock <IAdminProjectionService>();
            var movieServive      = new Mock <IAdminMovieService>();
            var themeService      = new Mock <IAdminThemeService>();

            var controller = new ProjectionsController(userManager.Object, projectionService.Object, movieServive.Object, themeService.Object);

            // Act
            var result = await controller.Create();

            // Assert
            result.Should().BeOfType <ViewResult>();

            var model = result.As <ViewResult>().Model;

            model.Should().BeOfType <AddProjectionFormModel>();

            var formModel = model.As <AddProjectionFormModel>();

            this.AssertLecturersSelectList(formModel.Lecturers);
        }
Beispiel #4
0
        public void PostAsync_With_UnValid_ProjectionDate_Return_BadRequest()
        {
            //Arrange
            string expectedMessage    = "Projection time cannot be in past.";
            int    expectedStatusCode = 400;

            CreateProjectionModel createProjectionModel = new CreateProjectionModel()
            {
                MovieId        = Guid.NewGuid(),
                ProjectionTime = DateTime.Now.AddDays(-1),
                AuditoriumId   = 0
            };

            _projectionService = new Mock <IProjectionService>();
            ProjectionsController projectionsController = new ProjectionsController(_projectionService.Object);

            //Act
            var result         = projectionsController.PostAsync(createProjectionModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultResponse = (BadRequestObjectResult)result;
            var createdResult  = ((BadRequestObjectResult)result).Value;
            var errorResponse  = ((SerializableError)createdResult).GetValueOrDefault(nameof(createProjectionModel.ProjectionTime));
            var message        = (string[])errorResponse;

            //Assert
            Assert.IsNotNull(resultResponse);
            Assert.AreEqual(expectedMessage, message[0]);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode);
        }
 public static ProjectionManagerNode Create(
     TFChunkDb db, QueuedHandler inputQueue, IHttpForwarder httpForwarder, HttpService[] httpServices, IPublisher networkSendQueue,
     IPublisher[] queues, RunProjections runProjections)
 {
     var projectionManagerNode = new ProjectionManagerNode(inputQueue, queues, runProjections);
     var projectionsController = new ProjectionsController(httpForwarder, inputQueue, networkSendQueue);
     foreach (var httpService in httpServices)
     {
         httpService.SetupController(projectionsController);
     }
     return projectionManagerNode;
 }
        public static void CreateManagerService(
            StandardComponents standardComponents,
            ProjectionsStandardComponents projectionsStandardComponents,
            IDictionary <Guid, IPublisher> queues,
            TimeSpan projectionQueryExpiry)
        {
            IQueuedHandler inputQueue   = projectionsStandardComponents.MasterInputQueue;
            InMemoryBus    outputBus    = projectionsStandardComponents.MasterOutputBus;
            var            ioDispatcher = new IODispatcher(outputBus, new PublishEnvelope(inputQueue));

            var projectionsController = new ProjectionsController(
                standardComponents.HttpForwarder,
                inputQueue,
                standardComponents.NetworkSendService);

            var forwarder = new RequestResponseQueueForwarder(
                inputQueue: projectionsStandardComponents.MasterInputQueue,
                externalRequestQueue: standardComponents.MainQueue);

            if (projectionsStandardComponents.RunProjections != ProjectionType.None)
            {
                foreach (var httpService in standardComponents.HttpServices)
                {
                    httpService.SetupController(projectionsController);
                }
            }

            var commandWriter = new MultiStreamMessageWriter(ioDispatcher);
            var projectionManagerCommandWriter  = new ProjectionManagerCommandWriter(commandWriter);
            var projectionManagerResponseReader = new ProjectionManagerResponseReader(outputBus, ioDispatcher,
                                                                                      queues.Count);

            var projectionManager = new ProjectionManager(
                inputQueue,
                outputBus,
                queues,
                new RealTimeProvider(),
                projectionsStandardComponents.RunProjections,
                ioDispatcher,
                projectionQueryExpiry);

            SubscribeMainBus(
                projectionsStandardComponents.MasterMainBus,
                projectionManager,
                projectionsStandardComponents.RunProjections,
                projectionManagerResponseReader,
                ioDispatcher,
                projectionManagerCommandWriter);


            SubscribeOutputBus(standardComponents, projectionsStandardComponents, forwarder);
        }
Beispiel #7
0
        public static ProjectionManagerNode Create(
            TFChunkDb db, QueuedHandler inputQueue, IHttpForwarder httpForwarder, HttpService[] httpServices, IPublisher networkSendQueue,
            IPublisher[] queues, RunProjections runProjections)
        {
            var projectionManagerNode = new ProjectionManagerNode(inputQueue, queues, runProjections);
            var projectionsController = new ProjectionsController(httpForwarder, inputQueue, networkSendQueue);

            foreach (var httpService in httpServices)
            {
                httpService.SetupController(projectionsController);
            }
            return(projectionManagerNode);
        }
        public static void CreateManagerService(
            StandardComponents standardComponents,
            ProjectionsStandardComponents projectionsStandardComponents,
            IDictionary<Guid, IPublisher> queues)
        {
            QueuedHandler inputQueue = projectionsStandardComponents.MasterInputQueue;
            InMemoryBus outputBus = projectionsStandardComponents.MasterOutputBus;
            var ioDispatcher = new IODispatcher(outputBus, new PublishEnvelope(inputQueue));

            var projectionsController = new ProjectionsController(
                standardComponents.HttpForwarder,
                inputQueue,
                standardComponents.NetworkSendService);

            var forwarder = new RequestResponseQueueForwarder(
                inputQueue: projectionsStandardComponents.MasterInputQueue,
                externalRequestQueue: standardComponents.MainQueue);

            if (projectionsStandardComponents.RunProjections != ProjectionType.None)
            {
                foreach (var httpService in standardComponents.HttpServices)
                {
                    httpService.SetupController(projectionsController);
                }
            }

            var commandWriter = new MultiStreamMessageWriter(ioDispatcher);
            var projectionManagerCommandWriter = new ProjectionManagerCommandWriter(commandWriter);
            var projectionManagerResponseReader = new ProjectionManagerResponseReader(outputBus, ioDispatcher, queues.Count);

            var projectionManager = new ProjectionManager(
                inputQueue,
                outputBus,
                queues,
                new RealTimeProvider(),
                projectionsStandardComponents.RunProjections,
                ioDispatcher);

            SubscribeMainBus(
                projectionsStandardComponents.MasterMainBus,
                projectionManager,
                projectionsStandardComponents.RunProjections,
                projectionManagerResponseReader,
                ioDispatcher,
                projectionManagerCommandWriter);


            SubscribeOutputBus(standardComponents, projectionsStandardComponents, forwarder);
        }
        public async Task And_Exception_Then_Returns_Bad_Request(
            long accountId,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] ProjectionsController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetAccountProjectionSummaryQuery>(),
                       It.IsAny <CancellationToken>()))
            .Throws <InvalidOperationException>();

            var controllerResult = await controller.GetAccountProjectionSummary(accountId) as BadRequestResult;

            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
Beispiel #10
0
        public void PostAsync_Create_Throw_DbException_Projection()
        {
            //Arrange
            string expectedMessage    = "Inner exception error message.";
            int    expectedStatusCode = 400;

            CreateProjectionModel createProjectionModel = new CreateProjectionModel()
            {
                MovieId        = Guid.NewGuid(),
                ProjectionTime = DateTime.Now.AddDays(1),
                AuditoriumId   = 1
            };
            CreateProjectionResultModel createProjectionResultModel = new CreateProjectionResultModel
            {
                Projection = new ProjectionDomainModel
                {
                    Id             = Guid.NewGuid(),
                    AuditoriumName = "ImeSale",
                    AuditoriumId   = createProjectionModel.AuditoriumId,
                    MovieId        = createProjectionModel.MovieId,
                    MovieTitle     = "ImeFilma",
                    ProjectionTime = createProjectionModel.ProjectionTime
                },
                IsSuccessful = true
            };
            Task <CreateProjectionResultModel> responseTask = Task.FromResult(createProjectionResultModel);
            Exception         exception         = new Exception("Inner exception error message.");
            DbUpdateException dbUpdateException = new DbUpdateException("Error.", exception);

            _projectionService = new Mock <IProjectionService>();
            _projectionService.Setup(x => x.CreateProjection(It.IsAny <ProjectionDomainModel>())).Throws(dbUpdateException);
            ProjectionsController projectionsController = new ProjectionsController(_projectionService.Object);

            //Act
            var result          = projectionsController.PostAsync(createProjectionModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultResponse  = (BadRequestObjectResult)result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(resultResponse);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode);
        }
Beispiel #11
0
        public void PostAsync_Create_createProjectionResultModel_IsSuccessful_False_Return_BadRequest()
        {
            //Arrange
            string expectedMessage    = "Error occured while creating new projection, please try again.";
            int    expectedStatusCode = 400;

            CreateProjectionModel createProjectionModel = new CreateProjectionModel()
            {
                MovieId        = Guid.NewGuid(),
                ProjectionTime = DateTime.Now.AddDays(1),
                AuditoriumId   = 1
            };
            CreateProjectionResultModel createProjectionResultModel = new CreateProjectionResultModel
            {
                Projection = new ProjectionDomainModel
                {
                    Id             = Guid.NewGuid(),
                    AuditoriumName = "ImeSale",
                    AuditoriumId   = createProjectionModel.AuditoriumId,
                    MovieId        = createProjectionModel.MovieId,
                    MovieTitle     = "ImeFilma",
                    ProjectionTime = createProjectionModel.ProjectionTime
                },
                IsSuccessful = false,
                ErrorMessage = Messages.PROJECTION_CREATION_ERROR,
            };
            Task <CreateProjectionResultModel> responseTask = Task.FromResult(createProjectionResultModel);


            _projectionService = new Mock <IProjectionService>();
            _projectionService.Setup(x => x.CreateProjection(It.IsAny <ProjectionDomainModel>())).Returns(responseTask);
            ProjectionsController projectionsController = new ProjectionsController(_projectionService.Object);

            //Act
            var result          = projectionsController.PostAsync(createProjectionModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultResponse  = (BadRequestObjectResult)result;
            var badObjectResult = ((BadRequestObjectResult)result).Value;
            var errorResult     = (ErrorResponseModel)badObjectResult;

            //Assert
            Assert.IsNotNull(resultResponse);
            Assert.AreEqual(expectedMessage, errorResult.ErrorMessage);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.AreEqual(expectedStatusCode, resultResponse.StatusCode);
        }
Beispiel #12
0
        public void TestViewModelForAvailableMovies()
        {
            var mockProjectionService = new Mock <IProjectionsService>();
            var mockMovieService      = new Mock <IMoviesService>();
            var mockCinemaService     = new Mock <ICinemaService>();

            mockProjectionService.Setup(x => x.AllProjections <ProjectionViewModel>())
            .Returns(this.ProjectionsViewModelData());

            var controller = new ProjectionsController(
                mockProjectionService.Object,
                mockMovieService.Object,
                mockCinemaService.Object);

            var result = controller.All();

            Assert.IsAssignableFrom <IActionResult>(result);
        }
Beispiel #13
0
        public void PostAsync_Create_createProjectionResultModel_IsSuccessful_True_Projection()
        {
            //Arrange
            int expectedStatusCode = 201;

            CreateProjectionModel createProjectionModel = new CreateProjectionModel()
            {
                MovieId        = Guid.NewGuid(),
                ProjectionTime = DateTime.Now.AddDays(1),
                AuditoriumId   = 1
            };
            CreateProjectionResultModel createProjectionResultModel = new CreateProjectionResultModel
            {
                Projection = new ProjectionDomainModel
                {
                    Id             = Guid.NewGuid(),
                    AuditoriumName = "ImeSale",
                    AuditoriumId   = createProjectionModel.AuditoriumId,
                    MovieId        = createProjectionModel.MovieId,
                    MovieTitle     = "ImeFilma",
                    ProjectionTime = createProjectionModel.ProjectionTime
                },
                IsSuccessful = true
            };
            Task <CreateProjectionResultModel> responseTask = Task.FromResult(createProjectionResultModel);


            _projectionService = new Mock <IProjectionService>();
            _projectionService.Setup(x => x.CreateProjection(It.IsAny <ProjectionDomainModel>())).Returns(responseTask);
            ProjectionsController projectionsController = new ProjectionsController(_projectionService.Object);

            //Act
            var result                = projectionsController.PostAsync(createProjectionModel).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var createdResult         = ((CreatedResult)result).Value;
            var projectionDomainModel = (ProjectionDomainModel)createdResult;

            //Assert
            Assert.IsNotNull(projectionDomainModel);
            Assert.AreEqual(createProjectionModel.MovieId, projectionDomainModel.MovieId);
            Assert.IsInstanceOfType(result, typeof(CreatedResult));
            Assert.AreEqual(expectedStatusCode, ((CreatedResult)result).StatusCode);
        }
        public async Task Then_Gets_Summary_From_Mediator(
            GetAccountProjectionSummaryQueryResult mediatorResult,
            long accountId,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] ProjectionsController controller)
        {
            mockMediator
            .Setup(mediator => mediator.Send(
                       It.IsAny <GetAccountProjectionSummaryQuery>(),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(mediatorResult);

            var controllerResult = await controller.GetAccountProjectionSummary(accountId) as ObjectResult;

            Assert.IsNotNull(controllerResult);
            controllerResult.StatusCode.Should().Be((int)HttpStatusCode.OK);
            var model = controllerResult.Value as GetAccountProjectionSummaryResponse;

            Assert.IsNotNull(model);
            model.Should().BeEquivalentTo(mediatorResult);
        }
        public void GetAsync_Return_All_Projections()
        {
            //Arrange
            List <ProjectionDomainModel> projectionsDomainModelsList = new List <ProjectionDomainModel>();
            ProjectionDomainModel        projectionDomainModel       = new ProjectionDomainModel
            {
                Id             = Guid.NewGuid(),
                AuditoriumName = "ImeSale",
                AuditoriumId   = 1,
                MovieId        = Guid.NewGuid(),
                MovieTitle     = "ImeFilma",
                ProjectionTime = DateTime.Now.AddDays(1)
            };

            query = new ProjectionQuery();

            projectionsDomainModelsList.Add(projectionDomainModel);
            IEnumerable <ProjectionDomainModel>         projectionDomainModels = projectionsDomainModelsList;
            Task <IEnumerable <ProjectionDomainModel> > responseTask           = Task.FromResult(projectionDomainModels);
            int expectedResultCount = 1;
            int expectedStatusCode  = 200;

            _projectionService = new Mock <IProjectionService>();
            _projectionService.Setup(x => x.GetAllAsync(query)).Returns(responseTask);
            ProjectionsController projectionsController = new ProjectionsController(_projectionService.Object);

            //Act
            var result     = projectionsController.GetAsync(query).ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultList = ((OkObjectResult)result).Value;
            var projectionDomainModelResultList = (List <ProjectionDomainModel>)resultList;

            //Assert
            Assert.IsNotNull(projectionDomainModelResultList);
            Assert.AreEqual(expectedResultCount, projectionDomainModelResultList.Count);
            Assert.AreEqual(projectionDomainModel.Id, projectionDomainModelResultList[0].Id);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
        }
Beispiel #16
0
        public void GetAsync_Return_NewList()
        {
            //Arrange
            IEnumerable <ProjectionDomainModel>         projectionDomainModels = null;
            Task <IEnumerable <ProjectionDomainModel> > responseTask           = Task.FromResult(projectionDomainModels);
            int expectedResultCount = 0;
            int expectedStatusCode  = 200;

            _projectionService = new Mock <IProjectionService>();
            _projectionService.Setup(x => x.GetAllAsync()).Returns(responseTask);
            ProjectionsController projectionsController = new ProjectionsController(_projectionService.Object);

            //Act
            var result     = projectionsController.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult().Result;
            var resultList = ((OkObjectResult)result).Value;
            var projectionDomainModelResultList = (List <ProjectionDomainModel>)resultList;

            //Assert
            Assert.IsNotNull(projectionDomainModelResultList);
            Assert.AreEqual(expectedResultCount, projectionDomainModelResultList.Count);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode);
        }
Beispiel #17
0
        public async Task ReturnRedirectWithValidModel()
        {
            // Arrange
            var           dateValue       = DateTime.UtcNow.AddDays(10);
            const int     startTimeValue  = 20;
            const int     durationValue   = 120;
            const decimal priceValue      = 10.0m;
            const string  lecturerIdValue = "1";
            const int     movieIdValue    = 1;
            const int     themeIdValue    = 1;

            DateTime modelDate       = DateTime.UtcNow;
            int      modelStartTime  = 0;
            int      modelDuration   = 0;
            decimal  modelPrice      = 0;
            string   modelLecturerId = null;
            int      modelMovieId    = 0;
            int      modelThemeId    = 0;
            string   successMessage  = null;

            var projectionService = new Mock <IAdminProjectionService>();

            projectionService
            .Setup(p => p.Create(It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <decimal>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()))
            .Callback((DateTime date, int startTime, int duration, decimal price, string lecturerId, int movieId, int themeId) =>
            {
                modelDate       = date;
                modelStartTime  = startTime;
                modelDuration   = duration;
                modelPrice      = price;
                modelLecturerId = lecturerId;
                modelMovieId    = movieId;
                modelThemeId    = themeId;
            })
            .Returns(Task.CompletedTask);

            var tempData = new Mock <ITempDataDictionary>();

            tempData
            .SetupSet(t => t[WebConstants.TempDataSuccessMessageKey] = It.IsAny <string>())
            .Callback((string key, object message) => successMessage = message as string);

            var controller = new ProjectionsController(null, projectionService.Object, null, null);

            controller.TempData = tempData.Object;

            // Act
            var result = await controller.Create(new AddProjectionFormModel
            {
                Date       = dateValue,
                StartTime  = startTimeValue,
                Duration   = durationValue,
                Price      = priceValue,
                LecturerId = lecturerIdValue,
                MovieId    = movieIdValue,
                ThemeId    = themeIdValue
            });

            // Assert
            modelDate.Should().Be(dateValue);
            modelStartTime.Should().Be(startTimeValue);
            modelDuration.Should().Be(durationValue);
            modelPrice.Should().Be(priceValue);
            modelLecturerId.Should().Be(lecturerIdValue);
            modelMovieId.Should().Be(movieIdValue);
            modelThemeId.Should().Be(themeIdValue);

            successMessage.Should().Be("Projection created successfully.");

            result.Should().BeOfType <RedirectToActionResult>();

            result.As <RedirectToActionResult>().ActionName.Should().Be(nameof(ProjectionsController.Index));
            //result.As<RedirectToActionResult>().ControllerName.Should().Be(nameof(ProjectionsController));
            //result.As<RedirectToActionResult>().RouteValues.Keys.Should().Contain("area");
            //result.As<RedirectToActionResult>().RouteValues.Values.Should().Contain("Admin");
        }