Пример #1
0
        public void Get_All_Available_Quality_Check_Rules_Success()
        {
            List<QualityCheckColumnRule> lstCol = new List<QualityCheckColumnRule>();
            QualityCheckColumnRule colRule = new QualityCheckColumnRule() { Description = "Column 1 desc", ErrorMessage = "error msg", HeaderName = "Column 1", IsActive = true, IsRequired = true, Order = 1, QualityCheck = null, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 1, QualityCheckId = 1, Range = "" };
            QualityCheckColumnRule colRule1 = new QualityCheckColumnRule() { Description = "Column 2 desc", ErrorMessage = "error msg1", HeaderName = "Column 2", IsActive = true, IsRequired = true, Order = 2, QualityCheck = null, QualityCheckColumnRuleId = 2, QualityCheckColumnTypeId = 2, QualityCheckId = 1, Range = "" };
            lstCol.Add(colRule);
            lstCol.Add(colRule1);

            List<QualityCheckModel> lstModel = new List<QualityCheckModel>()
            {
                new QualityCheckModel(){ CreatedUser="******", QualityCheckData= new QualityCheck(){CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Test Rule", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Test Rule", QualityCheckColumnRules = lstCol, QualityCheckId = 1}}          
            };

            this.qcService = new StubIQCService()
            {
                GetQualityCheckRulesBoolean = (includeAdmin) => { return lstModel; }
            };

            HttpResponseMessage response = null;
          
            QCController qcController = CreateRequest(HttpMethod.Get);

            // Perform
            response = qcController.RetrieveQualityCheckRules();
            
         
            // Assert
            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK, "Status Code is not as Expected");
            var result = response.Content.ReadAsAsync<List<QualityCheckModel>>().Result;

            Assert.IsTrue(result.Count >= 1, "There is no Quality check rule in the List");
            Assert.AreEqual(result.Count, lstModel.Count, "Expected and Actula Repository Counts are not equal");

            Assert.AreEqual(result[0].CreatedUser, "Test User");
            Assert.AreEqual(result[0].QualityCheckData.CreatedBy, 1);
            Assert.AreEqual(result[0].QualityCheckData.Description, "Test Rule");
            Assert.AreEqual(result[0].QualityCheckData.EnforceOrder, true);
            Assert.AreEqual(result[0].QualityCheckData.IsActive, true);
            Assert.AreEqual(result[0].QualityCheckData.IsVisibleToAll, true);
            Assert.AreEqual(result[0].QualityCheckData.EnforceOrder, true);
            Assert.AreEqual(result[0].QualityCheckData.ModifiedBy, 1);
            Assert.AreEqual(result[0].QualityCheckData.Name, "Test Rule");
            Assert.AreEqual(result[0].QualityCheckData.QualityCheckId, 1);
        }
Пример #2
0
        public void Get_Quality_Check_By_Id_Success()
        {
            List<QualityCheckColumnRule> lstCol = new List<QualityCheckColumnRule>();
            QualityCheckColumnRule colRule = new QualityCheckColumnRule() { Description = "Column 1 desc", ErrorMessage = "error msg", HeaderName = "Column 1", IsActive = true, IsRequired = true, Order = 1, QualityCheck = null, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 1, QualityCheckId = 1, Range = "" };
            QualityCheckColumnRule colRule1 = new QualityCheckColumnRule() { Description = "Column 2 desc", ErrorMessage = "error msg1", HeaderName = "Column 2", IsActive = true, IsRequired = true, Order = 2, QualityCheck = null, QualityCheckColumnRuleId = 2, QualityCheckColumnTypeId = 2, QualityCheckId = 1, Range = "" };

            lstCol.Add(colRule);
            lstCol.Add(colRule1);

            QualityCheckModel model = new QualityCheckModel() { CreatedUser = "******", QualityCheckData = new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Test Rule", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Test Rule", QualityCheckColumnRules = lstCol, QualityCheckId = 1 } };

            this.qcService = new StubIQCService()
            {
                GetQualityCheckByIdInt32 = (id) => { return model; }
            };

            QCController qcController = CreateRequest(HttpMethod.Get);

            // Perform
            var response = qcController.GetQualityCheckById(1);

            // Assert
            Assert.AreEqual(response.StatusCode, HttpStatusCode.OK, "Status Code is not as Expected");
            var result = response.Content.ReadAsAsync<QualityCheckModel>().Result;

            Assert.IsNotNull(result, "There is no Quality check rule for the mentioned id");

            Assert.AreEqual(result.CreatedUser, "Test User");
            Assert.AreEqual(result.QualityCheckData.CreatedBy, 1);
            Assert.AreEqual(result.QualityCheckData.Description, "Test Rule");
            Assert.AreEqual(result.QualityCheckData.EnforceOrder, true);
            Assert.AreEqual(result.QualityCheckData.IsActive, true);
            Assert.AreEqual(result.QualityCheckData.IsVisibleToAll, true);
            Assert.AreEqual(result.QualityCheckData.EnforceOrder, true);
            Assert.AreEqual(result.QualityCheckData.ModifiedBy, 1);
            Assert.AreEqual(result.QualityCheckData.Name, "Test Rule");
            Assert.AreEqual(result.QualityCheckData.QualityCheckId, 1);
        }
Пример #3
0
        public void Initialize()
        {
            List<QualityCheckColumnRule> lstCol = new List<QualityCheckColumnRule>();
            QualityCheckColumnRule colRule = new QualityCheckColumnRule() { Description = "Column 1 desc", ErrorMessage = "error msg", HeaderName = "Column 1", IsActive = true, IsRequired = true, Order = 1, QualityCheck = null, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 1, QualityCheckId = 1, Range = "" };
            QualityCheckColumnRule colRule1 = new QualityCheckColumnRule() { Description = "Column 2 desc", ErrorMessage = "error msg1", HeaderName = "Column 2", IsActive = true, IsRequired = true, Order = 2, QualityCheck = null, QualityCheckColumnRuleId = 2, QualityCheckColumnTypeId = 2, QualityCheckId = 1, Range = "" };
            lstCol.Add(colRule);
            lstCol.Add(colRule1);

            // Unit of work code
            this.unitOfWork =
                new StubIUnitOfWork()
                {
                    Commit = () => { return; }
                };

            // User repository
            this.userRepository = new StubIUserRepository()
            {
                GetUserbyUserIdInt32 = (userId) =>
                    {
                        List<UserRole> userRoles = new List<UserRole>();
                        userRoles.Add(new UserRole() { Role = null, RoleId = 1, UserId = userId, UserRoleId = 1 });
                        User userNew = new User() { CreatedOn = DateTime.UtcNow, EmailId = "*****@*****.**", FirstName = "First", IdentityProvider = "identity", IsActive = true, LastName = "Last", MiddleName = "midele", ModifiedOn = DateTime.UtcNow, NameIdentifier = "nameIdentifier", Organization = "Test Org", UserAttributes = null, UserId = userId, UserRoles = userRoles };
                        return userNew;
                    }
            };

            // file Service implementation
            this.fileService = new StubIFileService()
            {
                GetFileByFileIdInt32 = (fileId) =>
                    {
                        File fileToAdd = new File() { Citation = "Citation 1", CreatedBy = 1, CreatedOn = DateTime.Now, Description = "Document 1", FileAttributes = null, FileColumns = null, FileId = fileId, FileQualityChecks = null, Identifier = "asdahgsdfsghadfsghad", isDeleted = false, MimeType = "Mime type 1", ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Document One", Repository = null, RepositoryId = null, Size = 20.90, Status = "Uploaded", Title = "Document 1" };
                        return null;
                    }
            };

            // Quality check repository implementation
            this.qcRepository = new StubIQualityCheckRepository()
            {
                RetrieveQualityCheckRules = () =>
                    {
                        List<QualityCheck> lstQCRule = new List<QualityCheck>();
                        lstQCRule.Add(new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Test Rule", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Test Rule", QualityCheckColumnRules = lstCol, QualityCheckId = 1 });
                        // lstQCRule.Add(new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Test Rule1", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Test Rule1", QualityCheckColumnRules = lstCol, QualityCheckId = 1 });

                        return lstQCRule;
                    },
                RetrieveQCColumnTypes = () =>
                    {
                        List<QualityCheckColumnType> qcTypes = new List<QualityCheckColumnType>();
                        qcTypes.Add(new QualityCheckColumnType() { Description = "No check", Name = "None", QualityCheckColumnTypeId = 1 });
                        qcTypes.Add(new QualityCheckColumnType() { Description = "Number type", Name = "Numeric", QualityCheckColumnTypeId = 2 });
                        return qcTypes;
                    },
                GetQualityCheckByIDInt32 = (qualityCheckId) =>
                    {
                        QualityCheck qc = new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Get by id desc", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Get by id Rule", QualityCheckColumnRules = lstCol, QualityCheckId = qualityCheckId };
                        return qc;
                    },
                AddQualityCheckRuleQualityCheck = (qualityCheck) =>
                    {
                        qualityCheck.QualityCheckId = 2;
                        return qualityCheck;
                    },
                UpdateQualityCheckRuleQualityCheck = (qualityCheck) =>
                     {
                         qualityCheck.Name = "Updated rule From rep";
                         return qualityCheck;
                     },
                DeleteQualityCheckRuleInt32 = (qualityCheckId) =>
                      {
                          QualityCheck qc = new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Delete", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Delete Rule", QualityCheckColumnRules = lstCol, QualityCheckId = qualityCheckId };
                          return qc;
                      },
                DeleteColumnRulesInt32 = (qualityCheckId) =>
                    {
                        return true;
                    },
                AddFileQualityCheckFileQualityCheck = (fileQualityCheck) =>
                    {
                        fileQualityCheck.Status = true;
                        return fileQualityCheck;
                    },
                GetQualityCheckByNameString = (ruleName) =>
                    {
                        QualityCheck qc = new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Get by rule name", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = ruleName, QualityCheckColumnRules = lstCol, QualityCheckId = 10 };
                        return qc;
                    }
            };

            qcService = new QCS.QCService(this.qcRepository, this.unitOfWork, this.userRepository, this.fileService, this.blobRepository);
        }
        /// <summary>
        /// Extension method class for quality check rule viewmodel to put data on quality check domain model class.
        /// </summary>
        /// <param name="rule">Quality check rule view model.</param>
        /// <param name="qualityCheck">Quality check model.</param>
        /// <returns>Updated qualityCheck model class object.</returns>
        public static QualityCheck SetValuesTo(this QCRuleViewModel rule, QualityCheck qualityCheck)
        {
            Check.IsNotNull<QCRuleViewModel>(rule, "qcRuleViewModel");
            Check.IsNotNull<QualityCheck>(qualityCheck, "qualityCheck");
            qualityCheck.QualityCheckColumnRules = new List<QualityCheckColumnRule>();

            if (rule.QCRuleId == 0)
            {
                qualityCheck.CreatedOn = DateTime.UtcNow;
                qualityCheck.CreatedBy = BaseController.UserId;
            }
            else
            {
                qualityCheck.CreatedOn = Convert.ToDateTime(rule.CreatedDate).ToUTCFromClientTime();
                qualityCheck.CreatedBy = rule.CreatedBy;
                qualityCheck.ModifiedOn = DateTime.UtcNow;
                qualityCheck.ModifiedBy = BaseController.UserId;
            }

            qualityCheck.EnforceOrder = rule.IsOrderRequired;
            qualityCheck.IsVisibleToAll = rule.IsVisibleToAll;
            qualityCheck.Description = rule.QCRuleDescription;
            qualityCheck.QualityCheckId = rule.QCRuleId;
            qualityCheck.Name = rule.QCRuleName;
            qualityCheck.IsActive = true;
            qualityCheck.IsVisibleToAll = rule.VisibilityOption == 1 ? true : false;

            foreach (var headerModel in rule.LstHeaderNames)
            {
                if (!string.IsNullOrEmpty(headerModel.HeaderName))
                {
                    QualityCheckColumnRule columnRule = new QualityCheckColumnRule();
                    columnRule.QualityCheckColumnTypeId = headerModel.ColumnTypeId;
                    columnRule.ErrorMessage = headerModel.ErrorMessage;
                    columnRule.Description = headerModel.HeaderName;
                    columnRule.HeaderName = headerModel.HeaderName;
                    columnRule.IsRequired = true;
                    columnRule.IsActive = true;
                    columnRule.QualityCheckColumnRuleId = headerModel.QCColumnRuleId;
                    columnRule.QualityCheckId = qualityCheck.QualityCheckId;
                    columnRule.Order = headerModel.Order;

                    if (!string.IsNullOrEmpty(headerModel.RangeStart) || !string.IsNullOrEmpty(headerModel.RangeEnd))
                    {
                        columnRule.Range = (headerModel.RangeStart == null ? string.Empty : headerModel.RangeStart) + Utilities.Constants.RangeSeparator + (headerModel.RangeEnd == null ? string.Empty : headerModel.RangeEnd);
                    }

                    qualityCheck.QualityCheckColumnRules.Add(columnRule);
                }
            }

            return qualityCheck;
        }
 private void AddQualityCheckColumnRule(QualityCheckColumnRule qcColumnRule)
 {
     testDBContext.QualityCheckColumnRules.Add(qcColumnRule);
     testDBContext.Commit();
 }
        private void AddDefaultData()
        {
            User newUser = new User()
            {
                NameIdentifier = "s0Me1De9Tf!Er$tRing",
                FirstName = "SomeFirstName",
                MiddleName = "SomeMiddleName",
                LastName = "SomeLastName",
                IdentityProvider = "Windows Live",
                Organization = "SomeOrganization",
                EmailId = "*****@*****.**",
                CreatedOn = DateTime.Now,
                ModifiedOn = DateTime.Now,
                IsActive = true,
                UserAttributes = null
            };

            // User with userid 1
            AddUser(newUser);

            //Adding Quality check column rules data

            QualityCheckColumnType qcColType = new QualityCheckColumnType() { Description = "No type check", Name = "None", QualityCheckColumnTypeId = 1, QualityCheckColumnRules = null };
            QualityCheckColumnType qcColType1 = new QualityCheckColumnType() { Description = "Number type", Name = "Numeric", QualityCheckColumnTypeId = 2, QualityCheckColumnRules = null };

            AddQualityCheckColumnType(qcColType);
            AddQualityCheckColumnType(qcColType1);

            QualityCheck qcRule = new QualityCheck() { CreatedBy = 1, Description = "Test rule", CreatedOn = DateTime.UtcNow, EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Test Rule", QualityCheckId = 1, QualityCheckColumnRules = null };

            AddQualityCheckRule(qcRule);

            QualityCheckColumnRule colRule = new QualityCheckColumnRule() { Description = "Column 1", ErrorMessage = "Col1 is required", HeaderName = "Col1", IsActive = true, IsRequired = true, Order = 1, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 1, QualityCheckId = 1, Range = "" };
            QualityCheckColumnRule colRule1 = new QualityCheckColumnRule() { Description = "Column 2", ErrorMessage = "Col2 is required", HeaderName = "Col2", IsActive = true, IsRequired = false, Order = 2, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 2, QualityCheckId = 1, Range = "1-19999" };

            AddQualityCheckColumnRule(colRule);
            AddQualityCheckColumnRule(colRule1);
        }
        public void Add_QC_Rule_Test()
        {
            IQualityCheckRepository repository = new QualityCheckRepository(testDBContext);

            QualityCheckColumnRule colRule = new QualityCheckColumnRule() { Description = "Column 4", ErrorMessage = "Col1 is required", HeaderName = "Col1", IsActive = true, IsRequired = true, Order = 1, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 1, QualityCheckId = 2, Range = "" };
            QualityCheck qcRule = new QualityCheck()
            {
                CreatedBy = 1,
                CreatedOn = DateTime.UtcNow,
                Description = "Added rule",
                EnforceOrder = true,
                FileQualityChecks = null,
                IsActive = true,
                IsVisibleToAll = true,
                ModifiedBy = 1,
                ModifiedOn = DateTime.UtcNow,
                Name = "Added rule",
                QualityCheckColumnRules = new List<QualityCheckColumnRule>() { colRule },
                QualityCheckId = 2
            };

            repository.AddQualityCheckRule(qcRule);
            testDBContext.Commit();

            var addedQcRule = repository.GetQualityCheckByID(2);

            Assert.IsNotNull(addedQcRule);

            Assert.AreEqual(addedQcRule.CreatedBy, qcRule.CreatedBy);
            Assert.AreEqual(addedQcRule.Description, qcRule.Description);
            Assert.AreEqual(addedQcRule.EnforceOrder, qcRule.EnforceOrder);
            Assert.AreEqual(addedQcRule.IsActive, qcRule.IsActive);
            Assert.AreEqual(addedQcRule.IsVisibleToAll, qcRule.IsVisibleToAll);
            Assert.AreEqual(addedQcRule.ModifiedBy, qcRule.ModifiedBy);
            Assert.AreEqual(addedQcRule.Name, qcRule.Name);
            Assert.AreEqual(addedQcRule.QualityCheckId, qcRule.QualityCheckId);
            Assert.AreEqual(addedQcRule.Name, qcRule.Name);

            Assert.IsNull(addedQcRule.FileQualityChecks);
            Assert.IsNotNull(addedQcRule.QualityCheckColumnRules);

            var selColRule = addedQcRule.QualityCheckColumnRules.Where(rul => rul.QualityCheckId == 2).FirstOrDefault();

            Assert.AreEqual(selColRule.Description, colRule.Description);
            Assert.AreEqual(selColRule.ErrorMessage, colRule.ErrorMessage);
            Assert.AreEqual(selColRule.HeaderName, colRule.HeaderName);
            Assert.AreEqual(selColRule.IsActive, colRule.IsActive);
            Assert.AreEqual(selColRule.IsRequired, colRule.IsRequired);
            Assert.AreEqual(selColRule.Order, colRule.Order);
            Assert.AreEqual(selColRule.QualityCheckColumnRuleId, colRule.QualityCheckColumnRuleId);
            Assert.AreEqual(selColRule.QualityCheckId, colRule.QualityCheckId);
            Assert.AreEqual(selColRule.Range, colRule.Range);
        }