public async Task HasPointsPersistence_ShouldReturnFalse_WhenUserHasPointsPersistenceCannotReadTheUsersSkillProducts() { 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()).Throws(new Exception()); 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 <ITokenUserData> mockTokenUserData = new Mock <ITokenUserData>(); Mock <IUserProfileClient> mockUserProfileClient = new Mock <IUserProfileClient>(); mockUserProfileClient.Setup(x => x.GetUserId(It.IsAny <string>())).ReturnsAsync("TestProfileUserId"); RequestBusinessLogic sut = new RequestBusinessLogic(mockUserProfileClient.Object, mockSkillRequestValidator.Object, mockSkillProductsAdapter.Object, mockLogger.Object, mockRequestMapper.Object, mockTokenUserData.Object); bool hashPointsPersistence = await sut.HasPointsPersistence(ValidSkillRequest); Assert.False(hashPointsPersistence); }
public async Task HasPointsPersistence_ShouldReturnFalse_WhenUserDoesNotHavePointsPersistence() { Mock <ISkillRequestValidator> mockSkillRequestValidator = new Mock <ISkillRequestValidator>(); mockSkillRequestValidator.Setup(x => x.IsValid(It.IsAny <SkillRequest>())).Returns(true); Mock <IUserProfileClient> mockUserProfileClient = new Mock <IUserProfileClient>(); mockUserProfileClient.Setup(x => x.GetUserId(It.IsAny <string>())).ReturnsAsync("TestProfileUserId"); Mock <SkillProductsClient> mockInSkillProductsClient = new Mock <SkillProductsClient>(MockBehavior.Loose); mockInSkillProductsClient.Setup(x => x.GetProducts()).Returns(Task.FromResult <InSkillProductsResponse>( new InSkillProductsResponse() { Products = new InSkillProduct[] { new InSkillProduct() { Entitled = Entitlement.NotEntitled, ProductId = "NotPointsPersistence" } } } )); 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 <ITokenUserData> mockTokenUserData = new Mock <ITokenUserData>(); RequestBusinessLogic sut = new RequestBusinessLogic(mockUserProfileClient.Object, mockSkillRequestValidator.Object, mockSkillProductsAdapter.Object, mockLogger.Object, mockRequestMapper.Object, mockTokenUserData.Object); bool hashPointsPersistence = await sut.HasPointsPersistence(ValidSkillRequest); Assert.False(hashPointsPersistence); }
public async Task HasPointsPersistence_ShouldThrowArgumentNullException_WhenKillRequestIsNotValid() { 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()).Returns(Task.FromResult <InSkillProductsResponse>(null)); Mock <ISkillProductsClientAdapter> mockSkillProductsAdapter = new Mock <ISkillProductsClientAdapter>(MockBehavior.Loose); mockSkillProductsAdapter.Setup(x => x.GetClient(It.IsAny <SkillRequest>())).Returns(mockInSkillProductsClient.Object); Mock <IUserProfileClient> mockUserProfileClient = new Mock <IUserProfileClient>(); mockUserProfileClient.Setup(x => x.GetUserId(It.IsAny <string>())).ReturnsAsync("TestProfileUserId"); Mock <ILogger <RequestBusinessLogic> > mockLogger = new Mock <ILogger <RequestBusinessLogic> >(); Mock <IRequestMapper> mockRequestMapper = new Mock <IRequestMapper>(); Mock <ITokenUserData> mockTokenUserData = new Mock <ITokenUserData>(); RequestBusinessLogic sut = new RequestBusinessLogic(mockUserProfileClient.Object, mockSkillRequestValidator.Object, mockSkillProductsAdapter.Object, mockLogger.Object, mockRequestMapper.Object, mockTokenUserData.Object); await Assert.ThrowsAsync <ArgumentNullException>(() => sut.HasPointsPersistence(ValidSkillRequest)); }
public async Task HasPointsPersistence_ShouldReturnTrue_WhenUserHasPointsPersistenceAndIsEntitled() { 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()).Returns(Task.FromResult <InSkillProductsResponse>( new InSkillProductsResponse() { Products = new InSkillProduct[] { new InSkillProduct() { Entitled = Entitlement.Entitled, ProductId = "amzn1.adg.product.467f7ca4-91dd-48d3-b831-040673e7066c" } } } )); 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 <ITokenUserData> mockTokenUserData = new Mock <ITokenUserData>(); Mock <IUserProfileClient> mockUserProfileClient = new Mock <IUserProfileClient>(); mockUserProfileClient.Setup(x => x.GetUserId(It.IsAny <string>())).ReturnsAsync("TestProfileUserId"); SkillRequest skillRequest = ValidSkillRequest; RequestBusinessLogic sut = new RequestBusinessLogic(mockUserProfileClient.Object, mockSkillRequestValidator.Object, mockSkillProductsAdapter.Object, mockLogger.Object, mockRequestMapper.Object, mockTokenUserData.Object); bool hashPointsPersistence = await sut.HasPointsPersistence(skillRequest); Assert.True(hashPointsPersistence); }