Exemplo n.º 1
0
 public void NonExpiredLicense()
 {
     Instant expiry = Instant.FromUtc(2000, 1, 1, 0, 0, 0);
     StubClock clock = new StubClock(expiry - Duration.OneMillisecond);
     License license = new License(expiry, clock);
     Assert.IsFalse(license.HasExpired);
 }
Exemplo n.º 2
0
        public void StoreAssemblyShouldCopyFile()
        {
            var clock         = new StubClock();
            var appDataFolder = new StubAppDataFolder(clock);

            var assembly = GetType().Assembly;
            var name     = assembly.GetName().Name;

            {
                var dependenciesFolder = new DefaultAssemblyProbingFolder(appDataFolder,
                                                                          new DefaultAssemblyLoader(Enumerable.Empty <IAssemblyNameResolver>()));
                dependenciesFolder.StoreAssembly(name, assembly.Location);
            }

            {
                var dependenciesFolder = new DefaultAssemblyProbingFolder(appDataFolder,
                                                                          new DefaultAssemblyLoader(Enumerable.Empty <IAssemblyNameResolver>()));
                Assert.Equal(dependenciesFolder.AssemblyExists(name), true);
                Assert.Equal(dependenciesFolder.LoadAssembly(name), GetType().Assembly);
                {
                    //shouldn't throw Exception
                    dependenciesFolder.DeleteAssembly(name);
                }

                Assert.Equal(dependenciesFolder.LoadAssembly(name), null);
            }
        }
Exemplo n.º 3
0
 public void ExpiryAtExactInstance()
 {
     Instant expiry = Instant.FromUtc(2000, 1, 1, 0, 0, 0);
     StubClock clock = new StubClock(expiry);
     License license = new License(expiry, clock);
     Assert.IsTrue(license.HasExpired);
 }
Exemplo n.º 4
0
        public void LoadAssemblyShouldNotThrowIfAssemblyNotFound()
        {
            var clock              = new StubClock();
            var appDataFolder      = new StubAppDataFolder(clock);
            var dependenciesFolder = new DefaultAssemblyProbingFolder(appDataFolder, new DefaultAssemblyLoader(Enumerable.Empty <IAssemblyNameResolver>()));

            Assert.That(dependenciesFolder.LoadAssembly("foo"), Is.Null);
        }
Exemplo n.º 5
0
        public void FormatToday_Iso_Utc()
        {
            StubClock clock = new StubClock(Instant.UnixEpoch);
            Diary diary = new Diary(clock, CalendarSystem.Iso, DateTimeZone.Utc);

            string today = diary.FormatToday();
            Assert.AreEqual("1970-01-01", today);
        }
Exemplo n.º 6
0
        public void DeleteAssemblyShouldNotThrowIfAssemblyNotFound()
        {
            var clock              = new StubClock();
            var appDataFolder      = new StubAppDataFolder(clock);
            var dependenciesFolder = new DefaultAssemblyProbingFolder(appDataFolder, new DefaultAssemblyLoader(Enumerable.Empty <IAssemblyNameResolver>()));

            Assert.DoesNotThrow(() => dependenciesFolder.DeleteAssembly("foo"));
        }
Exemplo n.º 7
0
        public void FormatToday_Julian_Utcx()
        {
            StubClock clock = new StubClock(Instant.FromUtc(1970, 1, 1, 0, 0));
            Diary diary = new Diary(clock, CalendarSystem.GetJulianCalendar(7), DateTimeZone.Utc);

            string today = diary.FormatToday();
            Assert.AreEqual("1969-12-19", today);
        }
Exemplo n.º 8
0
        public void GetAssemblyDateTimeUtcShouldThrowIfAssemblyNotFound()
        {
            var clock              = new StubClock();
            var appDataFolder      = new StubAppDataFolder(clock);
            var dependenciesFolder = new DefaultAssemblyProbingFolder(appDataFolder, new DefaultAssemblyLoader(Enumerable.Empty <IAssemblyNameResolver>()));

            Assert.That(() => dependenciesFolder.GetAssemblyDateTimeUtc("foo"), Throws.Exception);
        }
Exemplo n.º 9
0
        public void FolderShouldBeEmptyByDefault()
        {
            var clock              = new StubClock();
            var appDataFolder      = new StubAppDataFolder(clock);
            var dependenciesFolder = new DefaultAssemblyProbingFolder(appDataFolder, new DefaultAssemblyLoader(Enumerable.Empty <IAssemblyNameResolver>()));

            Assert.That(dependenciesFolder.AssemblyExists("foo"), Is.False);
        }
Exemplo n.º 10
0
        public void CorePartValuesAreExtracted()
        {
            var clock = new StubClock();
            var hello = new ContentItemBuilder(new ContentTypeDefinitionBuilder().Named("hello").Build())
                        .Weld <CommonPart>()
                        .Weld <TitlePart>()
                        .Weld <BodyPart>()
                        .Weld <InfosetPart>()
                        .Build();

            hello.As <CommonPart>().Record = new CommonPartRecord();
            hello.As <TitlePart>().Record  = new TitlePartRecord();
            hello.As <BodyPart>().Record   = new BodyPartRecord();

            hello.As <CommonPart>().PublishedUtc = clock.UtcNow;
            hello.As <TitlePart>().Title         = "alpha";
            // hello.As<RoutePart>().Slug = "beta";
            hello.As <BodyPart>().Text = "gamma";

            var query = new StubQuery(new[] {
                hello,
            });

            var mockContentManager = new Mock <IContentManager>();

            mockContentManager.Setup(x => x.GetItemMetadata(It.IsAny <IContent>()))
            .Returns(new ContentItemMetadata()
            {
                DisplayText = "foo"
            });

            var builder = new ContainerBuilder();

            //builder.RegisterModule(new ImplicitCollectionSupportModule());
            builder.RegisterType <FeedController>();
            builder.RegisterInstance(new RouteCollection());
            builder.RegisterInstance(mockContentManager.Object).As <IContentManager>();
            builder.RegisterType <RssFeedBuilder>().As <IFeedBuilderProvider>();
            builder.RegisterType <CorePartsFeedItemBuilder>().As <IFeedItemBuilder>();
            builder.RegisterInstance(query).As <IFeedQueryProvider>();
            var container = builder.Build();

            var controller = container.Resolve <FeedController>();

            controller.ValueProvider = Values.From(new { });

            var result = controller.Index("rss");

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.InstanceOf <RssResult>());

            var doc  = ((RssResult)result).Document;
            var item = doc.Elements("rss").Elements("channel").Elements("item").Single();

            Assert.That(item.Element("title").Value, Is.EqualTo("foo"));
            Assert.That(item.Element("description").Value, Is.EqualTo("gamma"));
        }
Exemplo n.º 11
0
        public void Init()
        {
            _tempFolder = Path.GetTempFileName();
            File.Delete(_tempFolder);
            _appDataFolder = CreateAppDataFolder(_tempFolder);

            _clock           = new StubClock();
            _lockFileManager = new DefaultLockFileManager(_appDataFolder, _clock);
        }
Exemplo n.º 12
0
        public void FormatToday_Iso_NegativeOffset()
        {
            DateTimeZone zone  = DateTimeZone.ForOffset(Offset.FromHours(-8));
            var          clock = new StubClock(Instant.FromUtc(1970, 01, 01, 00, 00));
            Diary        diary = new Diary(clock, CalendarSystem.Iso, zone);

            string today = diary.FormatToday();

            Assert.AreEqual("1969-12-31", today);
        }
Exemplo n.º 13
0
        public void FormatToday_Iso_Utc()
        {
            DateTime date  = new DateTime(1970, 1, 1).ToUniversalTime();
            var      clock = new StubClock(Instant.FromDateTimeUtc(date));
            Diary    diary = new Diary(clock, CalendarSystem.Iso, DateTimeZone.Utc);

            string today = diary.FormatToday();

            Assert.AreEqual("1970-01-01", today);
        }
Exemplo n.º 14
0
 public void Init()
 {
     var builder = new ContainerBuilder();
     builder.RegisterModule(new CacheModule());
     builder.RegisterType<DefaultCacheManager>().As<ICacheManager>();
     builder.RegisterType<DefaultCacheHolder>().As<ICacheHolder>().SingleInstance();
     builder.RegisterType<DefaultCacheContextAccessor>().As<ICacheContextAccessor>();
     builder.RegisterInstance<IClock>(_clock=new StubClock());
     _container = builder.Build();
     _cacheManager = _container.Resolve<ICacheManager>(new TypedParameter(typeof (Type), GetType()));
 }
Exemplo n.º 15
0
        public void Init()
        {
            var clock = new StubClock();

            _appDataFolder = new StubAppDataFolder(clock);

            var builder = new ContainerBuilder();

            builder.RegisterInstance(_appDataFolder).As <IAppDataFolder>();
            builder.RegisterType <ShellDescriptorCache>().As <IShellDescriptorCache>();
            _container = builder.Build();
        }
Exemplo n.º 16
0
        public void Init()
        {
            var builder = new ContainerBuilder();

            builder.RegisterModule(new CacheModule());
            builder.RegisterType <DefaultCacheManager>().As <ICacheManager>();
            builder.RegisterType <DefaultCacheHolder>().As <ICacheHolder>().SingleInstance();
            builder.RegisterType <DefaultCacheContextAccessor>().As <ICacheContextAccessor>();
            builder.RegisterInstance <IClock>(_clock = new StubClock());
            _container    = builder.Build();
            _cacheManager = _container.Resolve <ICacheManager>(new TypedParameter(typeof(Type), GetType()));
        }
        public void Init()
        {
            var clock         = new StubClock();
            var appDataFolder = new StubAppDataFolder(clock);

            _controllerBuilder     = new ControllerBuilder();
            _routeCollection       = new RouteCollection();
            _modelBinderDictionary = new ModelBinderDictionary();
            _viewEngineCollection  = new ViewEngineCollection {
                new WebFormViewEngine()
            };

            _container = OrchardStarter.CreateHostContainer(
                builder => {
                builder.RegisterInstance(new StubShellSettingsLoader()).As <IShellSettingsManager>();
                builder.RegisterType <RoutePublisher>().As <IRoutePublisher>();
                builder.RegisterType <ModelBinderPublisher>().As <IModelBinderPublisher>();
                builder.RegisterType <ShellContextFactory>().As <IShellContextFactory>();
                builder.RegisterType <StubExtensionManager>().As <IExtensionManager>();
                builder.RegisterType <StubVirtualPathMonitor>().As <IVirtualPathMonitor>();
                builder.RegisterInstance(appDataFolder).As <IAppDataFolder>();
                builder.RegisterInstance(_controllerBuilder);
                builder.RegisterInstance(_routeCollection);
                builder.RegisterInstance(_modelBinderDictionary);
                builder.RegisterInstance(_viewEngineCollection);
                builder.RegisterAutoMocking()
                .Ignore <IExtensionFolders>()
                .Ignore <IRouteProvider>()
                .Ignore <IHttpRouteProvider>()
                .Ignore <IModelBinderProvider>()
                .Ignore <IWorkContextEvents>()
                .Ignore <IOwinMiddlewareProvider>();
            });
            _lifetime = _container.BeginLifetimeScope();

            _container.Mock <IContainerProvider>()
            .SetupGet(cp => cp.ApplicationContainer).Returns(_container);
            _container.Mock <IContainerProvider>()
            .SetupGet(cp => cp.RequestLifetime).Returns(_lifetime);
            _container.Mock <IContainerProvider>()
            .Setup(cp => cp.EndRequestLifetime()).Callback(() => _lifetime.Dispose());

            _container.Mock <IShellDescriptorManager>()
            .Setup(cp => cp.GetShellDescriptor()).Returns(default(ShellDescriptor));

            _container.Mock <IOrchardShellEvents>()
            .Setup(e => e.Activated());

            _container.Mock <IOrchardShellEvents>()
            .Setup(e => e.Terminating()).Callback(() => new object());
        }
Exemplo n.º 18
0
        public void StubClockShouldComeFromSystemUtcAndDoesNotComeFromSystemTime()
        {
            var clock  = new StubClock();
            var before = DateTime.UtcNow;

            Thread.Sleep(2);
            var mark = clock.UtcNow;

            Thread.Sleep(2);
            var after = DateTime.UtcNow;

            Assert.That(mark.Kind, Is.EqualTo(DateTimeKind.Utc));
            Assert.That(mark, Is.Not.InRange(before, after));
        }
Exemplo n.º 19
0
        public void StubClockCanBeManuallyAdvanced()
        {
            var clock  = new StubClock();
            var before = clock.UtcNow;

            clock.Advance(TimeSpan.FromMilliseconds(2));
            var mark = clock.UtcNow;

            clock.Advance(TimeSpan.FromMilliseconds(2));
            var after = clock.UtcNow;

            Assert.That(mark.Kind, Is.EqualTo(DateTimeKind.Utc));
            Assert.That(mark, Is.InRange(before, after));
            Assert.That(after.Subtract(before), Is.EqualTo(TimeSpan.FromMilliseconds(4)));
        }
Exemplo n.º 20
0
        public void Init()
        {
            var builder = new ContainerBuilder();

            //builder.RegisterModule(new ImplicitCollectionSupportModule());
            builder.RegisterType <MembershipValidationService>().As <IMembershipValidationService>();
            builder.RegisterType <MembershipService>().As <IMembershipService>();
            builder.RegisterType <DefaultContentQuery>().As <IContentQuery>();
            builder.RegisterType <DefaultContentManager>().As <IContentManager>();
            builder.RegisterType <StubCacheManager>().As <ICacheManager>();
            builder.RegisterType <Signals>().As <ISignals>();
            builder.RegisterType(typeof(SettingsFormatter)).As <ISettingsFormatter>();
            builder.RegisterType <ContentDefinitionManager>().As <IContentDefinitionManager>();
            builder.RegisterType <DefaultContentManagerSession>().As <IContentManagerSession>();
            builder.RegisterInstance(new ShellSettings {
                Name = ShellSettings.DefaultName, DataProvider = "SqlCe"
            });
            builder.RegisterType <UserPartHandler>().As <IContentHandler>();
            //builder.RegisterType<StubWorkContextAccessor>().As<IWorkContextAccessor>();
            builder.RegisterType <OrchardServices>().As <IOrchardServices>();
            builder.RegisterAutoMocking(MockBehavior.Loose);
            builder.RegisterGeneric(typeof(Repository <>)).As(typeof(IRepository <>));
            builder.RegisterType <DefaultShapeTableManager>().As <IShapeTableManager>();
            builder.RegisterType <DefaultShapeFactory>().As <IShapeFactory>();
            builder.RegisterInstance(_clock = new StubClock()).As <IClock>();
            builder.RegisterType <StubExtensionManager>().As <IExtensionManager>();
            builder.RegisterInstance(new Mock <IPageClassBuilder>().Object);
            builder.RegisterType <DefaultContentDisplay>().As <IContentDisplay>();
            builder.RegisterType <InfosetHandler>().As <IContentHandler>();
            builder.RegisterType <SiteService>().As <ISiteService>();
            builder.RegisterType <SiteSettingsPartHandler>().As <IContentHandler>();
            builder.RegisterType <RegistrationSettingsPartHandler>().As <IContentHandler>();

            _session = _sessionFactory.OpenSession();
            builder.RegisterInstance(new TestTransactionManager(_session)).As <ITransactionManager>();

            _workContext = new Mock <WorkContext>();
            _workContext.Setup(w => w.GetState <ISite>(It.Is <string>(s => s == "CurrentSite"))).Returns(() => { return(_container.Resolve <ISiteService>().GetSiteSettings()); });

            var _workContextAccessor = new Mock <IWorkContextAccessor>();

            _workContextAccessor.Setup(w => w.GetContext()).Returns(_workContext.Object);
            builder.RegisterInstance(_workContextAccessor.Object).As <IWorkContextAccessor>();

            _container = builder.Build();
            _membershipValidationService = _container.Resolve <IMembershipValidationService>();
            _membershipService           = _container.Resolve <IMembershipService>();
        }
        public virtual void Init()
        {
            _databaseFilePath = Path.GetTempFileName();
            _sessionFactory   = DataUtility.CreateSessionFactory(_databaseFilePath, DatabaseTypes.ToArray());
            _session          = _sessionFactory.OpenSession();
            _clock            = new StubClock();

            var builder = new ContainerBuilder();

            //builder.RegisterModule(new ImplicitCollectionSupportModule());
            builder.RegisterInstance(new StubLocator(_session)).As <ISessionLocator>();
            builder.RegisterInstance(_clock).As <IClock>();
            builder.RegisterGeneric(typeof(Repository <>)).As(typeof(IRepository <>));
            Register(builder);
            _container = builder.Build();
        }
Exemplo n.º 22
0
        public void ConvertToLocalizedTimeStringTest04()
        {
            var timeZone  = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var clock     = new StubClock(new DateTime(2012, 10, 3, 12, 0, 0, DateTimeKind.Utc));
            var container = TestHelpers.InitializeContainer("en-US", null, timeZone, clock);
            var target    = container.Resolve <IDateLocalizationServices>();

            var dateString = "3/10/2012";
            var timeString = "12:00:00 PM";

            var dateTimeUtc = target.ConvertFromLocalizedString(dateString, timeString);

            var dateString2 = target.ConvertToLocalizedDateString(dateTimeUtc);
            var timeString2 = target.ConvertToLocalizedTimeString(dateTimeUtc, new DateLocalizationOptions()
            {
                IgnoreDate = true
            });

            Assert.AreEqual(dateString, dateString2);
            Assert.AreEqual(timeString, timeString2);
        }
Exemplo n.º 23
0
        public virtual void Init()
        {
            _databaseFilePath = Path.GetTempFileName();
            _sessionFactory   = DataUtility.CreateSessionFactory(_databaseFilePath, DatabaseTypes.ToArray());
            _session          = _sessionFactory.OpenSession();
            _transaction      = _session.BeginTransaction(IsolationLevel.ReadCommitted);

            _clock = new StubClock();

            var builder = new ContainerBuilder();

            //builder.RegisterModule(new ImplicitCollectionSupportModule());
            builder.RegisterInstance(new StubLocator(_session)).As <ISessionLocator>();
            builder.RegisterInstance(_clock).As <IClock>();
            builder.RegisterGeneric(typeof(Repository <>)).As(typeof(IRepository <>));
            builder.RegisterInstance(new ShellSettings {
                Name = ShellSettings.DefaultName, DataProvider = "SqlCe"
            });
            Register(builder);
            _container = builder.Build();
        }
Exemplo n.º 24
0
        public void StoreAssemblyShouldCopyFile()
        {
            var clock         = new StubClock();
            var appDataFolder = new StubAppDataFolder(clock);

            var assembly = GetType().Assembly;
            var name     = assembly.GetName().Name;

            {
                var dependenciesFolder = new DefaultAssemblyProbingFolder(appDataFolder, new DefaultAssemblyLoader(Enumerable.Empty <IAssemblyNameResolver>()));
                dependenciesFolder.StoreAssembly(name, assembly.Location);
            }

            {
                var dependenciesFolder = new DefaultAssemblyProbingFolder(appDataFolder, new DefaultAssemblyLoader(Enumerable.Empty <IAssemblyNameResolver>()));
                Assert.That(dependenciesFolder.AssemblyExists(name), Is.True);
                Assert.That(dependenciesFolder.LoadAssembly(name), Is.SameAs(GetType().Assembly));
                Assert.DoesNotThrow(() => dependenciesFolder.DeleteAssembly(name));
                Assert.That(dependenciesFolder.LoadAssembly(name), Is.Null);
            }
        }
Exemplo n.º 25
0
        public void Init()
        {
            if (Directory.Exists(_basePath))
            {
                Directory.Delete(_basePath, true);
            }

            Directory.CreateDirectory(_basePath);
            _appDataFolder   = AppDataFolderTests.CreateAppDataFolder(_basePath);
            _webDownloader   = new Mock <IWebDownloader>();
            _orchardServices = new StubOrchardServices();
            ((StubWorkContextAccessor.WorkContextImpl.StubSite)_orchardServices.WorkContext.CurrentSite).BaseUrl = "http://orchardproject.net";

            _settings = new WarmupSettingsPart();

            _orchardServices.WorkContext.CurrentSite.ContentItem.Weld(_settings);
            _orchardServices.WorkContext.CurrentSite.ContentItem.Weld(new InfosetPart());

            var builder = new ContainerBuilder();

            builder.RegisterInstance(_appDataFolder).As <IAppDataFolder>();
            builder.RegisterInstance(_orchardServices).As <IOrchardServices>();
            builder.RegisterType <DefaultLockFileManager>().As <ILockFileManager>();
            builder.RegisterType <WarmupUpdater>().As <IWarmupUpdater>();
            builder.RegisterType <StubClock>().As <IClock>();
            builder.RegisterType <WarmupReportManager>().As <IWarmupReportManager>();
            builder.RegisterInstance(new ShellSettings {
                Name = "Default"
            }).As <ShellSettings>();
            builder.RegisterInstance(_clock = new StubClock()).As <IClock>();
            builder.RegisterInstance(_webDownloader.Object).As <IWebDownloader>();
            _container = builder.Build();

            _lockFileManager = _container.Resolve <ILockFileManager>();
            _warmupUpdater   = _container.Resolve <IWarmupUpdater>();
            _reportManager   = _container.Resolve <IWarmupReportManager>();

            _warmupFilename = _appDataFolder.Combine(TenantFolder, "warmup.txt");
            _lockFilename   = _appDataFolder.Combine(TenantFolder, "warmup.txt.lock");
        }
        public virtual void Init()
        {
            _databaseFilePath = Path.GetTempFileName();
            _sessionFactory   = DataUtility.CreateSessionFactory(_databaseFilePath, DatabaseTypes.ToArray());
            _session          = _sessionFactory.OpenSession();
            _clock            = new StubClock();

            var builder = new ContainerBuilder();

            //builder.RegisterModule(new ImplicitCollectionSupportModule());
            builder.RegisterType <InfosetHandler>().As <IContentHandler>();
            builder.RegisterInstance(new StubLocator(_session)).As <ISessionLocator>();
            builder.RegisterInstance(_clock).As <IClock>();
            builder.RegisterGeneric(typeof(Repository <>)).As(typeof(IRepository <>)).InstancePerLifetimeScope();
            builder.RegisterInstance(_shellSettings = new ShellSettings {
                Name = ShellSettings.DefaultName, DataProvider = "SqlCe"
            });
            builder.RegisterType <TestTransactionManager>().As <ITransactionManager>().InstancePerLifetimeScope();
            builder.Register(context => _sessionFactory.OpenSession()).As <ISession>().InstancePerLifetimeScope();

            Register(builder);
            _container = builder.Build();
        }
        public void Init()
        {
            var clock = new StubClock();

            _appDataFolder = new StubAppDataFolder(clock);
        }
Exemplo n.º 28
0
 public void before_each_test()
 {
     clock      = StubClock.FromDate(2012, 1, 1);
     controller = new HomeController(clock);
 }
Exemplo n.º 29
0
 public StubMessageChannel(TimeSpan simulatedProcessingTime, StubClock clock)
 {
     _simulatedProcessingTime = simulatedProcessingTime;
     _clock = clock;
 }
Exemplo n.º 30
0
 protected ReportTests()
 {
     Clock    = new StubClock();
     Reporter = new Reporter(Clock);
 }