示例#1
0
        public async void All_Not_Exists()
        {
            MessageControllerMockFacade mock = new MessageControllerMockFacade();

            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult <List <ApiMessageServerResponseModel> >(new List <ApiMessageServerResponseModel>()));
            MessageController controller = new MessageController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0, string.Empty);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiMessageServerResponseModel>;

            items.Should().BeEmpty();
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
示例#2
0
        public void AddWhenMessageIsValidShouldAddMessage()
        {
            var repository = Mock.Create <ITwsData>();

            var messageEntity = Entities.GetValidMessage();

            IList <Message> messageEntities = new List <Message>();

            messageEntities.Add(messageEntity);
            Mock.Arrange(() => repository.Messages.All())
            .Returns(() => messageEntities.AsQueryable());

            var userProvider = Mock.Create <IUserIdProvider>();

            var controller = new MessageController(repository, userProvider);

            var messageModels = controller.All(0);

            Assert.IsTrue(messageModels.Count() == 1);
            Assert.AreEqual(messageEntity.Text, messageModels.First().Text);
        }