public void Delete_Group_ReturnGroupID() { int?groupID = 5; var groups = new Groups() { GroupId = 5, GroupName = "C", GroupLength = 6 }; _mockRepo.Setup(d => d.Delete(groupID)).Returns(groups); var expectedModel = new Groups() { GroupId = groups.GroupId, GroupName = groups.GroupName, GroupLength = groups.GroupLength }; var actual = _controller.Delete(groupID); var actualModel = actual.Model as Groups; Assert.Equal(expectedModel.GroupId, actualModel.GroupId); Assert.Equal(expectedModel.GroupName, actualModel.GroupName); Assert.Equal(expectedModel.GroupLength, actualModel.GroupLength); }
public async Task DeleteGroup_RequiresPositiveId(int groupId) { var service = new Mock <IGroupService>(MockBehavior.Strict); var controller = new GroupsController(service.Object, Mapper.Instance); var result = await controller.Delete(groupId); Assert.IsTrue(result is BadRequestObjectResult); }
public async void Can_Delete_Group() { var model = new Model { Data = Utility.RandomString() }; //create the group object content = await(await _groupsController.Post(model)).GetContent(); // delete the group using the returned group id object result = await(await _groupsController.Delete((int)content.Get("id"))).GetContent(); Assert.Equal(MagicStrings.GroupDeleted, result); // what happens if the group doesnt exist? object result2 = await(await _groupsController.Delete(9999)).GetContent(); // not a lot - task will succeed, but nothing is actually deleted. does this matter? Assert.NotNull(result2); }
public async Task DeleteGroup_ReturnsOkWhenGroupIsDeleted() { var service = new Mock <IGroupService>(); service.Setup(x => x.DeleteGroup(2)) .Returns(Task.FromResult(true)) .Verifiable(); var controller = new GroupsController(service.Object, Mapper.Instance); var result = await controller.Delete(2); Assert.IsTrue(result is OkResult); service.VerifyAll(); }
public async Task DeleteGroup_ReturnsNotFoundWhenTheGroupFailsToDelete() { var service = new Mock <IGroupService>(); service.Setup(x => x.DeleteGroup(2)) .Returns(Task.FromResult(false)) .Verifiable(); var controller = new GroupsController(service.Object, Mapper.Instance); var result = await controller.Delete(2); Assert.IsTrue(result is NotFoundResult); service.VerifyAll(); }
public void DeleteGroup_NonExistingGroup_ReturnsBadRequest() { var groupId = 1; var groupServiceMock = new Mock <IGroupService>(); groupServiceMock.Setup(m => m.DeleteGroup(It.IsAny <int>())).Returns((int?)null); controller = new GroupsController(groupServiceMock.Object, Mock.Of <IExpenseService>()); var result = controller.Delete(groupId); Assert.IsTrue(result != null); Assert.IsInstanceOfType(result, typeof(BadRequestErrorMessageResult)); }