Exemple #1
0
        public void CallSaveAsMethodFromTheFile_Once_AndSetCorrectlyStatusMessage_WhenContentTypesAreValidAndContentLengthIsValid(int contentLength, string contentType)
        {
            var mockedAvatarUploadView         = new Mock <IAvatarUploadView>();
            var mockedAccountManagementService = new Mock <IAccountManagementService>();

            var mockedModel = new AvatarUploadModel();

            mockedAvatarUploadView.Setup(x => x.Model).Returns(mockedModel);

            var avatarUploadPresenter = new AvatarUploadPresenter(mockedAvatarUploadView.Object, mockedAccountManagementService.Object);
            var mockedFile            = new Mock <HttpPostedFileBase>();

            mockedFile.SetupGet(x => x.ContentType).Returns(contentType);
            mockedFile.SetupGet(x => x.ContentLength).Returns(contentLength);

            var args = new AvatarUploadEventArgs()
            {
                PostedFile = mockedFile.Object
            };

            mockedAvatarUploadView.Raise(x => x.EventUploadAvatar += null, args);

            string expectedMessage = "Аватарът е качен";

            mockedFile.Verify(x => x.SaveAs(It.IsAny <string>()), Times.Once());
            Assert.AreEqual(expectedMessage, mockedAvatarUploadView.Object.Model.StatusMessage);
        }
Exemple #2
0
        public void NotCallSaveAsMethodFromTheFile_AndSetStatusMessageCorrectly_WhenContentTypesAreInvalid(string contentType)
        {
            var mockedAvatarUploadView         = new Mock <IAvatarUploadView>();
            var mockedAccountManagementService = new Mock <IAccountManagementService>();

            var mockedModel = new AvatarUploadModel();

            mockedAvatarUploadView.Setup(x => x.Model).Returns(mockedModel);

            var avatarUploadPresenter = new AvatarUploadPresenter(mockedAvatarUploadView.Object, mockedAccountManagementService.Object);
            var mockedFile            = new Mock <HttpPostedFileBase>();

            mockedFile.SetupGet(x => x.ContentType).Returns(contentType);

            var args = new AvatarUploadEventArgs()
            {
                PostedFile = mockedFile.Object
            };

            mockedAvatarUploadView.Raise(x => x.EventUploadAvatar += null, args);

            var expectedMessage = "Моля изберете картинка с разширение .png, .jpg или .jpeg";

            mockedFile.Verify(x => x.SaveAs(It.IsAny <string>()), Times.Never());
            Assert.AreEqual(expectedMessage, mockedAvatarUploadView.Object.Model.StatusMessage);
        }
Exemple #3
0
        public void SetCorrectErrorMessage_WhenExceptionIsThrowsException(int validContentLength, string validContentType)
        {
            var mockedAvatarUploadView         = new Mock <IAvatarUploadView>();
            var mockedAccountManagementService = new Mock <IAccountManagementService>();

            var mockedModel = new AvatarUploadModel();

            mockedAvatarUploadView.Setup(x => x.Model).Returns(mockedModel);

            var avatarUploadPresenter = new AvatarUploadPresenter(mockedAvatarUploadView.Object, mockedAccountManagementService.Object);
            var mockedFile            = new Mock <HttpPostedFileBase>();

            mockedFile.SetupGet(x => x.ContentType).Returns(validContentType);
            mockedFile.SetupGet(x => x.ContentLength).Returns(validContentLength);

            var args = new AvatarUploadEventArgs()
            {
                PostedFile            = mockedFile.Object,
                LoggedUserUserName    = "******",
                UserAvatarUrl         = "~/path",
                AvatarStorateLocation = "/random"
            };

            mockedFile.Setup(x => x.SaveAs(args.AvatarStorateLocation)).Throws(new Exception());

            mockedAvatarUploadView.Raise(x => x.EventUploadAvatar += null, args);

            var expectedMessage = "Моля, опитайте отново!";

            Assert.AreSame(expectedMessage, mockedAvatarUploadView.Object.Model.StatusMessage);
        }
Exemple #4
0
        public void NotCall_UploadAvatar_FromAccountManagementServiceOnceWhenContentTypeOrContentLengthInAreValid(int contentLength, string contentType)
        {
            var mockedAvatarUploadView         = new Mock <IAvatarUploadView>();
            var mockedAccountManagementService = new Mock <IAccountManagementService>();

            var mockedModel = new AvatarUploadModel();

            mockedAvatarUploadView.Setup(x => x.Model).Returns(mockedModel);

            var avatarUploadPresenter = new AvatarUploadPresenter(mockedAvatarUploadView.Object, mockedAccountManagementService.Object);
            var mockedFile            = new Mock <HttpPostedFileBase>();

            mockedFile.SetupGet(x => x.ContentType).Returns(contentType);
            mockedFile.SetupGet(x => x.ContentLength).Returns(contentLength);

            var args = new AvatarUploadEventArgs()
            {
                PostedFile         = mockedFile.Object,
                LoggedUserUserName = "******",
                UserAvatarUrl      = "~/path"
            };

            mockedAvatarUploadView.Raise(x => x.EventUploadAvatar += null, args);

            mockedAccountManagementService.Verify(x => x.UploadAvatar(args.LoggedUserUserName, args.UserAvatarUrl), Times.Never());
        }
Exemple #5
0
        public void AtachUserAvatarUrlToTheModel(string userName, string userAvatarUrl)
        {
            var mockedAvatarUploadView         = new Mock <IAvatarUploadView>();
            var mockedAccountManagementService = new Mock <IAccountManagementService>();

            var mockedModel = new AvatarUploadModel();

            mockedAvatarUploadView.Setup(x => x.Model).Returns(mockedModel);
            mockedAccountManagementService.Setup(x => x.GetUserAvatarUrl(userName)).Returns(userAvatarUrl);

            var avatarUploadPresenter = new AvatarUploadPresenter(mockedAvatarUploadView.Object, mockedAccountManagementService.Object);
            var eventArgs             = new GetUserAvatarEventArgs()
            {
                LoggedUseUserName = userName
            };

            mockedAvatarUploadView.Raise(x => x.EventGetUserAvatar += null, eventArgs);

            Assert.AreEqual(userAvatarUrl, mockedAvatarUploadView.Object.Model.UserAvatarUrl);
        }
Exemple #6
0
        public void NotCallCallSaveAsMethodFromTheFile_WhenContentTypesAreValidButContentLengthIsInvalid(int contentLength, string contentType)
        {
            var mockedAvatarUploadView         = new Mock <IAvatarUploadView>();
            var mockedAccountManagementService = new Mock <IAccountManagementService>();

            var mockedModel = new AvatarUploadModel();

            mockedAvatarUploadView.Setup(x => x.Model).Returns(mockedModel);

            var avatarUploadPresenter = new AvatarUploadPresenter(mockedAvatarUploadView.Object, mockedAccountManagementService.Object);
            var mockedFile            = new Mock <HttpPostedFileBase>();

            mockedFile.SetupGet(x => x.ContentType).Returns(contentType);
            mockedFile.SetupGet(x => x.ContentLength).Returns(contentLength);

            var args = new AvatarUploadEventArgs()
            {
                PostedFile = mockedFile.Object
            };

            mockedAvatarUploadView.Raise(x => x.EventUploadAvatar += null, args);

            mockedFile.Verify(x => x.SaveAs(It.IsAny <string>()), Times.Never());
        }