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 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 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
            }));
        }
Beispiel #4
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 CreateActionBenefit_Valid_VerifyCreateActionBenefit()
        {
            var mockPharmacyRepo      = new Mock <IPharmacyRepo>();
            var mockActionBenefitRepo = new Mock <IActionBenefitRepository>();
            var exchange = "ex1";
            var pharmacy = new PharmacySystem {
                Id = 1, Name = "apoteka1", ApiKey = "api1", Url = "url1", ActionsBenefitsExchangeName = exchange, ActionsBenefitsSubscribed = true
            };
            var message = new ActionBenefitMessage("akcija1", "blablabla");

            mockPharmacyRepo.Setup(r => r.GetPharmacyByExchangeName(exchange)).Returns(pharmacy);
            mockActionBenefitRepo.Setup(r => r.CreateActionBenefit(It.Is <ActionBenefit>(ab => ab.PharmacyId == pharmacy.Id && ab.Message.Message == message.Message && ab.Message.Subject == message.Subject))).Verifiable();
            ActionBenefitService actionBenefitService = new ActionBenefitService(mockActionBenefitRepo.Object, mockPharmacyRepo.Object);

            actionBenefitService.CreateActionBenefit(exchange, message);

            mockActionBenefitRepo.Verify();
        }