Пример #1
0
        public async Task ThrowsArgumentExceptionTheNameIsTooLong()
        {
            var businessUnitServiceMock = new Mock <IBusinessUnitService>();
            var userServiceMock         = new Mock <IUserService>();
            var imageOptimizerMock      = new Mock <IImageOptimizer>();

            var sut = new BusinessUnitsController(businessUnitServiceMock.Object, userServiceMock.Object, imageOptimizerMock.Object);

            var businessUnitViewModel = new BusinessUnitViewModel()
            {
                Name                = new string ('a', 1000),
                Address             = "Cerni Vryh",
                PhoneNumber         = "1234567890",
                Email               = "*****@*****.**",
                Information         = "this is an information",
                CategoryId          = 1,
                TownId              = 1,
                BusinessUnitPicture = null
            };

            businessUnitServiceMock.Setup(x => x.CreateBusinnesUnitAsync(businessUnitViewModel.Name, businessUnitViewModel.Address, businessUnitViewModel.PhoneNumber, businessUnitViewModel.Email, businessUnitViewModel.Information, businessUnitViewModel.CategoryId, businessUnitViewModel.TownId, businessUnitViewModel.Picture)).ThrowsAsync(new ArgumentException());

            var actionResult = await sut.Create(businessUnitViewModel);

            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
        }
Пример #2
0
        public async Task ThrowsBadRequestWhenReviewViewModelIsNotValid()
        {
            var businessUnitServiceMock = new Mock <IBusinessUnitService>();
            var userServiceMock         = new Mock <IUserService>();
            var imageOptimizerMock      = new Mock <IImageOptimizer>();

            var sut = new BusinessUnitsController(businessUnitServiceMock.Object, userServiceMock.Object, imageOptimizerMock.Object);

            var businessUnitViewModel = new BusinessUnitViewModel()
            {
                Name                = null,
                Address             = "Cerni Vryh",
                PhoneNumber         = "1234567890",
                Email               = "*****@*****.**",
                Information         = "this is an information",
                CategoryId          = 1,
                TownId              = 1,
                BusinessUnitPicture = null
            };

            businessUnitServiceMock.Setup(x => x.CreateBusinnesUnitAsync(businessUnitViewModel.Name, businessUnitViewModel.Address, businessUnitViewModel.PhoneNumber, businessUnitViewModel.Email, businessUnitViewModel.Information, businessUnitViewModel.CategoryId, businessUnitViewModel.TownId, businessUnitViewModel.Picture)).ReturnsAsync(TestHelpersBusinessUnitController.TestBusinessUnitDTO01());

            var actionResult = await sut.Create(businessUnitViewModel);

            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
        }