public async void AddClaim_Should_Call_RoleService_And_Return_Created() { // Arrange var role = Fixture.Create <RoleModel>(); var claim = Fixture.Create <ClaimModel>(); var serviceResult = Fixture.Create <ClaimModel>(); _mockRoleService.Setup(_ => _.AddClaimAsync(role.Id, claim)) .ReturnsAsync(serviceResult); const string link = "http://fakelink.com"; // Matcher for determining if route params match Func <Dictionary <string, object>, bool> routeDictionaryMatcher = routeDictionary => { routeDictionary.ContainsKey("RoleId").Should().BeTrue(); routeDictionary["RoleId"].ToString().Should().Be(role.Id); routeDictionary.ContainsKey("ClaimId").Should().BeTrue(); routeDictionary["ClaimId"].As <int>().Should().Be(serviceResult.Id); return(true); }; _mockUrlHelper.Setup(_ => _.Link( "GetClaimById", It.Is <Dictionary <string, object> >(args => routeDictionaryMatcher(args)))) .Returns(link); // Act var result = await _roleController.AddClaim(role.Id, claim); // Assert var message = await result.ExecuteAsync(new CancellationToken()); message.StatusCode.Should().Be(HttpStatusCode.Created); message.Headers.Location.Should().Be(link); ClaimModel messageModel; message.TryGetContentValue(out messageModel).Should().BeTrue(); messageModel.ShouldBeEquivalentTo(serviceResult); }