public async Task ReturnCorrectViewModel()
        {
            var businessId            = 1;
            var date                  = new DateTime(2019, 6, 16);
            var logsDeleted           = 1;
            var businessServiceMocked = new Mock <IBusinessService>();
            var mapperMocked          = new Mock <IMappingProvider>();
            var facilityServiceMocked = new Mock <IFacilityService>();
            var pictureHelper         = new Mock <IPictureHelper>();
            var deleteLogsViewModel   = new DeleteLogsViewModel
            {
                BusinessId = businessId,
                Date       = date
            };

            businessServiceMocked.Setup(b => b.DeleteLogsForDate(businessId, date))
            .ReturnsAsync(logsDeleted);

            var businessController = new BusinessController(businessServiceMocked.Object,
                                                            mapperMocked.Object, facilityServiceMocked.Object, pictureHelper.Object);

            var result = await businessController.DeleteLogsForBusiness(deleteLogsViewModel);

            Assert.IsInstanceOfType(result, typeof(JsonResult));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> DeleteLogsForBusiness(DeleteLogsViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest("Invalid parameters!"));
            }

            var logsDeleted = await this.businessService.DeleteLogsForDate(model.BusinessId, model.Date);

            return(Json(logsDeleted));
        }
        public async Task ReturnBadRequest_WhenModelIsInvalid()
        {
            var businessServiceMocked = new Mock <IBusinessService>();
            var mapperMocked          = new Mock <IMappingProvider>();
            var facilityServiceMocked = new Mock <IFacilityService>();
            var pictureHelper         = new Mock <IPictureHelper>();
            var deleteLogsViewModel   = new DeleteLogsViewModel();

            var businessController = new BusinessController(businessServiceMocked.Object,
                                                            mapperMocked.Object, facilityServiceMocked.Object, pictureHelper.Object);

            businessController.ModelState.AddModelError("error", "error");

            var result = await businessController.DeleteLogsForBusiness(deleteLogsViewModel);

            Assert.AreEqual(result.GetType(), typeof(BadRequestObjectResult));
        }
        public async Task CallBusinessServiceOnce()
        {
            var businessId            = 1;
            var date                  = new DateTime(2019, 6, 16);
            var businessServiceMocked = new Mock <IBusinessService>();
            var mapperMocked          = new Mock <IMappingProvider>();
            var facilityServiceMocked = new Mock <IFacilityService>();
            var pictureHelper         = new Mock <IPictureHelper>();
            var deleteLogsViewModel   = new DeleteLogsViewModel
            {
                BusinessId = businessId,
                Date       = date
            };

            var businessController = new BusinessController(businessServiceMocked.Object,
                                                            mapperMocked.Object, facilityServiceMocked.Object, pictureHelper.Object);

            await businessController.DeleteLogsForBusiness(deleteLogsViewModel);

            businessServiceMocked.Verify(a => a.DeleteLogsForDate(businessId, date), Times.Once);
        }
Exemplo n.º 5
0
        public async Task ReturnCorrectViewModel()
        {
            var businessServiceMocked = new Mock <IBusinessService>();
            var mapperMocked          = new Mock <IMappingProvider>();
            var facilityServiceMocked = new Mock <IFacilityService>();
            var pictureHelper         = new Mock <IPictureHelper>();
            var businessDTOs          = new List <BusinessDTO> {
                new BusinessDTO()
            };
            var deleteLogsViewModel = new DeleteLogsViewModel();

            businessServiceMocked.Setup(b => b.ListAllBusinessesAsync <BusinessDTO>())
            .ReturnsAsync(businessDTOs);

            mapperMocked.Setup(m => m.MapTo <DeleteLogsViewModel>(businessDTOs))
            .Returns(deleteLogsViewModel);

            var businessController = new BusinessController(businessServiceMocked.Object,
                                                            mapperMocked.Object, facilityServiceMocked.Object, pictureHelper.Object);

            var result = await businessController.DeleteLogsForBusiness() as ViewResult;

            Assert.IsInstanceOfType(result.Model, typeof(DeleteLogsViewModel));
        }