public async void GetByName_InvalidName(string prettyName)
        {
            Mock <IDrugsQueryService> querySvc = new Mock <IDrugsQueryService>();

            querySvc.Setup(
                svc => svc.GetByName(
                    It.IsAny <string>()
                    )
                )
            .Returns(Task.FromResult(new DrugTerm()));

            // Call the controller, we don't care about the actual return value.
            DrugsController controller = new DrugsController(NullLogger <DrugsController> .Instance, querySvc.Object);

            var exception = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.GetByName(prettyName)
                );

            // Verify the service layer doesn't get called at all.
            querySvc.Verify(
                svc => svc.GetByName(It.IsAny <string>()),
                Times.Never
                );

            Assert.Equal("You must specify the prettyUrlName parameter.", exception.Message);
            Assert.Equal(400, exception.HttpStatusCode);
        }
        public void EditValidCheck()
        {
            MockDrugRepository mock = new MockDrugRepository();
            DrugsController    drug = new DrugsController(mock);
            Drug newDrug            = new Drug
            {
                DrugID       = 16,
                Description  = "Lucentis",
                Form         = "tablet",
                Route        = "Oral",
                IsRestricted = true,
                Name         = "Lucentis",
                Purpose      = "Eye Blindness",
                Rate         = 150
            };

            drug.Create(newDrug);

            newDrug.Purpose = "Eye Blindness and color blindness";

            drug.Edit(newDrug);
            ViewResult result = drug.Details(16) as ViewResult;

            Assert.AreEqual("Eye Blindness and color blindness", ((Drug)result.Model).Purpose);
        }
        public async void Expand_InvalidSize()
        {
            // Create a mock query that always returns the same result.
            Mock <IDrugsQueryService> querySvc = new Mock <IDrugsQueryService>();

            querySvc.Setup(
                svc => svc.Expand(
                    It.IsAny <char>(),
                    It.IsAny <int>(),
                    It.IsAny <int>(),
                    It.IsAny <DrugResourceType[]>(),
                    It.IsAny <TermNameType[]>(),
                    It.IsAny <TermNameType[]>()
                    )
                )
            .Returns(Task.FromResult(new DrugTermResults()));

            // Call the controller, we don't care about the actual return value.
            DrugsController controller = new DrugsController(NullLogger <DrugsController> .Instance, querySvc.Object);
            await controller.Expand('s', -1, DEFAULT_SEARCH_FROM,
                                    DEFAULT_DRUG_RESOURCE_TYPE_LIST,
                                    DEFAULT_INCLUDED_TERM_TYPE_LIST,
                                    DEFAULT_EXCLUDED_TERM_TYPE_LIST
                                    );

            // Verify that the query layer is called:
            //  a) with the expected updated values for size.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.Expand('s', DEFAULT_SEARCH_SIZE, DEFAULT_SEARCH_FROM,
                                  DEFAULT_DRUG_RESOURCE_TYPE_LIST, DEFAULT_INCLUDED_TERM_TYPE_LIST, DEFAULT_EXCLUDED_TERM_TYPE_LIST),
                Times.Once,
                "ITermsQueryService::Expand() should be called once, with the updated value for size"
                );
        }
        public async void GetAll_RequiredParametersOnly()
        {
            // Create a mock query that always returns the same result.
            Mock <IDrugsQueryService> querySvc = new Mock <IDrugsQueryService>();

            querySvc.Setup(
                svc => svc.GetAll(
                    It.IsAny <int>(),
                    It.IsAny <int>(),
                    It.IsAny <DrugResourceType[]>(),
                    It.IsAny <TermNameType[]>(),
                    It.IsAny <TermNameType[]>()
                    )
                )
            .Returns(Task.FromResult(new DrugTermResults()));

            // Call the controller, we don't care about the actual return value.
            DrugsController controller = new DrugsController(NullLogger <DrugsController> .Instance, querySvc.Object);
            await controller.GetAll();

            // Verify that the query layer is called:
            //  a) with the expected updated values for size, from, and requestedFields.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.GetAll(DEFAULT_SEARCH_SIZE, DEFAULT_SEARCH_FROM,
                                  DEFAULT_DRUG_RESOURCE_TYPE_LIST,
                                  DEFAULT_INCLUDED_TERM_TYPE_LIST,
                                  DEFAULT_EXCLUDED_TERM_TYPE_LIST),
                Times.Once,
                "ITermsQueryService::GetAll() should be called once, using default values."
                );
        }
Example #5
0
        public async void Search_InvalidSearchString(string query)
        {
            Mock <IDrugsQueryService> querySvc = new Mock <IDrugsQueryService>();

            querySvc.Setup(
                svc => svc.Search(
                    It.IsAny <string>(),
                    It.IsAny <MatchType>(),
                    It.IsAny <int>(),
                    It.IsAny <int>()
                    )
                )
            .Returns(Task.FromResult(new DrugTermResults()));

            // Call the controller, we don't care about the actual return value.
            DrugsController controller = new DrugsController(NullLogger <DrugsController> .Instance, querySvc.Object);

            var exception = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.Search(query)
                );

            // Verify the service layer doesn't get called at all.
            querySvc.Verify(
                svc => svc.Search(
                    It.IsAny <string>(),
                    It.IsAny <MatchType>(),
                    It.IsAny <int>(),
                    It.IsAny <int>()
                    ),
                Times.Never
                );

            Assert.Equal("You must specify a search string.", exception.Message);
            Assert.Equal(400, exception.HttpStatusCode);
        }
        public void DetailsNotNullCheck()
        {
            MockDrugRepository mock   = new MockDrugRepository();
            DrugsController    drug   = new DrugsController(mock);
            ViewResult         result = drug.Details(1) as ViewResult;

            Assert.IsNotNull(result);
        }
        public void DetailsValidNameCheck()
        {
            MockDrugRepository mock   = new MockDrugRepository();
            DrugsController    drug   = new DrugsController(mock);
            ViewResult         result = drug.Details(1) as ViewResult;

            Assert.AreEqual("Paracetamol", ((Drug)result.Model).Name);
        }
        public void DetailsValidDrugIDCheck()
        {
            MockDrugRepository mock   = new MockDrugRepository();
            DrugsController    drug   = new DrugsController(mock);
            ViewResult         result = drug.Details(1) as ViewResult;

            Assert.AreEqual(1, ((Drug)result.Model).DrugID);
        }
        public void IndexViewNameCheck()
        {
            MockDrugRepository mock   = new MockDrugRepository();
            DrugsController    drug   = new DrugsController(mock);
            ViewResult         result = drug.Index() as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }
        public async void GetByName_ValidName()
        {
            const string theName = "iodinated-contrast-agent";

            DrugTerm testTerm = new DrugTerm()
            {
                Aliases = new TermAlias[] {
                    new TermAlias()
                    {
                        Type = TermNameType.Synonym,
                        Name = "contrast dye, iodinated"
                    },
                    new TermAlias()
                    {
                        Type = TermNameType.LexicalVariant,
                        Name = "Iodinated Contrast Agent"
                    }
                },
                Definition = new Definition()
                {
                    Html = "A contrast agent containing an iodine-based dye used in many diagnostic imaging examinations, including computed tomography, angiography, and myelography. Check for <a ref=\"https://www.cancer.gov/about-cancer/treatment/clinical-trials/intervention/C28500\">active clinical trials</a> using this agent. (<a ref=\"https://ncit.nci.nih.gov/ncitbrowser/ConceptReport.jsp?dictionary=NCI%20Thesaurus&code=C28500\">NCI Thesaurus</a>)",
                    Text = "A contrast agent containing an iodine-based dye used in many diagnostic imaging examinations, including computed tomography, angiography, and myelography. Check for active clinical trials using this agent. (NCI Thesaurus)"
                },
                DrugInfoSummaryLink = null,
                FirstLetter         = 'i',
                Name           = "iodinated contrast dye",
                NCIConceptId   = "C28500",
                NCIConceptName = "Iodinated Contrast Agent",
                PrettyUrlName  = "iodinated-contrast-agent",
                TermId         = 37780,
                TermNameType   = TermNameType.PreferredName,
                Type           = DrugResourceType.DrugTerm
            };

            Mock <IDrugsQueryService> querySvc = new Mock <IDrugsQueryService>();

            querySvc.Setup(
                svc => svc.GetByName(
                    It.IsAny <string>()
                    )
                )
            .Returns(Task.FromResult(testTerm));

            // Call the controller, we don't care about the actual return value.
            DrugsController controller = new DrugsController(NullLogger <DrugsController> .Instance, querySvc.Object);
            DrugTerm        actual     = await controller.GetByName(theName);

            Assert.Equal(testTerm, actual);

            // Verify that the query layer is called:
            //  a) with the ID value.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.GetByName(theName),
                Times.Once,
                $"ITermsQueryService::GetByName() should be called once, with id = '{theName}"
                );
        }
        public void DrugByName_InValid_DrugDetails()
        {
            var mock = new Mock <DrugRepository>();

            mock.Setup(p => p.searchDrugsByName("Aciloc")).Returns(pcm);
            DrugsController con  = new DrugsController(mock.Object);
            var             data = con.GetDrugDetailByName("Aciloc") as OkObjectResult;

            Assert.AreEqual(200, data.StatusCode);
        }
        public void DrugByID_Location_InValid_DrugDetails()
        {
            var mock = new Mock <DrugRepository>();

            mock.Setup(p => p.GetDispatchableDrugStock(1, "Kolkata")).Returns(claimList);
            DrugsController con  = new DrugsController(mock.Object);
            var             data = con.getDispatchableDrugStock(10, "Kolkata") as OkObjectResult;

            Assert.AreEqual(200, data.StatusCode);
        }
        public void IndexObjectsCheck()
        {
            MockDrugRepository mock   = new MockDrugRepository();
            DrugsController    drug   = new DrugsController(mock);
            ViewResult         result = drug.Index() as ViewResult;
            IEnumerable <Drug> data   = (IEnumerable <Drug>)result.Model;
            List <Drug>        list   = new List <Drug>(mock.GetAllDrugs());

            CollectionAssert.Contains(data.ToList(), list[0]);
            CollectionAssert.Contains(data.ToList(), list[1]);
        }
        public void CreateNotNullCheck()
        {
            MockDrugRepository mock = new MockDrugRepository();
            DrugsController    drug = new DrugsController(mock);
            Drug newDrug            = new Drug {
                DrugID       = 3,
                Description  = "Insulin injection",
                Form         = "Inject",
                Route        = "Injection",
                IsRestricted = false,
                Name         = "Insulin",
                Purpose      = "Sugar control",
                Rate         = 100
            };
            ViewResult createResult = drug.Create(newDrug) as ViewResult;
            ViewResult result       = drug.Details(3) as ViewResult;

            Assert.IsNotNull(result);
        }
        public void CreateSuccessCheck()
        {
            MockDrugRepository mock = new MockDrugRepository();
            DrugsController    drug = new DrugsController(mock);
            Drug newDrug            = new Drug
            {
                DrugID       = 5,
                Description  = "Amoxylin antibiotic",
                Form         = "Liquid",
                Route        = "Oral",
                IsRestricted = false,
                Name         = "Insulin",
                Purpose      = "cold and cough",
                Rate         = 50
            };
            ViewResult createResult = drug.Create(newDrug) as ViewResult;
            ViewResult result       = drug.Details(5) as ViewResult;

            Assert.AreEqual(5, ((Drug)result.Model).DrugID);
        }
        public void CreateViewNameCheck()
        {
            MockDrugRepository mock = new MockDrugRepository();
            DrugsController    drug = new DrugsController(mock);
            Drug newDrug            = new Drug
            {
                DrugID       = 4,
                Description  = "Penicillin",
                Form         = "Inject",
                Route        = "Injection",
                IsRestricted = true,
                Name         = "Penicillin",
                Purpose      = "Antibiotic",
                Rate         = 200
            };

            RedirectToRouteResult result = (RedirectToRouteResult)drug.Create(newDrug);

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public async void GetById_InvalidId(long id)
        {
            Mock <IDrugsQueryService> querySvc = new Mock <IDrugsQueryService>();

            querySvc.Setup(
                svc => svc.GetById(
                    It.IsAny <int>()
                    )
                )
            .Returns(Task.FromResult(new DrugTerm()));

            // Call the controller, we don't care about the actual return value.
            DrugsController controller = new DrugsController(NullLogger <DrugsController> .Instance, querySvc.Object);

            var exception = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.GetById(id)
                );

            Assert.Equal($"Not a valid ID '{id}'.", exception.Message);
            Assert.Equal(400, exception.HttpStatusCode);
        }
Example #18
0
        static void Main(string[] args)
        {
            var repository = new DrugsEFRepository();
            var service    = new DrugServise(repository);
            var controller = new DrugsController(service);

            var drugPostModel = new DrugPostModel
            {
                Name = "Isoniazid Entity Frame",
                MedicinalSubstance = "Isoniazid Entity",
                FormId             = 1,
            };

            controller.Create(drugPostModel);

            var drugs = controller.GetAll();



            System.Console.WriteLine(drugs);
            System.Console.ReadLine();
        }
Example #19
0
        public async Task GetDrugs_Test()
        {
            var drugName   = "viagra";
            var customerID = Guid.NewGuid();
            var customer   = new CustomerPoco()
            {
                CustomerId = customerID
            };
            // Arrange
            var mockDrugService = new Mock <IDrugsService>();

            mockDrugService.Setup(x => x.GetDrugs(customerID, drugName))
            .Returns(Task.FromResult <IEnumerable <DrugPoco> >(new List <DrugPoco>()
            {
                new DrugPoco()
                {
                    DrugName = "viagra"
                }
            }));

            var mockCustomersService = new Mock <ICustomersService>();

            mockCustomersService.Setup(x => x.GetCustomer(customerID))
            .Returns(Task.FromResult(customer));


            // Arrange
            var controller = new DrugsController(mockDrugService.Object, mockCustomersService.Object);

            // Act
            var drugs = await controller.GetDrugs(drugName);


            // Assert
            Assert.NotNull(drugs);
            //Assert.Single(drugs);
        }
        public void DeleteViewNameCheck()
        {
            MockDrugRepository mock = new MockDrugRepository();
            DrugsController    drug = new DrugsController(mock);

            Drug newDrug = new Drug
            {
                DrugID       = 10,
                Description  = "A dummy medicine",
                Form         = "Capsule",
                Route        = "Oral",
                IsRestricted = false,
                Name         = "Dummy",
                Purpose      = "Does not do anything",
                Rate         = 100
            };

            drug.Create(newDrug);


            RedirectToRouteResult result = (RedirectToRouteResult)drug.DeleteConfirmed(10);

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public void EditViewNameCheck()
        {
            MockDrugRepository mock = new MockDrugRepository();
            DrugsController    drug = new DrugsController(mock);
            Drug newDrug            = new Drug
            {
                DrugID       = 15,
                Description  = "Galvus",
                Form         = "tablet",
                Route        = "Oral",
                IsRestricted = true,
                Name         = "Galvus",
                Purpose      = "Diabetes",
                Rate         = 150
            };

            drug.Create(newDrug);

            newDrug.Purpose = "controls diabetes and sugar level";

            RedirectToRouteResult result = (RedirectToRouteResult)drug.Edit(newDrug);

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public async void ExpandTerms()
        {
            Mock <IDrugsQueryService> termsQueryService = new Mock <IDrugsQueryService>();
            DrugsController           controller        = new DrugsController(NullLogger <DrugsController> .Instance, termsQueryService.Object);

            DrugTermResults drugTermResults = new DrugTermResults()
            {
                Results = new DrugTerm[] {
                    new DrugTerm()
                    {
                        TermId      = 475765,
                        Name        = "siltuximab",
                        FirstLetter = 's',
                        //Type = DrugResourceType.DrugTerm,
                        TermNameType  = TermNameType.PreferredName,
                        PrettyUrlName = "siltuximab",
                        Aliases       = new TermAlias[]
                        {
                            new TermAlias()
                            {
                                Type = TermNameType.CodeName,
                                Name = "CNTO 328"
                            },
                            new TermAlias()
                            {
                                Type = TermNameType.LexicalVariant,
                                Name = "anti-IL-6 chimeric monoclonal antibody"
                            },
                            new TermAlias()
                            {
                                Type = TermNameType.CASRegistryName,
                                Name = "541502-14-1"
                            },
                            new TermAlias()
                            {
                                Type = TermNameType.USBrandName,
                                Name = "Sylvant"
                            }
                        },
                        Definition = new Definition()
                        {
                            Text = "A chimeric, human-murine, monoclonal antibody targeting the pro-inflammatory cytokine interleukin 6 (IL-6), with antitumor and anti-inflammatory activities. Upon intravenous administration of siltuximab, this agent targets and binds to IL-6. This inhibits the binding of IL-6 to the IL-6 receptor (IL-6R), which results in the blockade of the IL-6/IL-6R-mediated signal transduction pathway. This inhibits cancer cell growth in tumors overexpressing IL-6. Check for active clinical trials using this agent. (NCI Thesaurus)",
                            Html = "A chimeric, human-murine, monoclonal antibody targeting the pro-inflammatory cytokine interleukin 6 (IL-6), with antitumor and anti-inflammatory activities. Upon intravenous administration of siltuximab, this agent targets and binds to IL-6. This inhibits the binding of IL-6 to the IL-6 receptor (IL-6R), which results in the blockade of the IL-6/IL-6R-mediated signal transduction pathway. This inhibits cancer cell growth in tumors overexpressing IL-6. Check for <a ref=\"https://www.cancer.gov/about-cancer/treatment/clinical-trials/intervention/C61084\">active clinical trials</a> using this agent. (<a ref=\"https://ncit.nci.nih.gov/ncitbrowser/ConceptReport.jsp?dictionary=NCI%20Thesaurus&code=C61084\">NCI Thesaurus</a>)"
                        },
                        DrugInfoSummaryLink = new DrugInfoSummaryLink()
                        {
                            Text = "Siltuximab",
                            URI  = new Uri("https://www.cancer.gov/about-cancer/treatment/drugs/siltuximab")
                        },
                        NCIConceptId   = "C61084",
                        NCIConceptName = "Siltuximab"
                    },
                    new DrugTerm()
                    {
                        TermId        = 674543,
                        Name          = "silver nitrate",
                        FirstLetter   = 's',
                        Type          = DrugResourceType.DrugTerm,
                        TermNameType  = TermNameType.PreferredName,
                        PrettyUrlName = "silver-nitrate"
                        , Aliases     = new TermAlias[]
                        {
                            new TermAlias()
                            {
                                Type = TermNameType.CASRegistryName,
                                Name = "7761-88-8"
                            }
                        },
                        Definition = new Definition()
                        {
                            Text = "An inorganic chemical with antiseptic activity. Silver nitrate can potentially be used as a cauterizing or sclerosing agent. Check for active clinical trials using this agent. (NCI Thesaurus)",
                            Html = "An inorganic chemical with antiseptic activity. Silver nitrate can potentially be used as a cauterizing or sclerosing agent. Check for <a ref=\"https://www.cancer.gov/about-cancer/treatment/clinical-trials/intervention/C77057\">active clinical trials</a> using this agent. (<a ref=\"https://ncit.nci.nih.gov/ncitbrowser/ConceptReport.jsp?dictionary=NCI%20Thesaurus&code=C77057\">NCI Thesaurus</a>)"
                        },
                        NCIConceptId   = "C77057",
                        NCIConceptName = "Silver Nitrate"
                    },
                },
                Meta = new ResultsMetadata()
                {
                    TotalResults = 854,
                    From         = 10
                },
                Links = null
            };

            termsQueryService.Setup(
                termQSvc => termQSvc.Expand(
                    It.IsAny <char>(),
                    It.IsAny <int>(),
                    It.IsAny <int>(),
                    It.IsAny <DrugResourceType[]>(),
                    It.IsAny <TermNameType[]>(),
                    It.IsAny <TermNameType[]>()
                    )
                )
            .Returns(Task.FromResult(drugTermResults));

            DrugTermResults actualReslts = await controller.Expand('s', 5, 10, DEFAULT_DRUG_RESOURCE_TYPE_LIST,
                                                                   DEFAULT_INCLUDED_TERM_TYPE_LIST, DEFAULT_EXCLUDED_TERM_TYPE_LIST);

            // Verify that the service layer is called:
            //  a) with the expected values.
            //  b) exactly once.
            termsQueryService.Verify(
                svc => svc.Expand('s', 5, 10, DEFAULT_DRUG_RESOURCE_TYPE_LIST,
                                  DEFAULT_INCLUDED_TERM_TYPE_LIST, DEFAULT_EXCLUDED_TERM_TYPE_LIST),
                Times.Once
                );

            // What we're really doing is verifying that Expand() returns the same
            // object it received from the service. If Expand() ever implements logic
            // to do its own processing, this test will need to change.
            Assert.Equal(drugTermResults, actualReslts, new DrugTermResultsComparer());
        }