public void PeriodicTasks_YoutubeDown_DecoratorReportsErrors()
        {
            var errorableDownloadFactory = Substitute.For <IErrorableFactory <string, string, string, string> >();

            errorableDownloadFactory.Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns("");
            var sender         = new TestableSerializer();
            var testableLogger = new TestableLogger();
            var container      = new TestContainerManager(c => {
                var senderRegistration = Lifestyle.Singleton.CreateRegistration(() => sender, c);
                c.RegisterConditional(typeof(IFactory <IEnumerable <ISendable <ITransmittable> >, IEnumerable <string> >), senderRegistration, _ => true);
                var errorableDownloadFactoryRegistration = Lifestyle.Singleton.CreateRegistration(() => errorableDownloadFactory, c);
                c.RegisterConditional(typeof(IErrorableFactory <string, string, string, string>), errorableDownloadFactoryRegistration, _ => true);
                var loggerRegistration = Lifestyle.Singleton.CreateRegistration(() => testableLogger, c);
                c.RegisterConditional(typeof(ILogger), loggerRegistration, pc => !pc.Handled);
            }, settings => settings.PeriodicMessageInterval = TimeSpan.FromMilliseconds(100))
                                 .InitializeAndIsolateRepository();
            var periodicTaskRunner = container.GetInstance <PeriodicTaskRunner>();

            periodicTaskRunner.Run();

            Task.Delay(900).Wait();
            Console.WriteLine(ObjectDumper.Dump(testableLogger.Outbox));
            Assert.IsTrue(testableLogger.Outbox.Any(x => x.Contains("Error occured in GenericClassFactoryTryCatchDecorator")));
            Assert.IsTrue(testableLogger.Outbox.Any(x => x.Contains("input1 is \"https://www.youtube.com/feeds/videos.xml?user=destiny\"")));
        }
        public void PeriodicTasks_Run_YieldsAlternatingMessages()
        {
            var errorableDownloadFactory = Substitute.For <IErrorableFactory <string, string, string, string> >();

            errorableDownloadFactory.Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(TestData.YoutubeFeed);
            var sender    = new TestableSerializer();
            var container = new TestContainerManager(c => {
                var senderRegistration = Lifestyle.Singleton.CreateRegistration(() => sender, c);
                c.RegisterConditional(typeof(IFactory <IEnumerable <ISendable <ITransmittable> >, IEnumerable <string> >), senderRegistration, _ => true);
                var errorableDownloadFactoryRegistration = Lifestyle.Singleton.CreateRegistration(() => errorableDownloadFactory, c);
                c.RegisterConditional(typeof(IErrorableFactory <string, string, string, string>), errorableDownloadFactoryRegistration, _ => true);
            }, settings => settings.PeriodicMessageInterval = TimeSpan.FromMilliseconds(100))
                            .InitializeAndIsolateRepository();
            var periodicTaskRunner = container.GetInstance <PeriodicTaskRunner>();

            periodicTaskRunner.Run();

            Task.Delay(1000).Wait();
            var cache = "";

            foreach (var sendable in sender.Outbox.Cast <SendablePublicMessage>())
            {
                if (sendable.Text == cache)
                {
                    Assert.Fail();
                }
                cache = sendable.Text;
            }
        }
        public void PeriodicTwitterStatusUpdaterHandle_NewDb_UpdatesDbAndSendsOneMessage_DoNotRunContinuously()
        {
            var sender               = new TestableSerializer();
            var container            = GetContainer(sender);
            var periodicTaskRunner   = container.GetInstance <PeriodicTwitterStatusUpdater>();
            var unitOfWork           = container.GetInstance <IQueryCommandService <IUnitOfWork> >();
            var latestDestinyTweetId = unitOfWork.Query(u => u.StateIntegers.LatestDestinyTweetId);

            Assert.AreEqual(-1, latestDestinyTweetId);

            periodicTaskRunner.Handle();

            Task.Delay(400).Wait();
            Assert.AreEqual(1, sender.Outbox.Cast <SendablePublicMessage>().Count());
            latestDestinyTweetId = unitOfWork.Query(u => u.StateIntegers.LatestDestinyTweetId);
            Assert.AreNotEqual(-1, latestDestinyTweetId);
        }
Exemple #4
0
        public void Should_prioritize_non_default_serializer_match()
        {
            const string expectedMediaRange = "application/json";

            var expectedSerializer =
                new TestableSerializer(expectedMediaRange);

            var serializers = new ISerializer[]
            {
                new DefaultJsonSerializer(GetTestingEnvironment()),
                expectedSerializer
            };

            this.serializerFactory = new DefaultSerializerFactory(serializers);

            // When
            var result = this.serializerFactory.GetSerializer(expectedMediaRange);

            // Then
            result.ShouldBeSameAs(expectedSerializer);
        }
Exemple #5
0
        public void Should_return_serializer_for_media_range(string expectedMediaRange)
        {
            // Given
            var expectedSerializer =
                new TestableSerializer(expectedMediaRange);

            var serializers = new ISerializer[]
            {
                expectedSerializer,
                new TestableSerializer("custom/foo"),
                new TestableSerializer("custom/bar"),
                new TestableSerializer("custom/baz"),
            };

            this.serializerFactory = new DefaultSerializerFactory(serializers);

            // When
            var result = this.serializerFactory.GetSerializer(expectedMediaRange);

            // Then
            result.ShouldBeSameAs(expectedSerializer);
        }
 private static Container GetContainer(TestableSerializer sender) => new TestContainerManager(c => {
     var senderRegistration = Lifestyle.Singleton.CreateRegistration(() => sender, c);
     c.RegisterConditional(typeof(IFactory <IEnumerable <ISendable <ITransmittable> >, IEnumerable <string> >), senderRegistration, _ => true);
 }, settings => settings.TwitterStatusUpdaterInterval = TimeSpan.FromMilliseconds(100))
 .InitializeAndIsolateRepository();