public void Validate_NoFilesPosted_ModelStateErrorRegistered()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            viewModel.ContentFiles = new List<HttpPostedFileBase> { null };

            // Act
            var results = viewModel.Validate(null);

            // Assert
            results.Should().Contain(x => x.MemberNames.Contains("ContentFiles"));
        }
        public void UploadPost_TwoPostedFile_BothPostedFileStored()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            viewModel.ContentFiles = new List<HttpPostedFileBase>
                                     {
                                         CreateHttpPostedFile(),
                                         CreateHttpPostedFile()
                                     };

            // Act
            _controller.Upload(viewModel);

            // Assert
            _fileStorageManager.Package.Files.Should().HaveCount(2);
        }
        public void UploadPost_ThereIsEmptyPropertyStates_EmptyPropertyStatesSkiped()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            viewModel.PreviewContentFiles = new List<HttpPostedFileBase> {CreateHttpPostedFile()};
            viewModel.States = new Dictionary<int, string> {{1, string.Empty}, {2, "state3"}};

            // Act
            _controller.Upload(viewModel);

            // Assert
            _fileStorageManager.Package.PropertyStates.Single().Value.Should().Be("state3");
        }
        public void UploadPost_SinglePostedPreviewFile_PostedFileIsPreview()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            viewModel.PreviewContentFiles = new List<HttpPostedFileBase> {CreateHttpPostedFile()};

            // Act
            _controller.Upload(viewModel);

            // Assert
            _fileStorageManager.Package.Files.Single().IsPreview.Should().BeTrue();
        }
        public void UploadPost_SinglePostedContentFile_PostedFileStored()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            var httpPostedFile = CreateHttpPostedFile();
            viewModel.ContentFiles = new List<HttpPostedFileBase> {httpPostedFile};

            // Act
            _controller.Upload(viewModel);

            // Assert
            _fileStorageManager.Package.Files.Single().Name.Should().Be(httpPostedFile.FileName);
        }
        public void UploadPost_SinglePostedContentFile_ContentPackageStoredToDatabase()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            viewModel.ContentFiles = new List<HttpPostedFileBase> {CreateHttpPostedFile()};

            // Act
            _controller.Upload(viewModel);

            // Assert
            var result = _unitOfWork.GetRepository<ContentPackage>().Get();
            result.Should().HaveCount(3);
        }
        public void UploadPost_Simple_PriceOfPackageInitialized()
        {
            // Arrange
            var viewModel = new UploadViewModel {Price = 10};
            viewModel.PreviewContentFiles = new List<HttpPostedFileBase> {CreateHttpPostedFile()};

            // Act
            _controller.Upload(viewModel);

            // Assert
            _unitOfWork.GetRepository<ContentPackage>().Get().Last().Price.Should().Be(10);
        }
        public void UploadPost_Simple_OwnerOfPackageIsCurrentUser()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            viewModel.PreviewContentFiles = new List<HttpPostedFileBase> {CreateHttpPostedFile()};

            // Act
            _controller.Upload(viewModel);

            // Assert
            var package = _unitOfWork.GetRepository<ContentPackage>().Get().Last();
            package.Owner.Should().Be(_currentUser);
        }
        public void UploadPost_Simple_ContentFileHasSpecifiedStream()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            var stream = CreateInputStream();
            viewModel.PreviewContentFiles = new List<HttpPostedFileBase> {CreateHttpPostedFile(stream)};

            // Act
            _controller.Upload(viewModel);

            // Assert
            _fileStorageManager.Package.Files.Single().Stream.Should().Be(stream);
        }
        public void UploadPost_Simple_ContentFileHasSpecifiedFileName()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            viewModel.PreviewContentFiles = new List<HttpPostedFileBase>
                                            {
                                                CreateHttpPostedFile(filename: "filename")
                                            };

            // Act
            _controller.Upload(viewModel);

            // Assert
            _fileStorageManager.Package.Files.Single().Name.Should().Be("filename");
        }
        public void UploadPost_NewPropertyStates_NewPropertyStatesStoredToDatabase()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            viewModel.PreviewContentFiles = new List<HttpPostedFileBase> {CreateHttpPostedFile()};
            viewModel.States = new Dictionary<int, string> {{1, "newState"}};

            // Act
            _controller.Upload(viewModel);

            // Assert
            var result = _unitOfWork.GetRepository<PropertyState>().Get();
            result.Last().Value.Should().Be("newState");
        }
        public void UploadPost_NewPropertyStates_NewPropertyStatesHasInitializedIndex()
        {
            // Arrange
            var viewModel = new UploadViewModel();
            viewModel.PreviewContentFiles = new List<HttpPostedFileBase> {CreateHttpPostedFile()};
            viewModel.States = new Dictionary<int, string> {{1, "newState"}};

            // Act
            _controller.Upload(viewModel);

            // Assert
            var repositoryMock = _unitOfWork.GetRepository<ContentPackage>();
            repositoryMock.Get().Last().PropertyStates.Should().OnlyContain(x => x.Index != 0);
        }
Exemplo n.º 13
0
        public ActionResult Upload(UploadViewModel viewModel)
        {
            viewModel.Properties = UnitOfWork.GetRepository<Property>().Get();

            if (!ModelState.IsValid)
            {
                return View(viewModel);
            }

            var package = new ContentPackage();
            package.PropertyStates = new Collection<PropertyState>();
            package.Files = new Collection<ContentFile>();
            package.Description = viewModel.Description;
            package.Caption = viewModel.Caption;
            package.Price = viewModel.Price;
            package.Owner = CurrentUser;

            ImportFilesToPackage(package, viewModel.PreviewContentFiles, true);
            ImportFilesToPackage(package, viewModel.ContentFiles, false);

            var service = new PropertyStateService(UnitOfWork);
            var specifiedStates = viewModel.States.Where(pair => !string.IsNullOrEmpty(pair.Value));
            foreach (var pair in specifiedStates)
            {
                //получаем состояние или создаем новое если не существет
                var propertyState = service.GetState(pair.Key, pair.Value);
                if (propertyState == null)
                {
                    var property = UnitOfWork.GetRepository<Property>().GetByID(pair.Key);
                    propertyState = service.CreateState(property, pair.Value);
                }

                package.PropertyStates.Add(propertyState);
            }

            _fileStorageManager.Store(package);
            UnitOfWork.GetRepository<ContentPackage>().Insert(package);
            UnitOfWork.Save();

            return InformationView("Загрузка завершена",
                                   "Контент успешно загружен. Благодарим за использование нашего ресурса.",
                                   new ActionLinkInfo("Content", "Upload", "Вернуться"));
        }
Exemplo n.º 14
0
        public ViewResult Upload()
        {
            var viewModel = new UploadViewModel();
            viewModel.Properties = UnitOfWork.GetRepository<Property>().Get();

            return View(viewModel);
        }