public async void PostUserComplex_Ok() { // Arrange var mockLoggingService = new Mock <IDatabaseAccessService>(); mockLoggingService.Setup(service => service.LogUserAsync(It.IsAny <UserInfoFullRequestBody>())) .ReturnsAsync(new FullUserInfo()); var mockRevenueForecastService = new Mock <IRevenueForecastService>(); mockRevenueForecastService.Setup(service => service.StartCalculationAsync(It.IsAny <FullUserInfo>())) .ReturnsAsync(new RevenueForecasts()); var mockExportService = new Mock <IForecastExportService>(); var controller = new RevenueForecastController(mockLoggingService.Object, mockRevenueForecastService.Object, _mapper, mockExportService.Object); // Act var requestBody = new UserInfoFullRequestBody { Email = "123" }; var result = await controller.PostUserComplexAsync(requestBody); // Assert if (result is OkObjectResult objectResult) { Assert.IsType <RevenueForecastViewModel>(objectResult.Value as RevenueForecastViewModel); } else { Assert.True(false, "failed to receive revenue forecast as result"); } }
public async Task <FullUserInfo> LogUserAsync(UserInfoFullRequestBody userInfoDto) { userInfoDto.ForecastType = ForecastType.Absolute; var userInfoDoc = userInfoDto.ToBsonDocument(); await _users.InsertOneAsync(userInfoDoc); var userInfoModel = BsonSerializer.Deserialize <UserInfoFullRequestBody>(userInfoDoc); var userInfo = _mapper.Map <FullUserInfo>(userInfoModel); return(userInfo); }
public async Task <IActionResult> PostUserComplexAsync([FromBody] UserInfoFullRequestBody userInfoDto) { if (!ModelState.IsValid) { throw new ValidationException(ModelState); } var userInfo = await _databaseAccessService.LogUserAsync(userInfoDto); var forecast = await _revenueForecastService.StartCalculationAsync(userInfo); await _databaseAccessService.AttachForecastToUserAsync(userInfo.Id, forecast.Id); return(Ok(_mapper.Map <RevenueForecastViewModel>(forecast))); }