public async void MustReturnAllApis() { // Arrange var expectedApis = new Api[] { new Api { Name = "Testing Api 1" }, new Api { Name = "Testing Api 2" }, new Api { Name = "Testing Api 3" } }; ApiServiceMock .Setup(x => x.ReadAllAsync()) .ReturnsAsync(expectedApis); // Act var result = await ControllerToTest.ReadAllAsync(); // Assert var okResult = Assert.IsType <OkObjectResult>(result); Assert.Same(expectedApis, okResult.Value); }
public void ShowMock() { var userMock = new Mock <IPrincipal>(); userMock.Setup(p => p.IsInRole("admin")).Returns(true); userMock.SetupGet(p => p.Identity.Name).Returns("tester"); userMock.SetupGet(p => p.Identity.IsAuthenticated).Returns(true); var requestContext = new Mock <HttpRequestContext>(); requestContext.Setup(x => x.Principal).Returns(userMock.Object); var controller = new ControllerToTest() { RequestContext = requestContext.Object, Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; }