コード例 #1
0
        // Test DELETE for message
        public void MessagesController_Delete_ReturnsNoContentResult_WhenDeleted()
        {
            //Arrange
            int Id = 1;

            //Act
            var result           = controller.Delete(Id);
            var getDeletedResult = controller.Get(Id);

            //Assert
            Assert.IsType <NoContentResult>(result);
            Assert.IsType <NotFoundResult>(getDeletedResult);
        }
コード例 #2
0
ファイル: ApiTest.cs プロジェクト: dancoconetu/Messages
        public void DeleteReturnsNotFound()
        {
            MessagesController messagesController = new MessagesController();
            IHttpActionResult  deleteActionResult = messagesController.Delete(100);

            Assert.IsInstanceOfType(deleteActionResult, typeof(NotFoundResult));
        }
コード例 #3
0
        public async Task DeleteMessageTestAsync()
        {
            // Arrange
            var message1 = new Message()
            {
                MessageID   = Guid.Parse("11111111-1111-1111-1111-111111111111"),
                CreatedTime = new DateTime(2019, 06, 22),
                Text        = "Hello World"
            };
            var mock = new Mock <IMessageRepository>();

            mock.Setup(m => m.Find(message1.MessageID)).ReturnsAsync(message1);
            mock.Setup(m => m.Remove(message1));
            var controller = new MessagesController(mock.Object);

            // Act
            var result = (await controller.Delete(message1.MessageID));

            // Assert
            mock.Verify(m => m.Remove(It.Is <Message>(d => d == message1)));
            Assert.AreEqual(typeof(Microsoft.AspNetCore.Mvc.NoContentResult), result.GetType());
            var noContentResult = result as Microsoft.AspNetCore.Mvc.NoContentResult;

            Assert.AreEqual(204, noContentResult.StatusCode);
        }
コード例 #4
0
ファイル: ApiTest.cs プロジェクト: dancoconetu/Messages
        public void DeleteReturnsOk()
        {
            Message message = new Message()
            {
                Text = "Firsttime"
            };
            MessagesController messagesController = new MessagesController();
            IHttpActionResult  postActionResult   = messagesController.Post(message);
            var postCreatedResult = postActionResult as CreatedAtRouteNegotiatedContentResult <Message>;
            IHttpActionResult deleteActionResult = messagesController.Delete(postCreatedResult.Content.Id);

            Assert.IsInstanceOfType(deleteActionResult, typeof(OkResult));
        }
コード例 #5
0
        public async Task DeleteMessageNotFoundTestAsync()
        {
            // Arrange
            var messageID = Guid.NewGuid();
            var mock      = new Mock <IMessageRepository>();

            mock.Setup(m => m.Remove(messageID));
            var controller = new MessagesController(mock.Object);

            // Act
            var result = (await controller.Delete(messageID));

            // Assert
            Assert.AreEqual(typeof(Microsoft.AspNetCore.Mvc.NotFoundResult), result.GetType());
        }
コード例 #6
0
ファイル: ApiTest.cs プロジェクト: dancoconetu/Messages
        public void DeleteReturnsForbidden()
        {
            Message message = new Message()
            {
                Text = "Firsttime"
            };
            MessagesController messagesController = new MessagesController();
            IHttpActionResult  postActionResult   = messagesController.Post(message);
            var postCreatedResult = postActionResult as CreatedAtRouteNegotiatedContentResult <Message>;

            //changing the username of the message so no one else is allowed to change/delete it
            MessageCollection messageCollection = MessageCollection.GetInstace();

            messageCollection.Messages[postCreatedResult.Content.Id].Username = "******";

            IHttpActionResult deleteActionResult = messagesController.Delete(postCreatedResult.Content.Id);
            var deleteCreatedResult = deleteActionResult as StatusCodeResult;

            Assert.AreEqual(deleteCreatedResult.StatusCode, HttpStatusCode.Forbidden);
        }
コード例 #7
0
        public void DeleteMessage(int messageId, int statusCode, int messageUserId)
        {
            // Arrange
            messagesRepositoryMock.Setup(r => r.Find(1)).Returns(Task.FromResult(new Message()
            {
                Id = 1, Text = "Old text", UserId = messageUserId, DateCreate = DateTime.Now
            }));

            // Act
            var result = messagesController.Delete(1, 1).Result;

            // Assert
            if (statusCode == 200)
            {
                Assert.IsType <OkResult>(result);
            }
            else
            {
                Assert.NotNull(result);
                Assert.Equal(statusCode, (result as ObjectResult).StatusCode);
            }
        }
コード例 #8
0
        public void ApiDeleteSuccess()
        {
            var response = (OkResult)ApiController.Delete(2);

            Assert.AreEqual(200, response.StatusCode);
        }
コード例 #9
0
        public void Delete_Returns_HttpBadRequestWhenIdIsNull()
        {
            ActionResult result = _uut.Delete(null);

            Assert.IsInstanceOfType(result, typeof(HttpStatusCodeResult));
        }