public async Task ReturnsAlreadyReportedResultWhenUserSessionAlreadyExists()
        {
            // Arrange
            var dfcUserSession = CreateDfcUserSession();
            var questionSet    = CreateQuestionSet();
            var userSession    = CreateUserSession();
            var ms             = new MemoryStream();

            using var sw = new StreamWriter(ms);

            sw.Write(JsonConvert.SerializeObject(dfcUserSession));
            sw.Flush();
            ms.Position = 0;

            A.CallTo(() => httpRequest.Body).Returns(ms);
            A.CallTo(() => questionSetRepository.GetCurrentQuestionSet(A <string> .Ignored)).Returns(questionSet);
            A.CallTo(() => userSessionRepository.GetByIdAsync(A <string> .Ignored, A <string> .Ignored)).Returns(userSession);
            A.CallTo(() => sessionClient.ValidateUserSession(A <DfcUserSession> .Ignored)).Returns(true);

            // Act
            var result = await functionApp.CreateNewSkillsAssessment(httpRequest).ConfigureAwait(false);

            // Assert
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.AlreadyReported, statusCodeResult.StatusCode);
        }
        public async Task <IActionResult> GetUserSession([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "assessment/session/{sessionId}")] HttpRequest request, string sessionId)
        {
            request.LogRequestHeaders(logService);

            var correlationId = Guid.Parse(correlationIdProvider.CorrelationId);

            logService.LogMessage($"CorrelationId: {correlationId} - Creating a new assessment", SeverityLevel.Information);

            var partitionKey        = sessionClient.GeneratePartitionKey(sessionId);
            var existingUserSession = await userSessionRepository.GetByIdAsync(sessionId, partitionKey).ConfigureAwait(false);

            if (existingUserSession is null)
            {
                logService.LogMessage($"Unable to find User Session with id {sessionId}.", SeverityLevel.Information);
                return(responseWithCorrelation.ResponseWithCorrelationId(HttpStatusCode.NoContent, correlationId));
            }

            var dfcUserSession = new DfcUserSession
            {
                SessionId    = existingUserSession.UserSessionId,
                CreatedDate  = existingUserSession.StartedDt,
                PartitionKey = existingUserSession.PartitionKey,
                Salt         = existingUserSession.Salt,
            };

            return(responseWithCorrelation.ResponseObjectWithCorrelationId(dfcUserSession, correlationId));
        }
        public async Task ReturnsNoContentResultWhenUserSessionDoesNotExist()
        {
            // Arrange
            A.CallTo(() => userSessionRepository.GetByIdAsync(A <string> .Ignored, A <string> .Ignored)).Returns((UserSession)null);

            // Act
            var result = await functionApp.GetUserSession(httpRequest, "DummySessionId").ConfigureAwait(false);

            // Assert
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)HttpStatusCode.NoContent, statusCodeResult.StatusCode);
        }
示例#4
0
        public async Task CreateNewSkillsAssessmentCreatedSuccessfully()
        {
            // Arrange
            var dfcSession   = sessionClient.NewSession();
            var partitionKey = sessionClient.GeneratePartitionKey(dfcSession.SessionId);
            var client       = new RestClient(apiBaseUrl);
            var req          = new RestRequest("assessment/skills", Method.POST)
            {
                Body = new RequestBody("application/json", "integrationTest", JsonConvert.SerializeObject(dfcSession)),
            };

            // Act
            var response = client.Execute(req);

            // Assert
            Assert.True(response.IsSuccessful && response.StatusCode == HttpStatusCode.Created);

            var createdUserSession = await userSessionRepository.GetByIdAsync(dfcSession.SessionId, partitionKey).ConfigureAwait(false);

            Assert.NotNull(createdUserSession);
            Assert.True(createdUserSession.PartitionKey == dfcSession.PartitionKey &&
                        createdUserSession.Salt == dfcSession.Salt &&
                        createdUserSession.UserSessionId == dfcSession.SessionId &&
                        createdUserSession.StartedDt == dfcSession.CreatedDate);
        }
 public async Task <Maybe <UserSession> > GetSessionAsync(Guid id)
 => await _providerClient.GetAsync(
     async() => await _userSessionRepository.GetByIdAsync(id),
     async() => await _userServiceClient.GetSessionAsync <UserSession>(id));
示例#6
0
 public async Task <Maybe <UserSession> > GetSessionAsync(Guid id)
 => await _userSessionRepository.GetByIdAsync(id);
 public async Task <UserSession> GetSessionAsync(Guid id)
 {
     return(await _userSessionRepository.GetByIdAsync(id));
 }