public async Task GetUserApplicationState_ShouldReturnTokenUser_WhenExistingUserIsFound() { TokenUser expectedTokenUser = new TokenUser() { Id = "existingTokenUser", Players = new List <Player>() }; Mock <ISkillRequestValidator> mockSkillRequestValidator = new Mock <ISkillRequestValidator>(); mockSkillRequestValidator.Setup(x => x.IsValid(It.IsAny <SkillRequest>())).Returns(true); Mock <SkillProductsClient> mockInSkillProductsClient = new Mock <SkillProductsClient>(MockBehavior.Loose); mockInSkillProductsClient.Setup(x => x.GetProducts()).ReturnsAsync(new InSkillProductsResponse() { Products = new InSkillProduct[0] }); Mock <ISkillProductsClientAdapter> mockSkillProductsAdapter = new Mock <ISkillProductsClientAdapter>(MockBehavior.Loose); mockSkillProductsAdapter.Setup(x => x.GetClient(It.IsAny <SkillRequest>())).Returns(mockInSkillProductsClient.Object); Mock <ILogger <RequestBusinessLogic> > mockLogger = new Mock <ILogger <RequestBusinessLogic> >(); Mock <IRequestMapper> mockRequestMapper = new Mock <IRequestMapper>(); Mock <IUserProfileClient> mockUserProfileClient = new Mock <IUserProfileClient>(); mockUserProfileClient.Setup(x => x.GetUserId(It.IsAny <string>())).ReturnsAsync("TestProfileUserId"); Mock <ITokenUserData> mockTokenUserData = new Mock <ITokenUserData>(); mockTokenUserData.Setup(x => x.Get(It.IsAny <string>())).ReturnsAsync(expectedTokenUser); RequestBusinessLogic sut = new RequestBusinessLogic(mockUserProfileClient.Object, mockSkillRequestValidator.Object, mockSkillProductsAdapter.Object, mockLogger.Object, mockRequestMapper.Object, mockTokenUserData.Object); TokenUser tokenUser = await sut.GetUserApplicationState(ValidSkillRequest); Assert.Equal(expectedTokenUser, tokenUser); }
public async Task GetUserApplicationState_ShouldThrowArgumentNullException_WhenSkillRequestIsInvalid() { TokenUser expectedTokenUser = new TokenUser() { Id = "existingTokenUser", Players = new List <Player>() }; Mock <ISkillRequestValidator> mockSkillRequestValidator = new Mock <ISkillRequestValidator>(); mockSkillRequestValidator.Setup(x => x.IsValid(It.IsAny <SkillRequest>())).Returns(false); Mock <SkillProductsClient> mockInSkillProductsClient = new Mock <SkillProductsClient>(MockBehavior.Loose); mockInSkillProductsClient.Setup(x => x.GetProducts()).ReturnsAsync(new InSkillProductsResponse() { Products = new InSkillProduct[0] }); Mock <ISkillProductsClientAdapter> mockSkillProductsAdapter = new Mock <ISkillProductsClientAdapter>(MockBehavior.Loose); mockSkillProductsAdapter.Setup(x => x.GetClient(It.IsAny <SkillRequest>())).Returns(mockInSkillProductsClient.Object); Mock <ILogger <RequestBusinessLogic> > mockLogger = new Mock <ILogger <RequestBusinessLogic> >(); Mock <IRequestMapper> mockRequestMapper = new Mock <IRequestMapper>(); Mock <IUserProfileClient> mockUserProfileClient = new Mock <IUserProfileClient>(); mockUserProfileClient.Setup(x => x.GetUserId(It.IsAny <string>())).ReturnsAsync("TestProfileUserId"); Mock <ITokenUserData> mockTokenUserData = new Mock <ITokenUserData>(); mockTokenUserData.Setup(x => x.Get(It.IsAny <string>())).ReturnsAsync(expectedTokenUser); RequestBusinessLogic sut = new RequestBusinessLogic(mockUserProfileClient.Object, mockSkillRequestValidator.Object, mockSkillProductsAdapter.Object, mockLogger.Object, mockRequestMapper.Object, mockTokenUserData.Object); await Assert.ThrowsAsync <ArgumentNullException>(() => sut.GetUserApplicationState(ValidSkillRequest)); }