Esempio n. 1
0
        public async Task GetInfoAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _infoDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new Exception());
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetInfoAsync("1");

            await result.Should().ThrowExactlyAsync <Exception>();
        }
Esempio n. 2
0
        public async Task GetInfoAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string id)
        {
            _infoDbServiceMock.Setup(x => x.GetAsync(id)).ThrowsAsync(new ArgumentException());
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetInfoAsync(id);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
Esempio n. 3
0
        public async Task GetInfoAsync__Element_not_found__Should_return_404NotFound_response_with_error()
        {
            _infoDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ThrowsAsync(new InvalidOperationException()).Verifiable();
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetInfoAsync("1");

            (result as ObjectResult).StatusCode.Should().Be(404);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
Esempio n. 4
0
        public async Task UpdateInfoAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _infoDbServiceMock.Setup(x => x.UpdateAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new Exception());
            _infoDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new Exception());
            _mapperMock.Setup(x => x.Map <VisitInfo>(It.IsNotNull <VisitInfoDto>())).Returns(_info);
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.UpdateInfoAsync(_infoDto.Id, _infoDto);

            await result.Should().ThrowExactlyAsync <Exception>();
        }
Esempio n. 5
0
        public async Task DeleteInfoAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException()
        {
            // Example of these errors: database does not exist, table does not exist etc.

            _infoDbServiceMock.Setup(x => x.DeleteAsync(It.IsAny <string>())).ThrowsAsync(new InternalDbServiceException());
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.DeleteInfoAsync("1");

            await result.Should().ThrowExactlyAsync <InternalDbServiceException>();
        }
Esempio n. 6
0
        public async Task UpdateInfoAsync__Argument_id_and_id_property_in_element_to_be_updated_mismatches__Should_return_400BadRequest_response()
        {
            var    controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);
            var    infoDto    = _infoDtos[0];
            string id         = infoDto.Id + "_mismatched_id";

            var result = await controller.UpdateInfoAsync(id, infoDto);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
Esempio n. 7
0
        public async Task AddInfoAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _infoDbServiceMock.Setup(x => x.AddAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new Exception());
            _infoDbServiceMock.Setup(x => x.RestrictedAddAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new Exception());
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);
            var infoDto    = CreateInfoDto(CreateModel.CreateInfo());

            Func <Task> result = async() => await controller.AddInfoAsync(infoDto);

            await result.Should().ThrowExactlyAsync <Exception>();
        }
Esempio n. 8
0
        public async Task GetAllinfoAsync__At_least_one_element_found__Should_return_200OK_response_with_not_empty_IEnumerable()
        {
            _infoDbServiceMock.Setup(x => x.GetAllAsync()).ReturnsAsync(new VisitInfo[] { _info });
            _mapperMock.Setup(x => x.Map <IEnumerable <VisitInfoDto> >(It.IsNotNull <IEnumerable <VisitInfo> >())).Returns(_infoDtos.AsEnumerable());
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetAllInfoAsync();

            (result as ObjectResult).StatusCode.Should().Be(200);
            (((result as ObjectResult).Value as ResponseWrapper).Data as IEnumerable <VisitInfoDto>).Should().NotBeEmpty();
        }
Esempio n. 9
0
        public async Task DeleteInfoAsync__Delete_succeeded__Should_return_200OK_empty_response()
        {
            var emptyResponse = new ResponseWrapper();

            _infoDbServiceMock.Setup(x => x.DeleteAsync(It.IsNotNull <string>()));
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.DeleteInfoAsync("123");

            (result as ObjectResult).StatusCode.Should().Be(200);
            ((result as ObjectResult).Value as ResponseWrapper).Should().BeEquivalentTo(emptyResponse);
        }
Esempio n. 10
0
        public async Task UpdateInfoAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string id)
        {
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);
            var infoDto    = CreateInfoDto(CreateModel.CreateInfo());

            infoDto.Id = id;

            var result = await controller.UpdateInfoAsync(id, infoDto);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
Esempio n. 11
0
        public async Task GetInfoAsync__Data_retrieve_succeeded__Should_return_200Ok_response_with_data()
        {
            string id = "15891fb0-faec-43c6-9e83-04a4a17c3660";

            _infoDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ReturnsAsync(_info);
            _mapperMock.Setup(x => x.Map <VisitInfoDto>(It.IsNotNull <VisitInfo>())).Returns(_infoDtos[0]);
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetInfoAsync(id);

            (result as ObjectResult).StatusCode.Should().Be(200);
            ((result as ObjectResult).Value as ResponseWrapper).Data.Should().NotBeNull();
        }
Esempio n. 12
0
        public async Task UpdateInfoAsync__Element_not_found__Should_return_404NotFound_response_with_error()
        {
            _mapperMock.Setup(x => x.Map <VisitInfo>(It.IsNotNull <VisitInfoDto>())).Returns(_info);
            _mapperMock.Setup(x => x.Map <VisitInfoDto>(It.IsNotNull <VisitInfo>())).Returns(_infoDto);
            _infoDbServiceMock.Setup(x => x.UpdateAsync(It.IsNotNull <VisitInfo>())).ThrowsAsync(new InvalidOperationException());
            _infoDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsNotNull <VisitInfo>())).ThrowsAsync(new InvalidOperationException());
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.UpdateInfoAsync(_infoDto.Id, _infoDto);

            (result as ObjectResult).StatusCode.Should().Be(404);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeEquivalentTo(new ApiError());
        }
Esempio n. 13
0
        public async Task AddInfoAsync__Already_there_is_the_same_element_in_database__Should_return_400BadRequest_response()
        {
            _mapperMock.Setup(x => x.Map <VisitInfo>(_infoDto)).Returns(_info);
            _infoDbServiceMock.Setup(x => x.AddAsync(It.IsNotNull <VisitInfo>())).ThrowsAsync(new InvalidOperationException());
            _infoDbServiceMock.Setup(x => x.RestrictedAddAsync(It.IsNotNull <VisitInfo>())).ThrowsAsync(new InvalidOperationException());
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);
            var infoDto    = CreateInfoDto(CreateModel.CreateInfo());

            var result = await controller.AddInfoAsync(infoDto);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
Esempio n. 14
0
        public async Task UpdateInfoAsync__Update_succeeded__Should_return_200OK_response_with_updated_element()
        {
            _mapperMock.Setup(x => x.Map <VisitInfo>(It.IsNotNull <VisitInfoDto>())).Returns(_info);
            _mapperMock.Setup(x => x.Map <VisitInfoDto>(It.IsNotNull <VisitInfo>())).Returns(_infoDto);
            _infoDbServiceMock.Setup(x => x.UpdateAsync(It.IsNotNull <VisitInfo>())).ReturnsAsync(_info);
            _infoDbServiceMock.Setup(x => x.RestrictedUpdateAsync(It.IsNotNull <VisitInfo>())).ReturnsAsync(_info);
            _mapperMock.Setup(x => x.Map <VisitInfoDto>(It.IsNotNull <VisitInfo>())).Returns(_infoDto);
            var controller = new SDCWebApp.Controllers.VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.UpdateInfoAsync(_infoDto.Id, _infoDto);

            (result as ObjectResult).StatusCode.Should().Be(200);
            ((result as ObjectResult).Value as ResponseWrapper).Data.Should().BeEquivalentTo(_infoDto);
        }