Example #1
0
        public void EditProfile_ShouldUpdate()
        {
            var videoRepositoryMock       = new Mock <IRepository <Video> >();
            var unitOfWorkMock            = new Mock <IUnitOfWork>();
            var commentRepositoryMock     = new Mock <IRepository <Comment> >();
            var userRepositoryMock        = new Mock <IRepository <VidconfileUser> >();
            var passwordHasherMock        = new Mock <IPasswordHasher>();
            var subscribeToSubscriberMock = new Mock <IRepository <SubscribeToSubscribers> >();

            Guid userId = Guid.NewGuid();

            VidconfileUser user = new VidconfileUser();

            string photoUrl = "asd";

            subscribeToSubscriberMock.Setup(x => x.All())
            .Returns(new List <SubscribeToSubscribers>()
            {
                new SubscribeToSubscribers()
                {
                    SubscribedToId = userId
                },
                new SubscribeToSubscribers()
                {
                    SubscribedToId = userId
                }, new SubscribeToSubscribers()
                {
                    SubscribedToId = userId
                }
            }.AsQueryable());

            VidconfileUserServices userService =
                new VidconfileUserServices(userRepositoryMock.Object, unitOfWorkMock.Object, passwordHasherMock.Object,
                                           videoRepositoryMock.Object, subscribeToSubscriberMock.Object);

            userService.EditProfile(user, photoUrl);

            Assert.Equal(photoUrl, user.ProfilePhotoUrl);
            userRepositoryMock.Verify(x => x.Update(user), Times.Once);
            unitOfWorkMock.Verify(x => x.Commit(), Times.Once);
        }
Example #2
0
        public void EditProfile_PhotoNull_ShouldThrow()
        {
            var videoRepositoryMock       = new Mock <IRepository <Video> >();
            var unitOfWorkMock            = new Mock <IUnitOfWork>();
            var commentRepositoryMock     = new Mock <IRepository <Comment> >();
            var userRepositoryMock        = new Mock <IRepository <VidconfileUser> >();
            var passwordHasherMock        = new Mock <IPasswordHasher>();
            var subscribeToSubscriberMock = new Mock <IRepository <SubscribeToSubscribers> >();

            Guid userId = Guid.NewGuid();

            VidconfileUser user = new VidconfileUser();

            string photoUrl = "asd";

            subscribeToSubscriberMock.Setup(x => x.All())
            .Returns(new List <SubscribeToSubscribers>()
            {
                new SubscribeToSubscribers()
                {
                    SubscribedToId = userId
                },
                new SubscribeToSubscribers()
                {
                    SubscribedToId = userId
                }, new SubscribeToSubscribers()
                {
                    SubscribedToId = userId
                }
            }.AsQueryable());

            VidconfileUserServices userService =
                new VidconfileUserServices(userRepositoryMock.Object, unitOfWorkMock.Object, passwordHasherMock.Object,
                                           videoRepositoryMock.Object, subscribeToSubscriberMock.Object);

            string msg = Assert.Throws <NullReferenceException>(() => userService.EditProfile(user, null))
                         .Message;

            Assert.Equal("newProfilePhotoUrl cannot be null", msg);
        }