public async Task HandleSkillRequest_ShouldThrowArgumentNullException_WhenLambdaContextIsNull() { 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 <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); await Assert.ThrowsAsync <ArgumentNullException>(() => sut.HandleSkillRequest(ValidSkillRequest, null)); }
public async Task HandleSkillRequest_ShouldReturnSkillResponse_WhenInputIsValid() { SkillResponse expectedSkillResponse = new SkillResponse() { Version = "TestVersion", Response = new ResponseBody() }; Mock <ILambdaContext> mockLambdaContext = new Mock <ILambdaContext>(); 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 <IRequestRouter> mockIntentRequestRouter = new Mock <IRequestRouter>(); mockIntentRequestRouter.Setup(x => x.GetSkillResponse(It.IsAny <SkillRequest>(), It.IsAny <TokenUser>())).ReturnsAsync(expectedSkillResponse); mockIntentRequestRouter.Setup(x => x.RequestType).Returns(RequestType.IntentRequest); Mock <IRequestMapper> mockRequestMapper = new Mock <IRequestMapper>(); mockRequestMapper.Setup(x => x.GetRequestHandler(It.IsAny <SkillRequest>())).Returns(mockIntentRequestRouter.Object); Mock <ITokenUserData> mockTokenUserData = new Mock <ITokenUserData>(); mockTokenUserData.Setup(x => x.Save(It.IsAny <TokenUser>())).Returns(Task.FromResult(true)); 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); SkillResponse skillResponse = await sut.HandleSkillRequest(ValidSkillRequest, mockLambdaContext.Object); Assert.IsType <SkillResponse>(skillResponse); }