public async void Successfully_registers_api()
        {
            var pharmacy   = CreatePharmacy.CreateValidTestObject();
            var controller = GetPharmacyController();

            var result = await controller.ApiRegister(new PharmacySystemDTO { Name = pharmacy.Name, ApiKey = pharmacy.ApiKey, Url = pharmacy.Url });

            Assert.IsType <RedirectToActionResult>(result);
        }
        public async void Does_not_successfully_register_api()
        {
            var pharmacy   = CreatePharmacy.CreateInvalidTestObject();
            var controller = GetPharmacyController();

            controller.ModelState.AddModelError("Url", "Required");

            var result = await controller.ApiRegister(new PharmacySystemDTO { Name = pharmacy.Name, ApiKey = pharmacy.ApiKey, Url = pharmacy.Url });

            Assert.IsType <BadRequestObjectResult>(result);
        }
Exemple #3
0
        private PharmacyController GetPharmacyController()
        {
            var pharmacy = CreatePharmacy.CreateValidTestObject();

            pharmacy.Id = 1;
            PharmacySystem pharmacyNull        = null;
            var            pharmacyServiceMock = new Mock <IPharmacySystemService>();

            pharmacyServiceMock.Setup(p => p.Get(It.Is <int>(i => i == 1))).Returns(Task.Run(() => pharmacy));
            pharmacyServiceMock.Setup(p => p.Get(It.Is <int>(i => i != 1))).Returns(Task.Run(() => pharmacyNull));

            return(new PharmacyController(pharmacyServiceMock.Object));
        }