Пример #1
0
        public void RightVersionNotFound(bool getOnlyPublished)
        {
            // Arrange
            var id             = Guid.NewGuid();
            var unitOfWork     = unitOfWorkMockSetup.Object;
            var contextManager = new TestContextManager(unitOfWork, unitOfWork);

            var serviceUtilities = new ServiceUtilities(UserIdentification, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            VersioningManagerMock.Setup(s => s.GetVersionId <StatutoryServiceGeneralDescriptionVersioned>(unitOfWork, id, PublishingStatus.Published, true)).Returns((Guid?)null);
            VersioningManagerMock.Setup(s => s.GetVersionId <StatutoryServiceGeneralDescriptionVersioned>(unitOfWork, id, null, false)).Returns((Guid?)null);

            var gdService = new GeneralDescriptionService(contextManager, UserIdentification, translationManagerMockSetup.Object, TranslationManagerVModel,
                                                          Logger, serviceUtilities, CommonService, PublishingStatusCache, UserOrganizationChecker, LanguageCache, TypeCache,
                                                          VersioningManager, DataUtils, ValidationManagerMock);

            // Act
            var result = gdService.GetGeneralDescriptionVersionBase(id, DefaultVersion, getOnlyPublished);

            // Assert
            result.Should().BeNull();
            if (getOnlyPublished)
            {
                VersioningManagerMock.Verify(x => x.GetVersionId <StatutoryServiceGeneralDescriptionVersioned>(unitOfWork, id, PublishingStatus.Published, true), Times.Once());
            }
            else
            {
                VersioningManagerMock.Verify(x => x.GetVersionId <StatutoryServiceGeneralDescriptionVersioned>(unitOfWork, id, null, false), Times.Once());
            }
        }
Пример #2
0
        private void TestBase(DateTime?date, List <StatutoryServiceGeneralDescriptionVersioned> entityList, int pageNumber, int pageSize, int count, int expectedPageCount, int expectedItemCountOnPage)
        {
            // unitOfWork
            var gdRepoMock = new Mock <IStatutoryServiceGeneralDescriptionVersionedRepository>();

            gdRepoMock.Setup(g => g.All()).Returns(entityList.AsQueryable());

            unitOfWorkMockSetup.Setup(uw => uw.CreateRepository <IRepository <StatutoryServiceGeneralDescriptionVersioned> >()).Returns(gdRepoMock.Object);
            unitOfWorkMockSetup.Setup(uw => uw.ApplyIncludes(
                                          It.IsAny <IQueryable <StatutoryServiceGeneralDescriptionVersioned> >(),
                                          It.IsAny <Func <IQueryable <StatutoryServiceGeneralDescriptionVersioned>, IQueryable <StatutoryServiceGeneralDescriptionVersioned> > >(),
                                          It.IsAny <bool>()
                                          )).Returns(entityList.AsQueryable());

            var unitOfWorkMock = unitOfWorkMockSetup.Object;

            // Translation manager
            translationManagerMockSetup.Setup(t => t.TranslateAll <StatutoryServiceGeneralDescriptionVersioned, VmOpenApiItem>(It.IsAny <IList <StatutoryServiceGeneralDescriptionVersioned> >()))
            .Returns(TestDataFactory.CreateVmItemList(count));
            var translationManagerMock = translationManagerMockSetup.Object;

            var contextManager = new TestContextManager(unitOfWorkMock, unitOfWorkMock);

            var serviceUtilities = new ServiceUtilities(UserIdentification, LockingManager, contextManager, UserOrganizationService,
                                                        VersioningManager, UserInfoService, UserOrganizationChecker);

            var gdService = new GeneralDescriptionService(contextManager, UserIdentification, translationManagerMock, TranslationManagerVModel,
                                                          Logger, serviceUtilities, CommonService, PublishingStatusCache, UserOrganizationChecker, LanguageCache, TypeCache,
                                                          VersioningManager, DataUtils, ValidationManagerMock);

            // Act
            var result = gdService.GetGeneralDescriptions(date, pageNumber, pageSize);

            // Assert
            result.Should().NotBeNull();
            result.PageCount.Should().Be(expectedPageCount);
            if (result is V3VmOpenApiGuidPage)
            {
                if (expectedItemCountOnPage == 0)
                {
                    (result as V3VmOpenApiGuidPage).ItemList.Should().BeNull();
                }
                else
                {
                    (result as V3VmOpenApiGuidPage).ItemList.Count.Should().BeGreaterThan(0);
                }
            }
        }
        public IActionResult Get([FromQuery] DateTime?date, [FromQuery] int page = 1)
        {
            var pageSize = Settings.PageSize > 0 ? Settings.PageSize : 1000;

            return(Ok(GeneralDescriptionService.GetGeneralDescriptions(date, page, pageSize)));
        }