Пример #1
0
        public void Context()
        {
            _httpRequestMock = new Mock<HttpRequestBase>();
            _httpContextMock = new Mock<HttpContextBase>();
            _httpHelperMock = new Mock<IHttpHelper>();
            _postedFileKeyCollectionMock = new Mock<HttpFileCollectionBase>();
            _postedfileMock = new Mock<HttpPostedFileBase>();
            _dessertVMMMock = new Mock<IDessertViewModelManager>();
            _pictureServiceMock = new Mock<IPictureService>();
            _dessertServiceMock = new Mock<IDessertService>();

            _tempPictureViewModel = new TempPictureViewModel
                                        {
                                            Name = TEMP_PIC_FILE_NAME,
                                            Uri = _tempPictureUrl,
                                            SavedFIlePath = TEMP_PIC_FILE_PATH,
                                            ImageType = "jpg"
                                        };

            //Mock System.Web.Request
            _httpContextMock.SetupGet(ctx => ctx.Request)
                .Returns(_httpRequestMock.Object);

            //Mock System.Web.Request.Files
            _httpRequestMock.SetupGet(req => req.Files)
                .Returns(_postedFileKeyCollectionMock.Object);

            //TODO: Add this block in test to find and delete old picture
            ////Mock wrapper over HttpContext.Current
            _httpHelperMock.Setup(hpr => hpr.ExistsInSession(TEMP_PIC_SESSION_KEY))
                .Returns(true);

            //Mock System.Web.Request.Files enumerator
            _postedFileKeyCollectionMock.Setup(keys => keys[0])
                .Returns(_postedfileMock.Object);

            //Mock System.Web.Request.Files.FileName
            _postedfileMock.SetupGet(file => file.FileName)
                .Returns(TEMP_PIC_FILE_NAME);

            _dessertVMMMock.Setup(vmm => vmm.UploadTempPicture(_postedfileMock.Object))
                .Returns(_tempPictureViewModel);
        }
 public AddDessertViewModel()
 {
     Name = string.Empty;
     Description = string.Empty;
     TempPicture = new TempPictureViewModel();
 }
Пример #3
0
        public void Context()
        {
            _testDessert = new Dessert
                               {
                                   ID = new Guid("ca5e0210-16ac-4383-82a7-01efcc651f06"),
                                   //TODO: Check to see if this needs validating
                                   //Picture = ,
                                   Name = "Test Dessert",
                                   Likes = 5,
                                   Dislikes = 2,
                                   Description = "A yummy tasty treat"
                               };

            _tempPictureViewModel = new TempPictureViewModel
                                        {
                                            Name = TEMP_PIC_FILE_NAME,
                                            SavedFIlePath = TEMP_PIC_FILE_PATH,
                                            ImageType = "jpg"
                                        };

            _testDessertViewModel = new DessertBoxViewModel
                                        {
                                            ID = new Guid("ca5e0210-16ac-4383-82a7-01efcc651f06"),
                                            //TODO: Check to see if this needs validating
                                            //Picture = ,
                                            Name = "Test Dessert",
                                            Likes = 5,
                                            Dislikes = 2,
                                            Description = "A yummy tasty treat"
                                        };

            _unitOfWorkMock = new Mock<IUnitOfWork>();
            _httpHelperMock = new Mock<IHttpHelper>();
            //TODO: Add test for when TempPictureViewModel already exists in session.
            _httpHelperMock.Setup(helper => helper.GetFromAppSession<TempPictureViewModel>(TEMP_PIC_SESSION_KEY))
                .Returns(_tempPictureViewModel);
            _dessertRepoMock = new Mock<IDessertRepository>();
            _pictureServiceMock = new Mock<IPictureService>();
            _dessertServiceMock = new Mock<IDessertService>();
            _dessertVMMMock = new Mock<IDessertViewModelManager>();
            File.Copy(@"C:\Projects\LikeMyDessert\Projects\LikeMyDessert.Tests\IntegrationTests\Content\Test Pic.jpg", TEMP_PIC_FILE_PATH, true);
        }
        public TempPictureViewModel UploadTempPicture(HttpPostedFileBase pictureFile)
        {
            //Check to see if the user already uploaded a picture:
            if (_httpHelper.ExistsInSession(TEMP_PIC_SESSION_KEY))
            {
                var oldPicViewModel = _httpHelper.GetFromAppSession<TempPictureViewModel>(TEMP_PIC_SESSION_KEY);
                if (oldPicViewModel != null && !string.IsNullOrWhiteSpace(oldPicViewModel.SavedFIlePath))
                {
                    File.Delete(oldPicViewModel.SavedFIlePath);
                }
            }

            var picName = pictureFile.FileName;
            var tempRelativePath = ConfigurationManager.AppSettings["TempDirectory"];
            var tempDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, tempRelativePath);
            var tempUri = "/" + Path.Combine(tempRelativePath, picName).Replace("\\", "/");
            var savedFilePath = Path.Combine(tempDirectory, picName);
            pictureFile.SaveAs(savedFilePath);

            var tempPic = new TempPictureViewModel
                              {
                                  Name = picName,
                                  Uri = tempUri,
                                  SavedFIlePath = savedFilePath,
                                  ImageType = "jpg"
                              };

            _httpHelper.AddToAppSession(TEMP_PIC_SESSION_KEY ,tempPic);

            return tempPic;
        }