コード例 #1
0
        public async Task Get_Subscriptions_Success()
        {
            // Arrange
            var fakeSubId  = 1;
            var fakeChatId = 1;
            var fakeSub    = GetSubscribeFake(fakeSubId, fakeChatId);
            List <Subscribe> fakeSubscribes = new List <Subscribe>()
            {
                fakeSub
            };

            _subscribeRepositoryMock.Setup(x => x.GetSubscribersAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(fakeSubscribes.Select(x => x.ChatId).ToList()));

            // Act
            var subController = new SubscribesController(
                _subscribeRepositoryMock.Object
                );

            var actionResult = await subController.GetSubscribersAsync(fakeSub.BotId);

            // Assert
            Assert.AreEqual((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.AreEqual((((ObjectResult)actionResult.Result).Value as List <int>), fakeSubscribes.Select(x => x.ChatId).ToList());
        }
コード例 #2
0
        public async Task Get_Subscriptions_With_LessOrZero_Id_Should_Return_Bad_Request()
        {
            // Arrange
            var fakeBotId     = 0;
            var fakeBotIdLess = -1;

            _subscribeRepositoryMock.Setup(x => x.GetSubscribersAsync(It.IsAny <int>()));

            // Act
            var subController = new SubscribesController(
                _subscribeRepositoryMock.Object
                );

            var actionResult     = (await subController.GetSubscribersAsync(fakeBotId)).Result as BadRequestResult;
            var actionResultLess = (await subController.GetSubscribersAsync(fakeBotIdLess)).Result as BadRequestResult;

            // Assert
            Assert.NotNull(actionResult);
            Assert.NotNull(actionResultLess);
        }
コード例 #3
0
        public async Task Get_Subscriptions_With_Empty_List_Success()
        {
            // Arrange
            var fakeBotId = 1;

            _subscribeRepositoryMock.Setup(x => x.GetSubscribersAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(new List <int>()));
            // Act
            var subController = new SubscribesController(
                _subscribeRepositoryMock.Object
                );

            var actionResult = await subController.GetSubscribersAsync(fakeBotId);

            // Assert
            Assert.AreEqual((actionResult.Result as OkObjectResult).StatusCode, (int)System.Net.HttpStatusCode.OK);
            Assert.IsEmpty(((ObjectResult)actionResult.Result).Value as List <int>);
        }