Exemplo n.º 1
0
        protected virtual void Reset()
        {
            // reset and dispose scopes
            // ensures we don't leak an opened database connection
            // which would lock eg SqlCe .sdf files
            if (Factory?.TryGetInstance <IScopeProvider>() is ScopeProvider scopeProvider)
            {
                Scope scope;
                while ((scope = scopeProvider.AmbientScope) != null)
                {
                    scope.Reset();
                    scope.Dispose();
                }
            }

            Current.Reset(); // disposes the factory

            // reset all other static things that should not be static ;(
            UriUtility.ResetAppDomainAppVirtualPath();
            SettingsForTests.Reset(); // fixme - should it be optional?

            Mapper.Reset();

            // clear static events
            DocumentRepository.ClearScopeEvents();
            MediaRepository.ClearScopeEvents();
            MemberRepository.ClearScopeEvents();
            ContentTypeService.ClearScopeEvents();
            MediaTypeService.ClearScopeEvents();
            MemberTypeService.ClearScopeEvents();
        }
Exemplo n.º 2
0
        public void Setup()
        {
            // remove all handlers first
            DoThing1 = null;
            DoThing2 = null;
            DoThing3 = null;

            var register = RegisterFactory.Create();

            var composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of <IProfilingLogger>(), ComponentTests.MockRuntimeState(RuntimeLevel.Run));

            _testObjects = new TestObjects(register);

            composition.RegisterUnique(factory => new FileSystems(factory, factory.TryGetInstance <ILogger>()));
            composition.WithCollectionBuilder <MapperCollectionBuilder>();

            composition.Configs.Add(SettingsForTests.GetDefaultGlobalSettings);
            composition.Configs.Add(SettingsForTests.GetDefaultUmbracoSettings);

            Current.Reset();
            Current.Factory = composition.CreateFactory();

            SettingsForTests.Reset(); // ensure we have configuration
        }
Exemplo n.º 3
0
 public void TearDown()
 {
     SettingsForTests.Reset();
 }
Exemplo n.º 4
0
        public void SetUp()
        {
            // annoying, but content type wants short string helper ;(
            SettingsForTests.Reset();

            // well, this is also annoying, but...
            // validating a value is performed by its data editor,
            // based upon the configuration in the data type, so we
            // need to be able to retrieve them all...

            Current.Reset();

            var configs = new Configs();

            configs.Add(SettingsForTests.GetDefaultGlobalSettings);
            configs.Add(SettingsForTests.GetDefaultUmbracoSettings);

            var factory = Mock.Of <IFactory>();

            Current.Factory = factory;

            var dataEditors = new DataEditorCollection(new IDataEditor[]
            {
                new DataEditor(Mock.Of <ILogger>())
                {
                    Alias = "editor", ExplicitValueEditor = new DataValueEditor("view")
                }
            });
            var propertyEditors = new PropertyEditorCollection(dataEditors);

            var dataType = Mock.Of <IDataType>();

            Mock.Get(dataType)
            .Setup(x => x.Configuration)
            .Returns(null);

            var dataTypeService = Mock.Of <IDataTypeService>();

            Mock.Get(dataTypeService)
            .Setup(x => x.GetDataType(It.IsAny <int>()))
            .Returns <int>(x => dataType);

            var serviceContext = ServiceContext.CreatePartial(
                dataTypeService: dataTypeService,
                localizedTextService: Mock.Of <ILocalizedTextService>());

            Mock.Get(factory)
            .Setup(x => x.GetInstance(It.IsAny <Type>()))
            .Returns <Type>(x =>
            {
                if (x == typeof(Configs))
                {
                    return(configs);
                }
                if (x == typeof(PropertyEditorCollection))
                {
                    return(propertyEditors);
                }
                if (x == typeof(ServiceContext))
                {
                    return(serviceContext);
                }
                if (x == typeof(ILocalizedTextService))
                {
                    return(serviceContext.LocalizationService);
                }
                throw new NotSupportedException(x.FullName);
            });
        }
Exemplo n.º 5
0
 public virtual void Initialize()
 {
     SettingsForTests.Reset();
 }
Exemplo n.º 6
0
        public void TearDown()
        {
            Current.Reset();

            SettingsForTests.Reset();
        }
Exemplo n.º 7
0
 public override void TestTearDown()
 {
     SettingsForTests.Reset();
     base.TestTearDown();
 }