public void Set_Model_IsSuccesfull_Property_Correctly()
        {
            var mockedView = new Mock <ICreatingSubjectView>();
            var mockedsubjectManagementService = new Mock <ISubjectManagementService>();

            var model            = new CreatingSubjcetModel();
            var mockedAvatarFile = new Mock <HttpPostedFileBase>();

            var args = new CreatingSubjectEventArgs()
            {
                AvatarFile = mockedAvatarFile.Object,
                SubjectPictureStoragePath = "store path"
            };

            var presenter = new CreatingSubjectPresenter(
                mockedView.Object,
                mockedsubjectManagementService.Object);

            var expected = true;

            mockedView.SetupGet(x => x.Model).Returns(model);
            mockedsubjectManagementService
            .Setup(x => x.CreateSubject(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(expected);

            mockedView.Raise(x => x.EventCreateSubject += null, args);

            Assert.AreEqual(expected, mockedView.Object.Model.IsSuccesfull);
        }
        public void Call_SaveAs_Method_FromTheFile_Once()
        {
            var mockedView = new Mock <ICreatingSubjectView>();
            var mockedsubjectManagementService = new Mock <ISubjectManagementService>();

            var model            = new CreatingSubjcetModel();
            var mockedAvatarFile = new Mock <HttpPostedFileBase>();

            var args = new CreatingSubjectEventArgs()
            {
                AvatarFile = mockedAvatarFile.Object,
                SubjectPictureStoragePath = "store path"
            };

            var presenter = new CreatingSubjectPresenter(
                mockedView.Object,
                mockedsubjectManagementService.Object);

            mockedView.SetupGet(x => x.Model).Returns(model);
            mockedsubjectManagementService
            .Setup(x => x.CreateSubject(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(It.IsAny <bool>);

            mockedView.Raise(x => x.EventCreateSubject += null, args);

            mockedAvatarFile.Verify(x => x.SaveAs(It.IsAny <string>()), Times.Once());
        }
        protected void AddSubjectBtn_Click(object sender, EventArgs e)
        {
            if (this.SubjectPicture.HasFile)
            {
                var subjectAvatarFile = this.SubjectPicture.PostedFile;

                HttpPostedFileWrapper file = new HttpPostedFileWrapper(subjectAvatarFile);

                string extension   = Path.GetExtension(file.FileName);
                string subjectName = this.SubjectNameTextBox.Text;

                string filename = subjectName + extension;

                string subjectPictureStoragePath = Server.MapPath("~/Images/subject_images/") + filename;
                string subjectPictureUrl         = "~/Images/subject_images/" + filename;

                var subj = new CreatingSubjectEventArgs()
                {
                    SubjectName = subjectName,
                    AvatarFile  = file,
                    SubjectPictureStoragePath = subjectPictureStoragePath,
                    SubjectPictureUrl         = subjectPictureUrl
                };

                this.EventCreateSubject(this, subj);

                if (this.Model.IsSuccesfull)
                {
                    this.Notifier.NotifySuccess("Предметът е създаден!");
                    this.SubjectNameTextBox.Text = string.Empty;
                }
                else
                {
                    this.Notifier.NotifyError("Възникна грешка! (Вероятно вече съществува предмет с такова име)");
                }
            }
            else
            {
                this.Notifier.NotifyError("Mоля, прикачете картинка на предмета!");
            }
        }
Exemplo n.º 4
0
        private void CreateSubject(object sender, CreatingSubjectEventArgs e)
        {
            e.AvatarFile.SaveAs(e.SubjectPictureStoragePath);

            this.View.Model.IsSuccesfull = this.subjectManagementService.CreateSubject(e.SubjectName, e.SubjectPictureUrl);
        }