public void Details_ReturnsActionBenfit_Id_1()
        {
            DbContextInMemory    testData             = new DbContextInMemory();
            MyDbContext          context              = testData._context;
            ActionBenefitService actionBenefitService = new ActionBenefitService(new MySqlActionBenefitRepository(context), new MySqlPharmacyRepo(context));
            var rabbitServiceMock = new Mock <IRabbitMqActionBenefitService>();
            var controller        = new ActionBenefitServiceController(actionBenefitService, rabbitServiceMock.Object);

            var result = controller.Get(1) as OkObjectResult;

            Assert.Equal("m", ((ActionBenefit)result.Value).Message.Message);
        }
        public void CloseTender_Valid_Id()
        {
            DbContextInMemory       testData   = new DbContextInMemory();
            MyDbContext             context    = testData._context;
            TenderServiceController controller =
                new TenderServiceController(new TenderService(new MySqlTenderRepository(context)),
                                            new TenderMessageService(new MySqlTenderMessageRepository(context)),
                                            new Mock <IRabbitMqTenderingService>().Object);

            controller.CloseTender(1);
            Assert.True(context.Tenders.Find(1).IsClosed);
        }
        public void Index_ReturnsSingleItem()
        {
            DbContextInMemory    testData             = new DbContextInMemory();
            MyDbContext          context              = testData._context;
            ActionBenefitService actionBenefitService = new ActionBenefitService(new MySqlActionBenefitRepository(context), new MySqlPharmacyRepo(context));
            var rabbitServiceMock = new Mock <IRabbitMqActionBenefitService>();
            var controller        = new ActionBenefitServiceController(actionBenefitService, rabbitServiceMock.Object);

            var result = controller.GetAll() as OkObjectResult;

            Assert.IsType <List <ActionBenefit> >(result.Value);
        }
        public void PushDrugList_Invalid_List()
        {
            DbContextInMemory       testData   = new DbContextInMemory();
            MyDbContext             context    = testData._context;
            TenderServiceController controller =
                new TenderServiceController(new TenderService(new MySqlTenderRepository(context)),
                                            new TenderMessageService(new MySqlTenderMessageRepository(context)),
                                            new Mock <IRabbitMqTenderingService>().Object);

            controller.CreateTender(new TenderDTO());

            Assert.True(context.Tenders.Find(2) == null);
        }
        public void MakePublic_SetsInvalidActionBenefit_IsPublic_ToValue_ThrowException()
        {
            DbContextInMemory    testData             = new DbContextInMemory();
            MyDbContext          context              = testData._context;
            ActionBenefitService actionBenefitService = new ActionBenefitService(new MySqlActionBenefitRepository(context), new MySqlPharmacyRepo(context));
            var rabbitServiceMock = new Mock <IRabbitMqActionBenefitService>();
            var controller        = new ActionBenefitServiceController(actionBenefitService, rabbitServiceMock.Object);

            Assert.Throws <ArgumentException>(() => controller.SetPublic(new SetPublicRequest()
            {
                Id = 5, IsPublic = true
            }));
        }
Esempio n. 6
0
        public void CreateActionBenefit_Valid_Invalid_Test()
        {
            DbContextInMemory testData = new DbContextInMemory();
            MyDbContext       context  = testData._context;
            var pharmacyRepo           = new MySqlPharmacyRepo(context);
            var actionBenefitRepo      = new MySqlActionBenefitRepository(context);
            var actionBenefitService   = new ActionBenefitService(actionBenefitRepo, pharmacyRepo);
            var message = new ActionBenefitMessage("akcija1", "blablabla");

            actionBenefitService.CreateActionBenefit("exchange", message);
            Assert.Contains(context.ActionsBenefits, ab => ab.Message.Message == message.Message && ab.Message.Subject == message.Subject);

            Assert.Throws <ValidationException>(() => new ActionBenefitMessage("", ""));
        }
        public void MakePublic_SetsActionBenefit_IsPublic_ToValue()
        {
            DbContextInMemory    testData             = new DbContextInMemory();
            MyDbContext          context              = testData._context;
            ActionBenefitService actionBenefitService = new ActionBenefitService(new MySqlActionBenefitRepository(context), new MySqlPharmacyRepo(context));
            var rabbitServiceMock = new Mock <IRabbitMqActionBenefitService>();
            var controller        = new ActionBenefitServiceController(actionBenefitService, rabbitServiceMock.Object);

            Assert.False(actionBenefitService.GetActionBenefitById(1).IsPublic);
            controller.SetPublic(new SetPublicRequest()
            {
                Id = 1, IsPublic = true
            });
            Assert.True(actionBenefitService.GetActionBenefitById(1).IsPublic);
        }
        public void Order_Succesfull_But_Drug_Not_In_Database()
        {
            Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
            DbContextInMemory     testData   = new DbContextInMemory();
            MyDbContext           context    = testData._context;
            DrugServiceController controller =
                new DrugServiceController(new DrugService(new MySqlConfirmedDrugRepository(context),
                                                          new MySqlUnconfirmedDrugRepository(context),
                                                          new MySqlDrugInRoomRepository(context)),
                                          new DrugConsumptionService(new MySqlDrugConsumptionRepository(context)));

            Assert.IsType <NotFoundResult>(controller.AddQuantity(new AddDrugQuantityRequest {
                Quantity = 1, Code = "20000"
            }));
        }
        public async void Search_ForDrug_Found_And_NotFound()
        {
            DbContextInMemory testData = new DbContextInMemory();
            MyDbContext       context  = testData._context;
            var p = context.Pharmacies;

            IPharmacyService pharmacyService = new PharmacyService(new MySqlPharmacyRepo(context));
            var pharmacyServiceMock          = new Mock <IPharmacySystemService>();

            pharmacyServiceMock.Setup(s => s.GetAll()).Returns(Task.Run(() => (pharmacyService.GetAllPharmacies()).ToList()));
            var adapterContext = new Mock <IAdapterContext>();

            adapterContext.Setup(c => c.PharmacySystemAdapter.DrugAvailibility(It.Is <string>(name => name == "droga"))).Returns(
                new List <DrugDto>()
            {
                new DrugDto()
                {
                    Id = 1, Name = "droga", Quantity = 5, PharmacyDto = new PharmacyDto {
                        Id = 1, Name = "lokacija-1"
                    }
                },
                new DrugDto()
                {
                    Id = 4, Name = "drogaricin", Quantity = 5, PharmacyDto = new PharmacyDto {
                        Id = 3, Name = "lokacija-3"
                    }
                }
            }
                );
            adapterContext.Setup(c => c.PharmacySystemAdapter.DrugAvailibility(It.Is <string>(name => name != "droga"))).Returns(new List <DrugDto>());
            adapterContext.Setup(c => c.SetPharmacySystemAdapter(It.IsAny <PharmacySystem>())).Returns(new Mock <IPharmacySystemAdapter>().Object);
            adapterContext.Setup(c => c.RemoveAdapter()).Verifiable();
            DrugAvailabilityController controller = new DrugAvailabilityController(adapterContext.Object, pharmacyServiceMock.Object);

            ViewResult result = await controller.Search("droga") as ViewResult;

            adapterContext.Verify(c => c.RemoveAdapter());
            Assert.NotEmpty((IEnumerable <SearchResultDto>)result.Model);

            result = await controller.Search("nesto") as ViewResult;

            adapterContext.Verify(c => c.RemoveAdapter());
            Assert.Empty((IEnumerable <SearchResultDto>)result.Model);
        }
        public void Order_Succesfull()
        {
            Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
            DbContextInMemory     testData   = new DbContextInMemory();
            MyDbContext           context    = testData._context;
            DrugServiceController controller =
                new DrugServiceController(new DrugService(new MySqlConfirmedDrugRepository(context),
                                                          new MySqlUnconfirmedDrugRepository(context),
                                                          new MySqlDrugInRoomRepository(context)),
                                          new DrugConsumptionService(new MySqlDrugConsumptionRepository(context)));

            var quantityBefore = context.Drugs.Find(1).Quantity;

            controller.AddQuantity(new AddDrugQuantityRequest {
                Quantity = 1, Code = "20033"
            });
            var quantityAfter = context.Drugs.Find(1).Quantity;

            Assert.True(quantityAfter - quantityBefore == 1);
        }
        public void PushDrugList_Valid_List()
        {
            DbContextInMemory       testData   = new DbContextInMemory();
            MyDbContext             context    = testData._context;
            TenderServiceController controller =
                new TenderServiceController(new TenderService(new MySqlTenderRepository(context)),
                                            new TenderMessageService(new MySqlTenderMessageRepository(context)),
                                            new Mock <IRabbitMqTenderingService>().Object);

            controller.CreateTender(new TenderDTO()
            {
                Name    = "tender-2",
                EndDate = new DateTime(2021, 5, 5),
                Drugs   = new List <TenderDrug>()
                {
                    new TenderDrug()
                    {
                        DrugId = 1, Quantity = 5
                    }
                }
            });

            Assert.True(context.Tenders.Find(2) != null);
        }