public IHttpActionResult GetUser(Guid userId) { if (userId == Guid.Empty) { throw new ArgumentException("userId must be defined."); } User user = mapperFactory.CreateUserMapper().Map(identityManagementService.GetUser(userId)); return(Ok(user)); }
public void GetUser() { Guid userId = Guid.NewGuid(); IUser user = Substitute.For <IUser>(); user.IsDisabled.Returns(true); user.Name.Returns("DisplayName"); identityManagementService.GetUser(userId).Returns(user); ICustomProperty customProperty1 = Substitute.For <ICustomProperty>(); customProperty1.Name.Returns("prop1"); customProperty1.Value.Returns("value1"); ICustomProperty customProperty2 = Substitute.For <ICustomProperty>(); customProperty2.Name.Returns("prop2"); customProperty2.Value.Returns((string)null); user.CustomProperties.Returns(new List <ICustomProperty> { customProperty1, customProperty2 }); OkNegotiatedContentResult <User> response = sut.GetUser(userId) as OkNegotiatedContentResult <User>; Assert.IsNotNull(response); Assert.IsNotNull(response.Content); Assert.IsTrue(response.Content.IsDisabled); Assert.AreEqual("DisplayName", response.Content.Name); Assert.AreEqual(2, response.Content.CustomProperties.Count); CustomProperty customProperty = response.Content.CustomProperties.SingleOrDefault(c => c.Name == "prop1"); Assert.IsNotNull(customProperty); Assert.AreEqual("value1", customProperty.Value); customProperty = response.Content.CustomProperties.SingleOrDefault(c => c.Name == "prop2"); Assert.IsNotNull(customProperty); Assert.IsNull(customProperty.Value); }