コード例 #1
0
        public async void TestSubscribeFunctionality()
        {
            UserManager <ApplicationUser> userManager = MockUserManager();

            var mockSubscribesService = new Mock <ISubscribesService>();

            mockSubscribesService.Setup(x => x.ManageUserSubsctibe(FirstTestUserId, SecondTestUserId, true))
            .ReturnsAsync(true);
            mockSubscribesService.Setup(x => x.ManageUserSubsctibe(FirstTestUserId, SecondTestUserId, false))
            .ReturnsAsync(false);

            SubscribesController controller = new SubscribesController(
                userManager,
                mockSubscribesService.Object).WithIdentity(FirstTestUserId, "TestUser");

            ActionResult <SubscribeResponseModel> result = await controller.Subscribe(null);

            Assert.IsType <BadRequestResult>(result.Result);

            result = await controller.Subscribe(new SubscribeInputModel()
            {
                UserId = SecondTestUserId,
                Follow = true,
            });

            Assert.True(result.Value.Result);

            result = await controller.Subscribe(new SubscribeInputModel()
            {
                UserId = SecondTestUserId,
                Follow = false,
            });

            Assert.False(result.Value.Result);
        }
コード例 #2
0
        public async void ValidateInputModel()
        {
            UserManager <ApplicationUser> userManager = MockUserManager();

            var mockSubscribesService = new Mock <ISubscribesService>();

            SubscribesController controller = new SubscribesController(
                userManager,
                mockSubscribesService.Object).WithIdentity(FirstTestUserId, "TestUser");

            ActionResult <SubscribeResponseModel> result = await controller.Subscribe(null);

            Assert.IsType <BadRequestResult>(result.Result);

            result = await controller.Subscribe(new SubscribeInputModel()
            {
                UserId = null,
                Follow = true,
            });

            Assert.IsType <BadRequestResult>(result.Result);

            result = await controller.Subscribe(new SubscribeInputModel()
            {
                UserId = FirstTestUserId,
                Follow = true,
            });

            Assert.IsType <BadRequestResult>(result.Result);
        }