Пример #1
0
        public void GetAsync_ExistingKB()
        {
            var knowledgeBaseRepository = new Mock <IKnowledgeBaseRepository>();

            var service = new KnowledgeBaseService(knowledgeBaseRepository.Object, Mock.Of <ILogger <KnowledgeBaseService> >());

            var result = service.GetAsync("testId").Result;

            Assert.IsNull(result);
        }
Пример #2
0
        public async Task Test_Publish_Knowledge_Base_Async_Should_Ret_Status_Success()
        {
            // Arrange
            KnowledgeBaseService service = new KnowledgeBaseService();

            // Act
            var actual = await service.PublishKnowledgeBase(subKey, knowledgeBaseId);

            // Assert
            Assert.AreEqual(ActionStatus.Success, actual.ResultStatus);
        }
Пример #3
0
        public async Task Test_Get_Knowledge_Base_Detail_Async_Should_Ret_Detail_Model()
        {
            // Arrange
            KnowledgeBaseService service = new KnowledgeBaseService();

            // Act
            var acutal = await service.GetKnowledgebaseDetail(subKey, knowledgeBaseId);

            // Assert
            Assert.IsNotNull(acutal);
        }
Пример #4
0
        public ActionResult CreateKnowledgeBaseItem(KnowledgeBase model)
        {
            try
            {
                SiteUser                  siteUser            = (SiteUser)Session["SiteUser"];
                ModelServices             modelService        = new ModelServices();
                List <HttpPostedFileBase> httpPostedFileBases = null;
                if (model.Files.ToList()[0] != null)
                {
                    httpPostedFileBases = model.Files.ToList();
                    var allowedFileSize = ConfigurationManager.AppSettings["FileSize"].ToString();
                    if (!DocumentManagementService.ValidateAttachmentSize(httpPostedFileBases))
                    {
                        ModelState.AddModelError("Files", "Attachment Size exceeds allowed limit of " + allowedFileSize + " MB");
                    }
                }

                if (ModelState.IsValid)
                {
                    var db = new dbTIREntities();
                    KnowledgeBaseService kbService = new KnowledgeBaseService(siteUser, db);

                    if (!kbService.IsKnowledgeBaseExists(model.Title))
                    {
                        //TODO: Till nowwe are picking first district Id. Need to refactor code when a user belongs to more than 1 district.
                        model.DistrictId      = siteUser.Districts[0].Id;
                        model.RoleId          = model.RoleId;
                        model.CreatedDateTime = DateTime.Now;
                        model.CreatedUserId   = siteUser.EdsUserId;
                        model.FileDetails     = model.Files.ToList()[0] != null?DocumentManagementService.GetFileDetail(model.Files) : null;

                        kbService.SaveKnowledgeBase(model);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError("Title", "Duplicate Title - please choose a unique title.");
                    }
                }
                ViewBag.RoleId = new SelectList(modelService.GetRolesForRole((int)(siteUser.Role)), "RoleId", "RoleDesc");
                return(View());
            }
            catch (Exception ex)
            {
                Logging log = new Logging();
                log.LogException(ex);
                return(View("GeneralError"));
            }
        }
Пример #5
0
        public async Task Test_Import_Knowledge_Base_Async_Should_Ret_Status_Success()
        {
            // Arrange
            var srcFileName = "SampleFAQ.tsv";
            var srcFilePath = "https://drive.google.com/uc?export=download&id=1vBxM4cw3hjiiYYYZRTn4eGN-2ZUr5af0";

            srcFilePath = "https://tocalai.blob.core.windows.net/konwledgebase/SampleFAQ.tsv";
            KnowledgeBaseService service = new KnowledgeBaseService();

            // Act
            var actual = await service.ImportKnowledgeBase(subKey, knowledgeBaseId, srcFileName, srcFilePath);

            // Assert
            Assert.AreEqual(ActionStatus.Success, actual.ResultStatus);
        }
Пример #6
0
        public void DeleteAsync_MissingKB()
        {
            var deleteResult = new DeleteResult.Acknowledged(0);

            var knowledgeBaseRepository = new Mock <IKnowledgeBaseRepository>();

            knowledgeBaseRepository.Setup(x => x.RemoveAsync(It.IsAny <string>()))
            .Returns(Task.FromResult((DeleteResult)deleteResult));

            var service = new KnowledgeBaseService(knowledgeBaseRepository.Object, Mock.Of <ILogger <KnowledgeBaseService> >());

            var result = service.DeleteAsync("testId").Result;

            Assert.IsFalse(result);
        }
Пример #7
0
        public async Task Test_Download_Knowledge_Base_Contents_Async_Should_Ret_Content()
        {
            // Arrange
            var           env  = Library.Enums.KnowledgeBaseEnum.Environment.Test.GetStringValue();
            List <string> srcs = new List <string>()
            {
                "SmartLightFAQ.tsv"
            };
            KnowledgeBaseService service = new KnowledgeBaseService();

            //Act
            var acutal = await service.DownloadKnowledgeBaseContents(subKey, knowledgeBaseId, env, srcs);

            // Assert
            Assert.IsTrue(!string.IsNullOrEmpty(acutal));
        }
Пример #8
0
        public async Task Test_Delete_Knowledge_Base_Async_Should_Ret_Status_Success()
        {
            // Arrange
            // SmartLightFAQ.tsv CustomerServiceFAQ.tsv SampleFAQ.tsv
            List <string> srcs = new List <string>()
            {
                "SampleFAQ.tsv"
            };
            KnowledgeBaseService service = new KnowledgeBaseService();

            // Act
            var actual = await service.DeleteKnowledgeBase(subKey, knowledgeBaseId, srcs);

            // Assert
            Assert.AreEqual(ActionStatus.Success, actual.ResultStatus);
        }
Пример #9
0
        public void GetAsync_NewKB()
        {
            var knowledgeBase = new KnowledgeBase();

            var knowledgeBaseRepository = new Mock <IKnowledgeBaseRepository>();

            knowledgeBaseRepository.Setup(x => x.GetAsync(It.IsAny <string>()))
            .Returns(Task.FromResult((IKnowledgeBase)knowledgeBase));

            var service = new KnowledgeBaseService(knowledgeBaseRepository.Object, Mock.Of <ILogger <KnowledgeBaseService> >());

            var result = service.GetAsync("testId").Result;

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.KnowledgeBase);
        }
Пример #10
0
        public async Task <List <KnowledgeBaseModel> > FetchAllKnowledgeBaseData()
        {
            var knowledgeBaseService = new KnowledgeBaseService();

            KnowledgeBaseModel[] allKnowledge = await knowledgeBaseService.FetchAllKnowledgeBaseAsync();

            if (allKnowledge != null && allKnowledge.Length > 0)
            {
                List <KnowledgeBaseModel> allKnowledgeData = allKnowledge.ToList();
                return(allKnowledgeData);
            }
            else
            {
                Debug.WriteLine("KnowledgeBase data is empty on KnowledgeBase Category page");
                return(null);
            }
        }
Пример #11
0
        public void CreateAsync_ExistingKB()
        {
            var knowledgeBaseResource = new KnowledgeBaseResource {
                KnowledgeBase = new KnowledgeBase()
            };

            var knowledgeBaseRepository = new Mock <IKnowledgeBaseRepository>();

            knowledgeBaseRepository.Setup(x => x.CountAsync(It.IsAny <Expression <Func <IKnowledgeBase, bool> > >()))
            .Returns(Task.FromResult((long)1));

            var service = new KnowledgeBaseService(knowledgeBaseRepository.Object, Mock.Of <ILogger <KnowledgeBaseService> >());

            var result = service.CreateAsync(knowledgeBaseResource.KnowledgeBase).Result;

            Assert.IsNull(result);
        }
Пример #12
0
        public void UpdateAsync_MissingKB()
        {
            var knowledgeBase = new KnowledgeBase {
                Id = "testId"
            };
            var updateResponse = new ReplaceOneResult.Acknowledged(0, 0, new BsonString("testId"));

            var knowledgeBaseRepository = new Mock <IKnowledgeBaseRepository>();

            knowledgeBaseRepository.Setup(x => x.UpdateAsync(It.IsAny <string>(), It.IsAny <IKnowledgeBase>()))
            .Returns(Task.FromResult((ReplaceOneResult)updateResponse));

            var service = new KnowledgeBaseService(knowledgeBaseRepository.Object, Mock.Of <ILogger <KnowledgeBaseService> >());

            var result = service.UpdateAsync("testId", knowledgeBase).Result;

            Assert.IsNull(result);
        }
Пример #13
0
 public ActionResult KnowledgeBaseDetail(int KnowledgeBaseId)
 {
     try
     {
         var                  db         = new dbTIREntities();
         SiteUser             su         = (SiteUser)Session["SiteUser"];
         KnowledgeBaseService kbService  = new KnowledgeBaseService(su, db);
         int                  DistrictId = su.Districts[0].Id;
         var                  listdata   = kbService.GetKnowledgeBaseDetail(KnowledgeBaseId, DistrictId);
         return(View(listdata));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
Пример #14
0
 public ActionResult Index()
 {
     try
     {
         var                  db                 = new dbTIREntities();
         SiteUser             su                 = (SiteUser)Session["SiteUser"];
         KnowledgeBaseService kbService          = new KnowledgeBaseService(su, db);
         List <KnowledgeBase> KnowledgeBaseItems = new List <KnowledgeBase>();
         KnowledgeBaseItems = kbService.GetKnowledgeBase().ToList();
         ViewBag.AllowEdit  = HelperService.AllowUiEdits(su.RoleDesc, "USER");
         return(View(KnowledgeBaseItems));
     }
     catch (Exception ex)
     {
         Logging log = new Logging();
         log.LogException(ex);
         return(View("GeneralError"));
     }
 }
Пример #15
0
            public async Task <NetworkOverviewModel> Handle(Query request, CancellationToken cancellationToken)
            {
                var service = new KnowledgeBaseService <NetworkOverviewModel>();

                return(await service.Get(request));
            }