コード例 #1
0
        public void GetSubscriberCount_NullUser_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 user = new VidconfileUser();

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

            string result = Assert.Throws <NullReferenceException>(() => userService.GetSubscriberCount(null))
                            .Message;

            Assert.Equal("user cannot be null", result);
        }
コード例 #2
0
        public void GetSubscriberCount_ShouldGet()
        {
            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 user = new VidconfileUser();

            Guid userId = Guid.NewGuid();

            user.Id = userId;

            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);

            int subs = userService.GetSubscriberCount(user);

            Assert.Equal(3, subs);
        }