Пример #1
0
        public async Task ReturnCorrectViewModel()
        {
            var logbookName           = "test";
            var businessId            = 1;
            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 createLogBookViewModel = new CreateLogBookViewModel
            {
                LogBookName = logbookName,
                BusinessId  = businessId
            };

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

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

            var result = await businessController.CreateLogBook(createLogBookViewModel);

            Assert.IsInstanceOfType(result, typeof(JsonResult));
        }
Пример #2
0
        public async Task CallBusinessServiceOnce()
        {
            var businessServiceMocked = new Mock <IBusinessService>();
            var mapperMocked          = new Mock <IMappingProvider>();
            var facilityServiceMocked = new Mock <IFacilityService>();
            var pictureHelper         = new Mock <IPictureHelper>();

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

            await businessController.CreateLogBook();

            businessServiceMocked.Verify(a => a.ListAllBusinessesAsync <BusinessDTO>(), Times.Once);
        }
Пример #3
0
        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 createLogBookViewModel = new CreateLogBookViewModel();

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

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

            var result = await businessController.CreateLogBook(createLogBookViewModel);

            Assert.AreEqual(result.GetType(), typeof(BadRequestObjectResult));
        }
Пример #4
0
        public async Task CallBusinessServiceOnce()
        {
            var logbookName            = "test";
            var businessId             = 1;
            var businessServiceMocked  = new Mock <IBusinessService>();
            var mapperMocked           = new Mock <IMappingProvider>();
            var facilityServiceMocked  = new Mock <IFacilityService>();
            var pictureHelper          = new Mock <IPictureHelper>();
            var createLogBookViewModel = new CreateLogBookViewModel
            {
                LogBookName = logbookName,
                BusinessId  = businessId
            };

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

            await businessController.CreateLogBook(createLogBookViewModel);

            businessServiceMocked.Verify(a => a.AddLogBookToBusinessAsync(logbookName, businessId), Times.Once);
        }
Пример #5
0
        public async Task ThrowArgumentException_WhenLogBookExists()
        {
            var logbookName            = "test";
            var businessId             = 1;
            var businessServiceMocked  = new Mock <IBusinessService>();
            var mapperMocked           = new Mock <IMappingProvider>();
            var facilityServiceMocked  = new Mock <IFacilityService>();
            var pictureHelper          = new Mock <IPictureHelper>();
            var createLogBookViewModel = new CreateLogBookViewModel
            {
                LogBookName = logbookName,
                BusinessId  = businessId
            };

            businessServiceMocked.Setup(b => b.AddLogBookToBusinessAsync(logbookName, businessId))
            .ThrowsAsync(new ArgumentException());

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

            var result = await businessController.CreateLogBook(createLogBookViewModel);

            Assert.AreEqual(result.GetType(), typeof(BadRequestObjectResult));
        }
Пример #6
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 createLogBookViewModel = new CreateLogBookViewModel();

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

            mapperMocked.Setup(m => m.MapTo <CreateLogBookViewModel>(businessDTOs))
            .Returns(createLogBookViewModel);

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

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

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