コード例 #1
0
        public void SubscribeFromTo_ShouldSubscribe()
        {
            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 fromId = Guid.NewGuid();
            Guid toId   = Guid.NewGuid();

            VidconfileUser from = new VidconfileUser();
            VidconfileUser to   = new VidconfileUser();

            from.Id = fromId;
            to.Id   = toId;

            var sb = new SubscribeToSubscribers();

            sb.SubscribedToId = toId;
            sb.SubscriberId   = Guid.Empty;

            SubscribeToSubscribers res = null;

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

            subscribeToSubscriberMock.Setup(x => x.Add(It.IsAny <SubscribeToSubscribers>()))
            .Callback <SubscribeToSubscribers>(x => res = x)
            .Verifiable();

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

            userService.SubscribeFromTo(from, to);

            subscribeToSubscriberMock.Verify();
            unitOfWorkMock.Verify(x => x.Commit(), Times.Once);

            Assert.Equal(toId, res.SubscribedToId);
            Assert.Equal(fromId, res.SubscriberId);
        }
コード例 #2
0
        public void SubscribeFromTo_NullTo_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> >();

            VidconfileUser from = new VidconfileUser();
            VidconfileUser to   = new VidconfileUser();

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

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

            Assert.Equal("to cannot be null", msg);
        }
コード例 #3
0
        public void SubscribeFromTo_AlreadySubscribed_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 fromId = Guid.NewGuid();
            Guid toId   = Guid.NewGuid();

            VidconfileUser from = new VidconfileUser();
            VidconfileUser to   = new VidconfileUser();

            from.Id = fromId;
            to.Id   = toId;

            var sb = new SubscribeToSubscribers();

            sb.SubscribedToId = toId;
            sb.SubscriberId   = fromId;

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

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

            string msg = Assert.Throws <ArgumentException>(() => userService.SubscribeFromTo(from, to))
                         .Message;

            Assert.Equal("the user is already subscribed", msg);
        }