Esempio n. 1
0
        public void SetUp()
        {
            _groupDbServiceMock = new Mock <ISightseeingGroupDbService>();
            _infoDbServiceMock  = new Mock <IVisitInfoDbService>();

            _dbServiceFactoryMock = new Mock <IIndex <string, IServiceBase> >();
            _dbServiceFactoryMock.Setup(x => x["ISightseeingGroupDbService"]).Returns(_groupDbServiceMock.Object);
            _dbServiceFactoryMock.Setup(x => x["IVisitInfoDbService"]).Returns(_infoDbServiceMock.Object);

            _validSightseeingGroup = new SightseeingGroup
            {
                Id              = "1",
                MaxGroupSize    = 30,
                SightseeingDate = new DateTime(2019, 12, 12, 12, 0, 0)
            };
            _validSightseeingGroupDto = new SightseeingGroupDto
            {
                Id               = "1",
                MaxGroupSize     = 30,
                SightseeingDate  = new DateTime(2019, 12, 12, 12, 0, 0),
                IsAvailablePlace = true,
                CurrentGroupSize = 20
            };

            _info = CreateModel.CreateInfo();

            _logger = Mock.Of <ILogger <GroupsController> >();

            _mapperMock = new Mock <IMapper>();
            _mapperMock.Setup(x => x.Map <SightseeingGroupDto>(It.IsAny <SightseeingGroup>())).Returns(_validSightseeingGroupDto);
            _mapperMock.Setup(x => x.Map <SightseeingGroup>(It.IsAny <SightseeingGroupDto>())).Returns(_validSightseeingGroup);
        }
Esempio n. 2
0
        public void SetUp()
        {
            var info = CreateModel.CreateInfo();

            _dbContextMock = new Mock <ApplicationDbContext>();
            _dbContextMock.Setup(x => x.Info).Returns(CreateMock.CreateDbSetMock <VisitInfo>(new VisitInfo[] { info }).Object);
            _validator = new TicketValidator(_dbContextMock.Object);
        }
Esempio n. 3
0
        public void Equals__Two_info_with_the_same_properties_value_except_opening_hours__Should_be_the_same()
        {
            var info2 = CreateModel.CreateInfo();

            bool isEqual = _info.Equals(info2);

            isEqual.Should().BeTrue();
        }
Esempio n. 4
0
 public void SetUp()
 {
     _infoDbServiceMock = new Mock <IVisitInfoDbService>();
     _logger            = Mock.Of <ILogger <VisitInfoController> >();
     _mapperMock        = new Mock <IMapper>();
     _info     = CreateModel.CreateInfo();
     _infoDto  = CreateInfoDto(_info);
     _infoDtos = new VisitInfoDto[] { _infoDto };
 }
Esempio n. 5
0
        public void SetUp()
        {
            _info = CreateModel.CreateInfo(maxAllowedGroupSize: MaxAllowedGroupSize);
            var _dbContextMock = new Mock <ApplicationDbContext>();

            _dbContextMock.Setup(x => x.Info).Returns(CreateMock.CreateDbSetMock <VisitInfo>(new VisitInfo[] { _info }).Object);
            _validator       = new SightseeingGroupValidator(_dbContextMock.Object);
            _maxDaysForOrder = _info.MaxTicketOrderInterval * 7;
        }
Esempio n. 6
0
        public void Equals__At_least_one_property_value_is_different__Should_not_be_the_same()
        {
            // Different Description and MaxAllowedGroupSize.
            var info2 = CreateModel.CreateInfo(description: "other_test", maxAllowedGroupSize: 20);

            bool isEqual = _info.Equals(info2);

            isEqual.Should().BeFalse();
        }
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 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. 9
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. 10
0
        public async Task AddInfoAsync__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.AddAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new InternalDbServiceException());
            _infoDbServiceMock.Setup(x => x.RestrictedAddAsync(It.IsAny <VisitInfo>())).ThrowsAsync(new InternalDbServiceException());
            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 <InternalDbServiceException>();
        }
Esempio n. 11
0
        public async Task AddInfoAsync__Add_succeeded__Should_return_201OK_response_with_added_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.AddAsync(It.IsAny <VisitInfo>())).ReturnsAsync(_info);
            _infoDbServiceMock.Setup(x => x.RestrictedAddAsync(It.IsAny <VisitInfo>())).ReturnsAsync(_info);
            var controller = new VisitInfoController(_infoDbServiceMock.Object, _logger, _mapperMock.Object);
            var infoDto    = CreateInfoDto(CreateModel.CreateInfo());

            var result = await controller.AddInfoAsync(infoDto);

            (result as ObjectResult).StatusCode.Should().Be(201);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().BeEquivalentTo(new ApiError());
        }
Esempio n. 12
0
 public void SetUp()
 {
     _info = CreateModel.CreateInfo();
 }