示例#1
0
        private async void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            this.logger.LogDebug("get: data generation event elapsed");

            var topic = new TopicBuilder("playground")
                        .With("data")
                        .With("rng")
                        .Build();

            this.logger.LogDebug("get: generating data");
            var generatedData = this.GenerateRandomData().ToList();

            this.logger.LogDebug("get: generating data completed");

            var watch = Stopwatch.StartNew();

            this.logger.LogInformation($"get: enqueing {generatedData.Count} events");
            foreach (var data in generatedData)
            {
                this.logger.LogDebug($"get: creating event for topic {topic} and data {data}");
                var evt = new ValueEvent(topic, data);

                this.logger.LogDebug("get: enququing event");
                await this.publisher.WriteAsync(evt)
                .ConfigureAwait(false);
            }

            this.logger.LogInformation($"get: enqueing {generatedData.Count} events completed in {watch.ElapsedMilliseconds} ms");
        }
示例#2
0
        public void ToPublisherBuilder_FromSubscriberWithoutWildcards()
        {
            // Arrange
            var topics = Fixture.Create <List <string> >();

            var builder = new TopicBuilder(topics.Count + 1, TopicConsumer.Subscriber)
                          .AddTopics(topics);

            // Act
            var publisherBuilder = builder.ToPublisherBuilder();

            // Assert
            publisherBuilder.Levels
            .Should()
            .Be(builder.Levels,
                "because the content of the builder should remain the same");

            publisherBuilder.TopicCollection.ToArray()
            .Should()
            .Contain(builder.TopicCollection.ToArray(),
                     "because the content of the builder should remain the same");

            publisherBuilder.Consumer
            .Should()
            .Be(TopicConsumer.Publisher,
                "because the consumer should have changed for the converted builder");
        }
        public async Task Publish_diff_when_receiving_another_state_of_the_show()
        {
            var showId             = "3";
            var clientConnectionId = "signalR...";
            var topic = TopicBuilder.BuildTopicFor(showId);

            var fakeSignalR      = Substitute.For <IPublishMessages>();
            var publisherFactory = new PublisherFactory(fakeSignalR);
            IObserveReservedSeats clientProxy = new ClientProxy(showId, clientConnectionId, new List <string>(),
                                                                publisherFactory.GetPublisher());

            // Fake a new state of the show reception
            await clientProxy.Notify(new[] { "A1", "B7" });

            // Check that we published those new seats to the client
            var expectedPublication = new[] { "A1", "B7" };
            await fakeSignalR.Received().SendNewlyReservedSeatsAsync(topic, clientConnectionId,
                                                                     Arg.Is <string[]>(x => expectedPublication.SequenceEqual(x)));


            // Fake a new state of the show reception
            await clientProxy.Notify(new[] { "A1", "B2", "B7", "D99" });

            // Only the diff must be published then
            expectedPublication = new[] { "B2", "D99" };
            await fakeSignalR.Received().SendNewlyReservedSeatsAsync(topic, clientConnectionId,
                                                                     Arg.Is <string[]>(x => expectedPublication.SequenceEqual(x)));
        }
示例#4
0
        public void TestCreate()
        {
            Topic topic = TopicBuilder.New().WithName("Nome teste").Build();

            Assert.True(topic.Id != Guid.Empty && topic.Id != null);
            Assert.True(topic.Name == "Nome teste");
        }
示例#5
0
        private async Task TransformAsync(IEvent evt)
        {
            this.logger.LogDebug($"transform: received evt with topic {evt.Topic}");

            var topic = new TopicBuilder("playground")
                        .With("data")
                        .With("ascii")
                        .Build();

            if (!(evt is ValueEvent valueEvent))
            {
                this.logger.LogWarning($"transform: event is not from expected type ValueEvent");
                return;
            }

            this.logger.LogDebug("transform: transforming value to ascii");
            var ascii = Convert.ToChar(valueEvent.Value);

            this.logger.LogDebug($"transform: creating ascii event from transformed value {ascii}");
            var asciiEvent = new AsciiEvent(topic, ascii);

            this.logger.LogDebug("transform: enqueuing event");
            await this.publisher.WriteAsync(asciiEvent)
            .ConfigureAwait(false);
        }
示例#6
0
        public void TestValidationBadTopicNameNull()
        {
            var badTopic = TopicBuilder.New().WithName(null).Build();

            var resultValidation = new TopicValidator().Validate(badTopic);

            Assert.False(resultValidation.IsValid);
        }
示例#7
0
        void Handler(MessagePacket messagePacket)
        {
            var topic = new TopicBuilder().Excatly(service.ServiceName).Excatly(service.NodeName).Excatly("heartbeat").Excatly("response").Build();

            service.GetModules <Communicator>().ForEach(x => x.SendMessage(new MessagePacket {
                topic = topic
            }));
        }
示例#8
0
        public void GetByIdReturnsBadRequest()
        {
            var topic = TopicBuilder.New().Build();

            var result = controller.Get(topic.Id);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
示例#9
0
        public void TestValidationTopic()
        {
            var okTopic = TopicBuilder.New().Build();

            var resultValidation1 = new TopicValidator().Validate(okTopic);

            Assert.True(resultValidation1.IsValid);
        }
示例#10
0
        public void Builder_with_root_path_should_create_topic_with_leading_slash()
        {
            var expectedPath = "/root";

            var topic = new TopicBuilder("root")
                        .Build();

            Assert.Equal(expectedPath, topic.Path);
        }
示例#11
0
        public void TestGetAll()
        {
            Topic topic = TopicBuilder.New().WithName("Skate").Build();

            new CreateTopic().CreateNewRegister(topic);
            var idGet = new GetTopic().GetRegisterById(topic.Id);

            Assert.IsNotNull(idGet);
        }
示例#12
0
        public void GetByIdReturnsOk()
        {
            var topic = TopicBuilder.New().Build();

            creator.CreateNewRegister(topic);

            var result = controller.Get(topic.Id);

            Assert.IsType <OkObjectResult>(result.Result);
        }
示例#13
0
        public void PutReturnsBadRequest_TopicNotValid()
        {
            var topic = TopicBuilder.New().Build();

            creator.CreateNewRegister(topic);

            var result = controller.Put(topic.Id, "  ");

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
示例#14
0
        public void PutReturnsBadRequest_PublicationNotExistOnDatabase()
        {
            var topic = TopicBuilder.New().Build();

            new CreateTopic().CreateNewRegister(topic);

            var result = controller.Put(Guid.NewGuid(), "Nome put", "Conteudo", topic.Id);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
示例#15
0
        public void PostReturnsBadRequest_UserInvalid()
        {
            var topic = TopicBuilder.New().Build();

            new CreateTopic().CreateNewRegister(topic);

            var result = controller.Post(Guid.NewGuid(), "Titulo", "Conteudo", topic.Id);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
示例#16
0
        public void TestValidationPublicationBadTopic()
        {
            var badTopic = TopicBuilder.New().WithName("  ").Build();

            var badPublication = PublicationBuilder.New().WithTopic(badTopic).Build();

            var resultValidation = new PublicationValidator().Validate(badPublication);

            Assert.False(resultValidation.IsValid);
        }
示例#17
0
        public void TestValidationTopicExist()
        {
            var topic = TopicBuilder.New().WithName("Nome teste").Build();

            new TopicRepository().Create(topic);

            var resultValidation = new TopicExistValidator().Validate(topic.Id);

            Assert.True(resultValidation.IsValid);
        }
示例#18
0
        public async Task <ActionResult> SendNotification(string showId)
        {
            var topic = TopicBuilder.BuildTopicFor(showId);

            await _publisher.SendNewlyReservedSeatsToAllAsync(topic, new[] { "AZ", "ZZ" });

            //await _hubContext.Clients.All.SendAsync(topic, "Super message de ouf");

            return(Ok(""));
        }
示例#19
0
        public async Task WriteAsync_should_take_event_without_subscription()
        {
            var topic = new TopicBuilder("root").Build();

            var expectedEvent = new FakeEvent(topic, "Test");

            using var bus = new Bus();

            await bus.WriteAsync(expectedEvent).ConfigureAwait(false);
        }
示例#20
0
        public void Builder_with_deep_path_should_create_topic_with_delemitted_slashes()
        {
            var expectedPath = "/root/worker/config/changed";

            var topic = new TopicBuilder("root")
                        .With("worker")
                        .With("config")
                        .With("changed")
                        .Build();

            Assert.Equal(expectedPath, topic.Path);
        }
示例#21
0
        public MultipleEventsDataCollection()
        {
            var topic = new TopicBuilder("test").Build();

            this.AddRow(topic, new[] {
                new FakeEvent(topic, "Test"),
                new FakeEvent(topic, "Test"),
                new FakeEvent(topic, "Test"),
                new FakeEvent(topic, "Test"),
                new FakeEvent(topic, "Test")
            });
        }
示例#22
0
        public void TestValidationBadTopicNameExistsOnDatabase()
        {
            var topic = TopicBuilder.New().WithName("Nome").Build();

            new TopicRepository().Create(topic);

            var badTopic = new Topic("Nome");

            var resultValidation = new TopicValidator().Validate(badTopic);

            Assert.False(resultValidation.IsValid);
        }
示例#23
0
        public void AddTopic_OnBlankTopic()
        {
            // Arrange
            ITopicBuilder builder = new TopicBuilder(TopicConsumer.Subscriber);

            // Act
            Action appendingEmptyTopic = () =>
                                         builder.AddTopic(string.Empty);

            // Assert
            appendingEmptyTopic.Should()
            .Throw <EmptyTopicException>("because an empty topic is not a valid one to be added");
        }
示例#24
0
        public void RemoveInexistentQuestionShouldFail()
        {
            // Arrange
            var falseQuestion = new QuestionBuilder().Build();
            var question = new QuestionBuilder().Build();
            var topic = new TopicBuilder().WithQuestion(question).Build();

            // Act
               var actual = topic.Questions.Remove(falseQuestion);

            // Assert
            Assert.IsFalse(actual);
        }
示例#25
0
        public Topic GetDefaultTopic(string title)
        {
            var topic = new TopicBuilder()
                .WithTitle(title)
                .WithQuestion(this.GetDefaultQuestion("Question 1"))
                .WithQuestion(this.GetDefaultQuestion("Question 2"))
                .WithQuestion(this.GetDefaultQuestion("Question 3"))
                .WithQuestion(this.GetDefaultQuestion("Question 4"))
                .WithQuestion(this.GetDefaultQuestion("Question 5"))
                .Build();

            return topic;
        }
        public void find_some_comments()
        {
            TopicBuilder.FindComments(@"
a
b
<!--Title: foo-->
c
d
<!--Url: bar-->
e
f
").Each(x => Debug.WriteLine(x));
        }
示例#27
0
        public void AddSingleLevelWildcard()
        {
            // Arrange
            ITopicBuilder builder = new TopicBuilder(TopicConsumer.Publisher);

            // Act
            Action addSingleLevelWildcard = () =>
                                            builder = builder.AddMultiLevelWildcard();

            // Assert
            addSingleLevelWildcard.Should()
            .Throw <IllegalStateOperationException>(
                "because a topic used on PUBLISH mode cannot use wildcard");
        }
示例#28
0
        public void AddTopic_OnTopicSeparator()
        {
            // Arrange
            ITopicBuilder builder = new TopicBuilder(TopicConsumer.Subscriber);

            // Act
            Action appendingTopic = () =>
                                    builder.AddTopic(
                Mqtt.Topic.Separator.ToString());

            // Assert
            appendingTopic.Should()
            .Throw <InvalidTopicException>("because the topic separator is not a valid topic to be appended");
        }
示例#29
0
        public void PostReturnsBadRequest_PublicationInvalid()
        {
            var user = UserBuilder.New().Build();

            new CreateUser().CreateNewRegister(user);

            var topic = TopicBuilder.New().Build();

            new CreateTopic().CreateNewRegister(topic);

            var result = controller.Post(user.Id, "", "Conteudo", topic.Id);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
示例#30
0
        public void PostReturnsOk()
        {
            var user = UserBuilder.New().Build();

            new CreateUser().CreateNewRegister(user);

            var topic = TopicBuilder.New().Build();

            new CreateTopic().CreateNewRegister(topic);

            var result = controller.Post(user.Id, "Titulo", "Conteudo", topic.Id);

            Assert.IsType <CreatedAtActionResult>(result.Result);
        }
示例#31
0
        public void Builder_from_topic_should_copy_topic_path()
        {
            const string expectedPath = "/root/worker/config";

            var topic = new TopicBuilder("root")
                        .With("worker")
                        .With("config")
                        .Build();

            var pattern = new PatternBuilder()
                          .FromTopic(topic)
                          .Build();

            Assert.Equal(expectedPath, pattern.Value);
        }
示例#32
0
        private async Task PublishNewReservedSeats(IEnumerable <string> newlyAddedReservations)
        {
            var topic = TopicBuilder.BuildTopicFor(_showId);

            if (_messagePublisher == null)
            {
                // TEMP: should not happen at runtime!!!!
                _messagePublisher = _publishersFactory();
            }

            // Should we catch here?
            // var publisher = _publishersFactory(); // get a SignalR publisher
            await _messagePublisher.SendNewlyReservedSeatsAsync(topic, _clientConnectionId,
                                                                newlyAddedReservations.ToArray());
        }
示例#33
0
        public void RemoveQuestionToTopicShouldWork()
        {
            // Arrange
            var expectedCount = 0;
            var question = new QuestionBuilder().Build();
            var topic = new TopicBuilder().WithQuestion(question).Build();

            // Act
            topic.Questions.Remove(question);
            var actualCount = topic.Questions.Count();
            var actualQuestion = topic.Questions.FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreSame(null, actualQuestion);
        }
示例#34
0
        public void AddQuestionToTopicShouldWork()
        {
            // Arrange
            var expectedQuestionTitle = "Test Question";
            var expectedCount = 1;
            var topic = new TopicBuilder().Build();
            var question = new QuestionBuilder().WithText(expectedQuestionTitle).Build();

            // Act
            topic.Questions.Add(question);
            var actualCount = topic.Questions.Count();
            var actualQuestion = topic.Questions.FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreSame(question, actualQuestion);
        }
示例#35
0
        public void AddTopicToFormShouldWork()
        {
            // Arrange
            var expectedTopicTitle = "Test Topic";
            var expectedCount = 1;
            var form = new FormBuilder().Build();
            var topic = new TopicBuilder().WithTitle(expectedTopicTitle).Build();

            // Act
            form.Topics.Add(topic);
            var actualCount = form.Topics.Count();
            var actualTopic = form.Topics.FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreSame(topic, actualTopic);
        }
示例#36
0
        public void RemoveTopicToFormShouldWork()
        {
            // Arrange
            var expectedCount = 0;
            var topic = new TopicBuilder().Build();
            var form = new FormBuilder().WithTopic(topic).Build();

            // Act
            form.Topics.Remove(topic);
            var actualCount = form.Topics.Count();
            var actualTopic = form.Topics.FirstOrDefault();

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreSame(null, actualTopic);
        }
示例#37
0
        public void RemoveInexistentTopicShouldFail()
        {
            // Arrange
            var falseTopic = new TopicBuilder().Build();
            var topic = new TopicBuilder().Build();
            var form = new FormBuilder().WithTopic(topic).Build();

            // Act
            var actual = form.Topics.Remove(falseTopic);

            Assert.IsFalse(actual);
        }
示例#38
0
        public void TopicTitleShouldGetAndSetValues()
        {
            // Arrange
            var topic = new TopicBuilder().Build();
            var expected = "Test Topic";

            // Act
            topic.Title = expected;
            var actual = topic.Title;

            // Assert
            Assert.AreEqual(expected, actual);
        }
示例#39
0
        public void TopicIdShouldGetAndSetValues()
        {
            // Arrange
            var topic = new TopicBuilder().Build();
            var expected = 45;

            // Act
            topic.Id = expected;
            var actual = topic.Id;

            // Assert
            Assert.AreEqual(expected, actual);
        }