Beispiel #1
0
        public async Task RedirectToRoute_WhenParameterIsValid()
        {
            var businessServiceMocked = new Mock <IBusinessService>();
            var mapperMocked          = new Mock <IMappingProvider>();
            var facilityServiceMocked = new Mock <IFacilityService>();
            var pictureHelper         = new Mock <IPictureHelper>();
            var coverPictureMock      = new Mock <IFormFile>();
            var pictureMock           = new Mock <IFormFile>();
            var businessDTO           = new BusinessDTO {
                BusinessId = 1
            };

            var name           = "Ivan";
            var location       = "Tuk";
            var gpsCoordinates = "3424444";
            var about          = "ok";
            var shortDesc      = "ok";
            var coverPicture   = coverPictureMock.Object;
            var pictures       = new List <IFormFile> {
                pictureMock.Object
            };
            var facilitiesForTheBusiness = new List <int> {
                1
            };

            var createBusinessViewModel = new CreateBusinessViewModel
            {
                Name                     = name,
                Location                 = location,
                GPSCoordinates           = gpsCoordinates,
                About                    = about,
                ShortDescription         = shortDesc,
                CoverPicture             = coverPicture,
                Pictures                 = pictures,
                FacilitiesForTheBusiness = facilitiesForTheBusiness
            };

            businessServiceMocked.Setup(b => b.CreateBusiness(name, location, gpsCoordinates, about, shortDesc, null, new List <string> {
                null
            }, facilitiesForTheBusiness))
            .ReturnsAsync(businessDTO);

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

            var result = await businessController.CreateBusiness(createBusinessViewModel) as RedirectToRouteResult;;
            var route  = result.RouteValues.Values.ToList();

            Assert.AreEqual("Business", route[0]);
            Assert.AreEqual("Details", route[1]);
            Assert.AreEqual(1, route[2]);
        }
Beispiel #2
0
        public async Task CallbusinessServiceOnce_WhenParameterIsValid()
        {
            var businessServiceMocked = new Mock <IBusinessService>();
            var mapperMocked          = new Mock <IMappingProvider>();
            var facilityServiceMocked = new Mock <IFacilityService>();
            var pictureHelper         = new Mock <IPictureHelper>();
            var coverPictureMock      = new Mock <IFormFile>();
            var pictureMock           = new Mock <IFormFile>();
            var businessDTO           = new BusinessDTO {
                BusinessId = 1
            };

            var name           = "Ivan";
            var location       = "Tuk";
            var gpsCoordinates = "3424444";
            var about          = "ok";
            var shortDesc      = "ok";
            var coverPicture   = coverPictureMock.Object;
            var pictures       = new List <IFormFile> {
                pictureMock.Object
            };
            var facilitiesForTheBusiness = new List <int> {
                1
            };

            var createBusinessViewModel = new CreateBusinessViewModel
            {
                Name                     = name,
                Location                 = location,
                GPSCoordinates           = gpsCoordinates,
                About                    = about,
                ShortDescription         = shortDesc,
                CoverPicture             = coverPicture,
                Pictures                 = pictures,
                FacilitiesForTheBusiness = facilitiesForTheBusiness
            };

            businessServiceMocked.Setup(b => b.CreateBusiness(name, location, gpsCoordinates, about, shortDesc, null, new List <string> {
                null
            }, facilitiesForTheBusiness))
            .ReturnsAsync(businessDTO);

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

            await businessController.CreateBusiness(createBusinessViewModel);

            businessServiceMocked.Verify(b => b.CreateBusiness(name, location, gpsCoordinates, about, shortDesc, null, new List <string> {
                null
            }, facilitiesForTheBusiness), Times.Once);
        }
Beispiel #3
0
        public async Task CallFacilityServiceOnce()
        {
            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.CreateBusiness();

            facilityServiceMocked.Verify(f => f.ListAllFacilitiesAsync(), Times.Once);
        }
Beispiel #4
0
        public async Task ReturnCorrectViewModel_WhenModelIsInvalid()
        {
            var businessServiceMocked   = new Mock <IBusinessService>();
            var mapperMocked            = new Mock <IMappingProvider>();
            var facilityServiceMocked   = new Mock <IFacilityService>();
            var pictureHelper           = new Mock <IPictureHelper>();
            var createBusinessViewModel = new CreateBusinessViewModel();

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

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

            var result = await businessController.CreateBusiness(createBusinessViewModel) as ViewResult;

            Assert.IsInstanceOfType(result.Model, typeof(CreateBusinessViewModel));
        }
Beispiel #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 facilityDTOs          = new List <FacilityDTO> {
                new FacilityDTO()
            };
            var createBusinessVM = new CreateBusinessViewModel();

            facilityServiceMocked.Setup(f => f.ListAllFacilitiesAsync())
            .ReturnsAsync(facilityDTOs);

            mapperMocked.Setup(m => m.MapTo <CreateBusinessViewModel>(facilityDTOs))
            .Returns(createBusinessVM);

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

            var result = await accountController.CreateBusiness() as ViewResult;

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