public void User_ThrowsIfNotAvailable() { var httpContextAccessor = new HttpContextAccessor(); var userAccessor = new HttpContextUserAccessor(httpContextAccessor); Assert.Throws <InvalidOperationException>(() => userAccessor.User); }
public void User_ReturnsCurrentUser() { var httpContextAccessor = new HttpContextAccessor { HttpContext = Substitute.For <HttpContext>() }; var userAccessor = new HttpContextUserAccessor(httpContextAccessor); Assert.NotNull(userAccessor.User); }
public void TryGetUser_VerifyBehaviour() { var httpContextAccessor = new HttpContextAccessor(); var userAccessor = new HttpContextUserAccessor(httpContextAccessor); Assert.False(userAccessor.TryGetUser(out var nullUser)); Assert.Null(nullUser); httpContextAccessor.HttpContext = Substitute.For <HttpContext>(); Assert.True(userAccessor.TryGetUser(out var user)); Assert.NotNull(user); }