public void PostMessage() { var controller = new MessageController(); MessageModel message = new MessageModel { MessageContent = "test4" }; controller.Post(message); var result = controller.Get(); int maxID = (int)result.Max(msg => msg.ID); try { Assert.AreEqual(controller.Get(maxID).MessageContent, message.MessageContent); } catch (Exception) { throw; } finally { controller.Delete(maxID); } }
public void TestGet() { var controller = new MessageController(); var result = controller.Get(); Assert.AreEqual("Hello World!", result); }
public void TestGetName() { var controller = new MessageController(); var result = controller.Get("Jeff"); Assert.AreEqual("Hello Jeff!", result); }
public void GetTestHelper <T>() where T : class, IIdentifier { var repository = Mock.Create <IRepository>(); var messageToAdd = new Message() { Title = "testTitle", Content = "testContent", ChannelId = "43242342", CreatedDateTime = DateTime.Now.ToString(), Status = "add", Type = MessageTypes.Text }; IList <Message> messageEntities = new List <Message>(); messageEntities.Add(messageToAdd); Mock.Arrange <IQueryable <Message> >(() => repository.All <Message>(null)) .Returns(messages => messageEntities.AsQueryable()); var target = new MessageController(repository); var result = target.Get(); Assert.IsTrue(messageEntities.Count() == 1); Assert.AreEqual(messageToAdd.Title, messageEntities.First().Title); }
public void GetMessageTest() { var repository = Mock.Create <IRepository>(); var value = new Message() { Title = "testTitle", Content = "testContent", ChannelId = "43242342", CreatedDateTime = DateTime.Now.ToString(), Status = "add", Type = MessageTypes.Text, Id = "1235213432123" }; Mock.Arrange <Message>( () => repository.Find <Message>(m => m.Id == value.Id, null)) .IgnoreArguments() .Returns(value) .MustBeCalled(); var target = new MessageController(repository); var result = target.Get(value.Id); Assert.AreEqual(result.Id, value.Id); }
public void Should_GetMessageFunction_Return_SingleMessage() { //Arrange var _mockRepo = new Mock <IRepositoryWrapper>(); var _mockPrincipal = new Mock <IUserClaimsPrincipal>(); var _mockLogger = new Mock <ILoggerManager>(); var message = new MessageDetailVM() { Id = 1, UserName = "******", Text = "Hi There.", }; _mockRepo.Setup(x => x.Message.GetMessageWithDetailByIdAsync(message.Id)).ReturnsAsync(message); _mockPrincipal.Setup(x => x.GetUserName(It.IsAny <ClaimsPrincipal>())).Returns("admin"); _mockRepo.Setup(x => x.User.GetUserByUserNameAsync("admin")).ReturnsAsync(1); var controller = new MessageController(_mockRepo.Object, _mockLogger.Object, _mockPrincipal.Object); //Act var actual = controller.Get(message.Id); //Assert var actualUser = ((MessageDetailVM)(((OkObjectResult)actual.Result).Value)); Assert.Same(message, actualUser); Assert.Equal(message.Id, actualUser.Id); Assert.Equal(message.Text, actualUser.Text); }
public void Check_with_message_hi() { var controller = new MessageController(); var output = controller.Get("hi").Value; Assert.Equal("hello", output); }
public void Check_with_message_invalid() { var controller = new MessageController(); var output = controller.Get("h").Value; Assert.Equal("Invalid", output); }
/// <summary> ///A test for Get ///</summary> public void GetByIdTestHelper <T>() where T : class, IIdentifier { var repository = Mock.Create <IRepository>(); var messageToAdd = new Message() { Title = "testTitle", Content = "testContent", ChannelId = "43242342", CreatedDateTime = DateTime.Now.ToString(), Status = "add", Type = MessageTypes.Text, Id = "32432434242" }; IList <Message> messageEntities = new List <Message>(); messageEntities.Add(messageToAdd); //var any = ;//Arg.IsAny<Expression<Func<Message, bool>>>(); Mock.Arrange <Message>( () => repository.Find <Message>(m => m.Id == messageToAdd.Id, null)) .IgnoreArguments() .Returns(messageToAdd) .MustBeCalled(); var target = new MessageController(repository); var result = target.Get(messageToAdd.Id); Assert.AreEqual(messageToAdd.Id, result.Id); }
public void Get() { Message result = _controller.Get(); // Assert Assert.IsNotNull(result); Assert.AreEqual("Hello World", result.Msg); }
public void Get_EmptySet_ReturnsZero() { using (var store = Factory.GetStore()) { var controller = new MessageController(store); var result = controller.Get(); Assert.True(result.Count() == 0); } }
public void GetById_MissingId_ReturnsNull() { using (var store = Factory.GetStore()) { var controller = new MessageController(store); var result = controller.Get(100); Assert.True(result == null); } }
public void Get_WithData_RetursCorrectCount(int entityCount) { using (var store = Factory.GetStore()) { var controller = new MessageController(store); store.Save <Message>(GetEntities(entityCount)); var result = controller.Get(); Assert.True(result.Count() == entityCount); } }
public void Get_ReturnMessage_HelloWorld() { var expectedMessage = new Message("Hello World"); _messengerMock.Setup(x => x.GetMessage()).Returns(expectedMessage); Message actualMessage = _messageController.Get(); Assert.Equal(expectedMessage, actualMessage); }
public void ControllerTest() { string message = "Hello Word"; MessageController controller = new MessageController(); controller.Post(message); var result = controller.Get(); Assert.AreEqual(result, message); }
public void Get_ToTestStandardMessageResponse_RespondsWithMockedMessage() { // Arrange var attribTheMessage = new Mock <IConfigurationSection>(); attribTheMessage.Setup(c => c.Value).Returns("Test Value A"); var attribConnectionString = new Mock <IConfigurationSection>(); attribConnectionString.Setup(c => c.Value).Returns("Test Connection String A"); var attribSettingA = new Mock <IConfigurationSection>(); attribSettingA.Setup(c => c.Value).Returns("Test Value B"); var attribLegacyConnectionString = new Mock <IConfigurationSection>(); attribLegacyConnectionString.Setup(c => c.Value).Returns("Test Connection String B"); _config.Setup(c => c.GetSection("TheMessage")).Returns(attribTheMessage.Object); _config.Setup(c => c.GetSection("ANestedSetting:DatabaseConnection")).Returns(attribConnectionString.Object); _config.Setup(c => c.GetSection("SettingA")).Returns(attribSettingA.Object); _config.Setup(c => c.GetSection("ConnectionStrings:LegacyConnectionString")).Returns(attribLegacyConnectionString.Object); var controller = new MessageController(_logger.Object, _config.Object); // Act var response = controller.Get(); // Assert Assert.IsNotNull(response); try { var str = JsonConvert.SerializeObject(response); dynamic dynResponse = JsonConvert.DeserializeObject(str); Assert.IsNotNull(dynResponse.appSettings_json.message); Assert.AreEqual("Test Value A", dynResponse.appSettings_json.message.Value); Assert.IsNotNull(dynResponse.appSettings_json.connectionString); Assert.AreEqual("Test Connection String A", dynResponse.appSettings_json.connectionString.Value); Assert.IsNotNull(dynResponse.web_config.setting); Assert.AreEqual("Test Value B", dynResponse.web_config.setting.Value); Assert.IsNotNull(dynResponse.web_config.connectionString); Assert.AreEqual("Test Connection String B", dynResponse.web_config.connectionString.Value); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void GetById() { // Arrange MessageController controller = new MessageController(); // Act string result = controller.Get(); // Assert Assert.AreEqual("value", result); }
public void Get() { // Arrange MessageController controller = new MessageController(); // Act string result = controller.Get(); // Assert Assert.AreEqual("Hello World", result); }
public void Get() { // Arrange MessageController controller = new MessageController(); // Act var result = controller.Get(); // Assert Assert.IsNotNull(result); Assert.AreEqual("Hello World", result.text); }
public async Task GetAllMessages_ReturnsNotFound_WithZeroMessages() { const int count = 0; var fakeMessages = A.CollectionOfDummy <Message>(count).AsEnumerable(); var mockService = A.Fake <IMessageService>(); A.CallTo(() => mockService.GetAllAsync()).Returns(Task.FromResult(fakeMessages)); var controller = new MessageController(mockService); var actionResult = await controller.Get(); Assert.IsType <NotFoundResult>(actionResult.Result); }
public async Task GetMessageWithId_ReturnsNotFound_IfMessageNotExists() { const string recordId = "xxx"; Message message = null; var mockService = A.Fake <IMessageService>(); A.CallTo(() => mockService.GetByIdAsync(recordId)).Returns(message); var controller = new MessageController(mockService); var actionResult = await controller.Get(recordId); Assert.IsType <NotFoundResult>(actionResult.Result); }
public void ValuesController_FailedTest() { //Arrange var service = new Mock <IMessageService>(); service.Setup(o => o.GetMessage()).Throws(new Exception("test")); var sut = new MessageController(service.Object); //Act var actual = (ObjectResult)sut.Get().Result; //Assert Assert.Equal((int)HttpStatusCode.InternalServerError, actual.StatusCode); }
public void ValuesController_Test() { //Arrange var service = new Mock <IMessageService>(); service.Setup(o => o.GetMessage()).Returns("tests"); var expected = "tests"; var sut = new MessageController(service.Object); //Act var actual = (ObjectResult)sut.Get().Result; //Assert Assert.Equal(expected, actual.Value); Assert.Equal((int)HttpStatusCode.OK, actual.StatusCode); }
public async Task GetAllMessages_Returns_CorrectNumberOfMessages() { const int count = 3; var fakeMessages = A.CollectionOfDummy <Message>(count).AsEnumerable(); var mockService = A.Fake <IMessageService>(); A.CallTo(() => mockService.GetAllAsync()).Returns(Task.FromResult(fakeMessages)); var controller = new MessageController(mockService); var actionResult = await controller.Get(); var result = actionResult.Result as OkObjectResult; var returnMessages = result.Value as IEnumerable <Message>; Assert.Equal(count, returnMessages.Count()); }
public async void Get_Not_Exists() { MessageControllerMockFacade mock = new MessageControllerMockFacade(); mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiMessageServerResponseModel>(null)); 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.Get(default(int)); response.Should().BeOfType <StatusCodeResult>(); (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound); mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>())); }
public void MessageGetById() { Message message = SetUpMessageData(); SetUpController(controller, HttpMethod.Get); IHttpActionResult result = controller.Get(message.MessageId); var negResult = result as OkNegotiatedContentResult <MessageBase>; Assert.AreEqual(message.MessageId, negResult.Content.MessageId); Assert.AreEqual(message.ItemId, negResult.Content.ItemId); Assert.AreEqual(message.Text, negResult.Content.Text); //TODO: [Han] add test data to campare //Assert.AreEqual("2016-10-04T00:00:00", negResult.Content.time); //Assert.AreEqual(new User { }, negResult.Content.sender); //Assert.AreEqual(new User { }, negResult.Content.receiver); }
public async Task GetReturnsLogMessages() { //Arrange var fakeLogMessageResponse = new LogMessageResponse { Records = new List <RecordResponse>() { new RecordResponse { Id = Guid.NewGuid().ToString(), Field = new Field() { Id = "recTPWgTQaKlETabD", Message = "Test message summary", Summary = "Exceptiion occured at ...", ReceivedAt = DateTime.UtcNow }, CreatedTime = DateTime.UtcNow } }.ToArray() }; var mockLogMessageManager = new Mock <ILogMessageManager>(); mockLogMessageManager.Setup(x => x.GetLogMessagesAsync(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(fakeLogMessageResponse)); var mockLogger = new Mock <ILogger <MessageController> >(); var controller = new MessageController(mockLogMessageManager.Object, mockLogger.Object); //Act var result = await controller.Get("1", "Grid+view"); var okResult = result as OkObjectResult; //Assert Assert.IsInstanceOf(typeof(LogMessageResponse), okResult.Value); Assert.IsNotNull(okResult.Value); var response = okResult.Value as LogMessageResponse; Assert.AreEqual(fakeLogMessageResponse.Records.Length, response.Records.Length); Assert.AreEqual(200, okResult.StatusCode); }
public async Task GetMessageWithId_Returns_CorrectMessage() { const string recordId = "xxx"; var message = new Message() { Id = "1", Title = "Title", Text = "Text", ReceivedAt = DateTime.Now }; var mockService = A.Fake <IMessageService>(); A.CallTo(() => mockService.GetByIdAsync(recordId)).Returns(message); var controller = new MessageController(mockService); var actionResult = await controller.Get(recordId); var result = actionResult.Result as OkObjectResult; var resultValue = result.Value as Message; Assert.Equal(message.Id, resultValue.Id); Assert.Equal(message.Title, resultValue.Title); Assert.Equal(message.Text, resultValue.Text); Assert.Equal(message.ReceivedAt, resultValue.ReceivedAt); }
public async Task Get(string messageContent) { var service = new MessageService(new MemoryMessageRepository(), new MessageFactory()); var logger = new Mock <ILogger <MessageController> >(); var controller = new MessageController(logger.Object, service); // Act var response = await controller.Post(new MessageDto { MessageContent = messageContent }); var action = response as CreatedAtActionResult; var get = await controller.Get(); var result = get as OkObjectResult; Assert.That(result, Is.Not.Null); var messages = result.Value as IEnumerable <MessageDto>; Assert.That(messages.First().MessageContent, Is.EqualTo(messageContent)); }
public void Should_GetFunction_Return_AllMessages() { //Arrange List <MessageDetailVM> messages = new List <MessageDetailVM>(); messages.Add(new MessageDetailVM { Id = 1, UserName = "******", Text = "Hi There." }); messages.Add(new MessageDetailVM { Id = 2, UserName = "******", Text = "How are you?" }); var _mockRepo = new Mock <IRepositoryWrapper>(); var _mockPrincipal = new Mock <IUserClaimsPrincipal>(); var _mockLogger = new Mock <ILoggerManager>(); _mockRepo.Setup(x => x.Message.GetAllMessageWithDetailAsync(1)).ReturnsAsync(messages); _mockPrincipal.Setup(x => x.GetUserName(It.IsAny <ClaimsPrincipal>())).Returns("admin"); _mockRepo.Setup(x => x.User.GetUserByUserNameAsync("admin")).ReturnsAsync(1); var controller = new MessageController(_mockRepo.Object, _mockLogger.Object, _mockPrincipal.Object); //Act var actual = controller.Get(); //Assert var actualMessage = ((List <MessageDetailVM>)((ResponseVM)((OkObjectResult)actual).Value).Data); Assert.True(actualMessage.Count == 2); }
public void GetMessageTest() { var repository = Mock.Create<IRepository>(); var value = new Message() { Title = "testTitle", Content = "testContent", ChannelId = "43242342", CreatedDateTime = DateTime.Now.ToString(), Status = "add", Type = MessageTypes.Text, Id = "1235213432123" }; Mock.Arrange<Message>( () => repository.Find<Message>(m => m.Id == value.Id, null)) .IgnoreArguments() .Returns(value) .MustBeCalled(); var target = new MessageController(repository); var result = target.Get(value.Id); Assert.AreEqual(result.Id, value.Id); }