public void UserLearningModule_ValidModel_NoModelValidationError()
        {
            // Arrange- Setting valid learning module Id.
            var userLearningModuleViewModel = new UserLearningModuleViewModel
            {
                LearningModuleId = Guid.NewGuid(),
            };

            Assert.IsTrue(!this.ValidateModel(userLearningModuleViewModel).Any());
        }
        public void UserLearningModule_EmptyLearningModuleId_ModelValidationError()
        {
            // Arrange- Setting empty learning module Id.
            var userLearningModuleViewModel = new UserLearningModuleViewModel
            {
                LearningModuleId = Guid.Empty,
            };
            var modelValidationResult = this.ValidateModel(userLearningModuleViewModel);

            Assert.IsTrue(modelValidationResult.Any(
                              v => v.ErrorMessage.Contains("empty GUID")));
        }
Пример #3
0
        public async Task <IActionResult> PostAsync(UserLearningModuleViewModel userLearningModuleDetail)
        {
            this.RecordEvent("User learning module - Http Post call initiated.", RequestType.Initiated);
            this.logger.LogInformation("User learning module - Http Post call initiated.");

            try
            {
                if (userLearningModuleDetail == null)
                {
                    this.logger.LogError($"Error while saving user learning module details to storage for userId: {this.UserObjectId}");
                    this.RecordEvent("User learning module - Http Post call failed.", RequestType.Failed);
                    return(this.BadRequest("User learning module details cannot be null."));
                }

                var userLearningModuleEntity = new UserLearningModule()
                {
                    UserId           = this.UserObjectId,
                    LearningModuleId = userLearningModuleDetail.LearningModuleId,
                    CreatedOn        = DateTime.UtcNow,
                };
                var userResorces = await this.unitOfWork.UserLearningModuleRepository.FindAsync(userLearningModule => userLearningModule.LearningModuleId == userLearningModuleEntity.LearningModuleId && userLearningModule.UserId == userLearningModuleEntity.UserId);

                if (userResorces.Any())
                {
                    this.logger.LogInformation("User learning module - Http Post call succeeded.");
                    this.RecordEvent("User learning module - Http Post call succeeded.", RequestType.Succeeded);
                    return(this.Conflict("User learning module already exists."));
                }

                this.unitOfWork.UserLearningModuleRepository.Add(userLearningModuleEntity);
                await this.unitOfWork.SaveChangesAsync();

                this.logger.LogInformation("User learning module - Http Post call succeeded.");
                this.RecordEvent("User learning module - Http Post call succeeded.", RequestType.Succeeded);

                return(this.Ok(true));
            }
            catch (Exception ex)
            {
                this.RecordEvent("User learning module - Http Post call failed.", RequestType.Failed);
                this.logger.LogError(ex, $"Error while saving user learning module details for user id: {this.UserObjectId}.");
                throw;
            }
        }
        public async Task PostAsync_SaveUserLearningModule_RetrunsOkResult()
        {
            // ARRANGE
            var userlearningModule = new UserLearningModuleViewModel
            {
                LearningModuleId = Guid.NewGuid(),
            };
            var userlearningModuleEntityModel = new UserLearningModule
            {
                LearningModuleId = userlearningModule.LearningModuleId,
            };
            var userLearningModuleList = new List <UserLearningModule>();

            this.unitOfWork.Setup(uow => uow.UserLearningModuleRepository.FindAsync(It.IsAny <Expression <Func <UserLearningModule, bool> > >())).ReturnsAsync(userLearningModuleList);

            // ACT
            var result = (ObjectResult)await this.userLearningModuleController.PostAsync(userlearningModule);

            var resultValue = result.Value;

            // ASSERT
            Assert.AreEqual(result.StatusCode, StatusCodes.Status200OK);
            Assert.AreEqual(result.Value, true);
        }
        public async Task PostAsync_RecordAlreadyExist_ReturnsConflictResult()
        {
            // ARRANGE
            var userlearningModule = new UserLearningModuleViewModel
            {
                LearningModuleId = Guid.NewGuid(),
            };
            var userlearningModuleEntityModel = new UserLearningModule
            {
                LearningModuleId = userlearningModule.LearningModuleId,
            };
            var userLearningModuleList = new List <UserLearningModule>
            {
                userlearningModuleEntityModel,
            };

            this.unitOfWork.Setup(uow => uow.UserLearningModuleRepository.FindAsync(It.IsAny <Expression <Func <UserLearningModule, bool> > >())).ReturnsAsync(userLearningModuleList);

            // ACT
            var result = (ObjectResult)await this.userLearningModuleController.PostAsync(userlearningModule);

            // ASSERT
            Assert.AreEqual(result.StatusCode, StatusCodes.Status409Conflict);
        }