コード例 #1
0
        internal static void SetupMocksForPost(ServiceContext serviceContext)
        {
            var mockContentService = Mock.Get(serviceContext.ContentService);

            mockContentService.Setup(x => x.GetById(It.IsAny <int>())).Returns(() => ModelMocks.SimpleMockedContent());
            mockContentService.Setup(x => x.GetChildren(It.IsAny <int>())).Returns(new List <IContent>(new[] { ModelMocks.SimpleMockedContent(789) }));
            mockContentService.Setup(x => x.HasChildren(It.IsAny <int>())).Returns(true);
            mockContentService.Setup(x => x.CreateContent(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(() => ModelMocks.SimpleMockedContent(8888));

            var mockContentTypeService = Mock.Get(serviceContext.ContentTypeService);

            mockContentTypeService.Setup(x => x.GetContentType(It.IsAny <string>())).Returns(ModelMocks.SimpleMockedContentType());

            var mockDataTypeService = Mock.Get(serviceContext.DataTypeService);

            mockDataTypeService.Setup(x => x.GetPreValuesCollectionByDataTypeId(It.IsAny <int>())).Returns(new PreValueCollection(Enumerable.Empty <PreValue>()));

            var mockServiceProvider = new Mock <IServiceProvider>();

            mockServiceProvider.Setup(x => x.GetService(It.IsAny <Type>())).Returns(new ModelMocks.SimplePropertyEditor());

            Func <IEnumerable <Type> > producerList = Enumerable.Empty <Type>;
            var mockPropertyEditorResolver          = new Mock <PropertyEditorResolver>(
                Mock.Of <IServiceProvider>(),
                Mock.Of <ILogger>(),
                producerList,
                Mock.Of <IRuntimeCacheProvider>());

            mockPropertyEditorResolver.Setup(x => x.PropertyEditors).Returns(new[] { new ModelMocks.SimplePropertyEditor() });

            PropertyEditorResolver.Current = mockPropertyEditorResolver.Object;
        }
コード例 #2
0
        internal static void SetupMocksForPost(ServiceContext serviceContext)
        {
            var relType             = ModelMocks.SimpleMockedRelationType();
            var rel                 = ModelMocks.SimpleMockedRelation(1234, 567, 8910, relType);
            var mockRelationService = Mock.Get(serviceContext.RelationService);

            mockRelationService.Setup(x => x.GetRelationTypeByAlias(It.IsAny <string>())).Returns(() => relType);
            mockRelationService.Setup(x => x.GetById(It.IsAny <int>())).Returns(() => rel);
            mockRelationService.Setup(x => x.Relate(It.IsAny <IUmbracoEntity>(), It.IsAny <IUmbracoEntity>(), It.IsAny <IRelationType>()))
            .Returns(() => rel);
        }
コード例 #3
0
        internal static void SetupMocksForPost(ServiceContext serviceContext)
        {
            var mockContentService = Mock.Get(serviceContext.ContentService);

            mockContentService.Setup(x => x.GetById(It.IsAny <int>())).Returns(() => ModelMocks.SimpleMockedContent());
            mockContentService.Setup(x => x.GetChildren(It.IsAny <int>())).Returns(new List <IContent>(new[] { ModelMocks.SimpleMockedContent(789) }));
            mockContentService.Setup(x => x.HasChildren(It.IsAny <int>())).Returns(true);
            mockContentService.Setup(x => x.CreateContent(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(() => ModelMocks.SimpleMockedContent(8888));

            var entityServiceMock = Mock.Get(serviceContext.EntityService);

            entityServiceMock.Setup(x => x.GetIdForKey(456.ToGuid(), UmbracoObjectTypes.Document)).Returns(Attempt.Succeed(456));

            var fileServiceMock = Mock.Get(serviceContext.FileService);

            fileServiceMock.Setup(x => x.GetTemplate(9.ToGuid())).Returns(
                Mock.Of <ITemplate>(template =>
                                    template.Id == 9 &&
                                    template.Key == 9.ToGuid() &&
                                    template.Name == "test" &&
                                    template.IsMasterTemplate == false));

            var mockContentTypeService = Mock.Get(serviceContext.ContentTypeService);

            mockContentTypeService.Setup(x => x.GetContentType(It.IsAny <string>())).Returns(ModelMocks.SimpleMockedContentType());

            var mockDataTypeService = Mock.Get(serviceContext.DataTypeService);

            mockDataTypeService.Setup(x => x.GetPreValuesCollectionByDataTypeId(It.IsAny <int>())).Returns(new PreValueCollection(Enumerable.Empty <PreValue>()));

            var mockServiceProvider = new Mock <IServiceProvider>();

            mockServiceProvider.Setup(x => x.GetService(It.IsAny <Type>())).Returns(new ModelMocks.SimplePropertyEditor());

            Func <IEnumerable <Type> > producerList = Enumerable.Empty <Type>;
            var mockPropertyEditorResolver          = new Mock <PropertyEditorResolver>(
                Mock.Of <IServiceProvider>(),
                Mock.Of <ILogger>(),
                producerList,
                Mock.Of <IRuntimeCacheProvider>());

            mockPropertyEditorResolver.Setup(x => x.PropertyEditors).Returns(new[] { new ModelMocks.SimplePropertyEditor() });

            PropertyEditorResolver.Current = mockPropertyEditorResolver.Object;
        }
コード例 #4
0
        internal static void SetupMocksForPost(ServiceContext serviceContext)
        {
            var relType             = ModelMocks.SimpleMockedRelationType();
            var rel                 = ModelMocks.SimpleMockedRelation(1234, 567, 8910, relType);
            var mockRelationService = Mock.Get(serviceContext.RelationService);

            mockRelationService.Setup(x => x.GetRelationTypeByAlias(It.IsAny <string>())).Returns(() => relType);
            mockRelationService.Setup(x => x.GetById(It.IsAny <int>())).Returns(() => rel);
            mockRelationService.Setup(x => x.Relate(It.IsAny <IUmbracoEntity>(), It.IsAny <IUmbracoEntity>(), It.IsAny <IRelationType>()))
            .Returns(() => rel);

            var entityServiceMock = Mock.Get(serviceContext.EntityService);

            entityServiceMock.Setup(x => x.GetIdForKey(567.ToGuid(), UmbracoObjectTypes.Unknown)).Returns(Attempt.Succeed(567));
            entityServiceMock.Setup(x => x.GetIdForKey(8910.ToGuid(), UmbracoObjectTypes.Unknown)).Returns(Attempt.Succeed(8910));
            entityServiceMock.Setup(x => x.GetKeyForId(567, UmbracoObjectTypes.Unknown)).Returns(Attempt.Succeed(567.ToGuid()));
            entityServiceMock.Setup(x => x.GetKeyForId(8910, UmbracoObjectTypes.Unknown)).Returns(Attempt.Succeed(8910.ToGuid()));
        }
コード例 #5
0
        internal static void SetupMocksForPost(ServiceContext serviceContext)
        {
            var mockMediaService = Mock.Get(serviceContext.MediaService);

            mockMediaService.Setup(x => x.GetById(It.IsAny <int>())).Returns(() => ModelMocks.SimpleMockedMedia());
            mockMediaService.Setup(x => x.GetChildren(It.IsAny <int>())).Returns(new List <IMedia>(new[] { ModelMocks.SimpleMockedMedia(789) }));
            mockMediaService.Setup(x => x.HasChildren(It.IsAny <int>())).Returns(true);
            mockMediaService.Setup(x => x.CreateMedia(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <int>()))
            .Returns(() => ModelMocks.SimpleMockedMedia(8888));

            var entityServiceMock = Mock.Get(serviceContext.EntityService);

            entityServiceMock.Setup(x => x.GetIdForKey(456.ToGuid(), UmbracoObjectTypes.Media)).Returns(Attempt.Succeed(456));

            var mockContentTypeService = Mock.Get(serviceContext.ContentTypeService);

            mockContentTypeService.Setup(x => x.GetMediaType(It.IsAny <string>())).Returns(ModelMocks.SimpleMockedMediaType());

            var mockDataTypeService = Mock.Get(serviceContext.DataTypeService);

            mockDataTypeService.Setup(x => x.GetPreValuesCollectionByDataTypeId(It.IsAny <int>())).Returns(new PreValueCollection(Enumerable.Empty <PreValue>()));

            var mockServiceProvider = new Mock <IServiceProvider>();

            mockServiceProvider.Setup(x => x.GetService(It.IsAny <Type>())).Returns(new ModelMocks.SimplePropertyEditor());

            Func <IEnumerable <Type> > producerList = Enumerable.Empty <Type>;
            var mockPropertyEditorResolver          = new Mock <PropertyEditorResolver>(
                Mock.Of <IServiceProvider>(),
                Mock.Of <ILogger>(),
                producerList,
                Mock.Of <IRuntimeCacheProvider>());

            mockPropertyEditorResolver.Setup(x => x.PropertyEditors).Returns(new[] { new ModelMocks.SimplePropertyEditor() });

            PropertyEditorResolver.Current = mockPropertyEditorResolver.Object;
        }