Exemple #1
0
        public async Task Should_Add_ReturnsABadRequestResult()
        {
            //Arrange

            const int userId        = 2;
            const int residentialId = 3;

            var houseModel = new HouseToAdd();

            _controller = new HouseController(_userManagerMock.Object, _houseManagerMock.Object,
                                              _residentialManagerMock.Object, _localizerMock.Object);

            _controller.ValidateViewModel(houseModel);

            //Act

            var result = await _controller.Add(residentialId, houseModel);

            //Assert

            _userManagerMock.Verify(x => x.IsAdminAsync(residentialId, userId), Times.Never);

            _residentialManagerMock.Verify(x => x.ExistsAsync(residentialId), Times.Never);

            _houseManagerMock.Verify(x => x.AddAsync(houseModel), Times.Never);

            Assert.IsType <BadRequestResult>(result);
        }
Exemple #2
0
        public async Task Should_Add_ReturnsANotContentResult()
        {
            //Arrange

            const int userId        = 2;
            const int residentialId = 3;

            var houseModel = new HouseToAdd
            {
                Name          = "House Name",
                Street        = "Street Name",
                ResidentialId = residentialId
            };

            _userManagerMock.Setup(x => x.IsAdminAsync(residentialId, userId))
            .ReturnsAsync(true);

            _residentialManagerMock.Setup(x => x.ExistsAsync(residentialId))
            .ReturnsAsync(true);

            var claims = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(Business.Utils.ClaimsCustomTypes.Id, userId + ""),
                new Claim(Business.Utils.ClaimsCustomTypes.RoleId, ((int)RoleEnum.Admin) + "")
            }));

            var controllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext {
                    User = claims
                }
            };

            _controller = new HouseController(_userManagerMock.Object, _houseManagerMock.Object,
                                              _residentialManagerMock.Object, _localizerMock.Object)
            {
                ControllerContext = controllerContext
            };

            _controller.ValidateViewModel(houseModel);

            //Act

            var result = await _controller.Add(residentialId, houseModel);

            //Assert

            _userManagerMock.Verify(x => x.IsAdminAsync(residentialId, userId), Times.Once);

            _residentialManagerMock.Verify(x => x.ExistsAsync(residentialId), Times.Once);

            _houseManagerMock.Verify(x => x.AddAsync(houseModel), Times.Once);
        }