コード例 #1
0
        public override void FixtureSetUp()
        {
            base.FixtureSetUp();

            var topics = mongoDb.GetCollectionByType<Topic>();
            var subscriptions = mongoDb.GetCollectionByType<Subscription>();
            var groups = mongoDb.GetCollectionByType<Group>();

            var group = new Group();
            groups.Insert(group);

            tc =  new Topic { Description = "T1", Name = "Aaaa", GroupId = group.Id.Value };
            tc2 = new Topic { Description = "T2", Name = "Aaaa", GroupId = group.Id.Value };
            topics.Insert(tc);
            topics.Insert(tc2);

            subs1 = new Subscription
                            {
                                TargetKind = TargetKind.Topic,
                                TargetId = tc.Id ,
                                Callback = new Callback()
                            };

            subs2 = new Subscription
                            {
                                TargetKind = TargetKind.Topic,
                                TargetId = tc2.Id,
                                Callback = new Callback ()
                            };
            subscriptions.InsertBatch(new[] { subs1, subs2 });
        }
コード例 #2
0
 public void WhenThereIsNotATopicWithGivenName_ThenReturnsFalse()
 {
     var existTopicByTopicName = new ExistTopicByName(connectionString);
     var topic = new Topic {Id = Identity.Random(12), Name = "Foo", GroupId = Identity.Random(12) };
     topicsCollection.Insert(topic);
     existTopicByTopicName.Execute(topic.GroupId, "Bar").Should().Be.False();
 }
コード例 #3
0
ファイル: TopicsFixture.cs プロジェクト: ashic/Hermes
        public void Should_get_all_topic()
        {
            var group = new M.Group {
                Id = Identity.Random()
            };
            var topics = new M.Topic[]
            {
                new M.Topic {
                    Description = "description 1",
                    GroupId     = group.Id.Value,
                    Id          = Identity.Random(),
                    Name        = "test 1"
                },
                new M.Topic {
                    Description = "description 2",
                    GroupId     = group.Id.Value,
                    Id          = Identity.Random(),
                    Name        = "test 2"
                }
            };

            mockedGenericJsonQuery.Setup(r => r.Execute <Topic>(null, null, null)).Returns(topics);

            var result = client.ExecuteGet <F.Topic[]>("");

            Assert.IsNotNull(topics);
            Assert.AreEqual(topics.Length, result.Length);
            Assert.IsTrue(topics.All(t1 => result.Any(t2 => t1.Id == t2.Id.ToModel() && t1.Name == t2.Name)));
        }
コード例 #4
0
 public void WhenThereIsATopicWithSameNameInDifferentGroup_ThenReturnsFalse()
 {
     var existTopicByTopicName = new ExistTopicByName(connectionString);
     var topic = new Topic { Id = Identity.Random(12), Name = "Foo", GroupId = Identity.Random(12) };
     topicsCollection.Insert(topic);
     existTopicByTopicName.Execute(Identity.Random(12), "Foo", Identity.Random(12)).Should().Be.False();
 }
コード例 #5
0
 public void WhenThereIsATopicWithSameNameAndIdNull_ThenReturnsTrue()
 {
     var existTopicByTopicName = new ExistTopicByName(connectionString);
     var topic = new Topic { Id = Identity.Random(12), Name = "Foo", GroupId = Identity.Random(12) };
     topicsCollection.Insert(topic);
     existTopicByTopicName.Execute(topic.GroupId, "Foo", null).Should().Be.True();
 }
コード例 #6
0
ファイル: TopicsFixture.cs プロジェクト: jasondentler/Hermes
        public void Should_get_all_topic()
        {
            var group = new M.Group { Id = Identity.Random() };
            var topics = new M.Topic[]
                             {
                                new M.Topic{
                                Description = "description 1",
                                GroupId = group.Id.Value ,
                                Id = Identity.Random(),
                                Name = "test 1"
                                },
                                new M.Topic{
                                Description = "description 2",
                                GroupId = group.Id.Value ,
                                Id = Identity.Random(),
                                Name = "test 2"
                                }
                             };

            mockedGenericJsonQuery.Setup(r => r.Execute<Topic>(null, null, null)).Returns(topics);

            var result = client.ExecuteGet<F.Topic[]>("");

            Assert.IsNotNull(topics);
            Assert.AreEqual(topics.Length, result.Length);
            Assert.IsTrue(topics.All(t1 => result.Any(t2 => t1.Id == t2.Id.ToModel() && t1.Name == t2.Name)));
        }
コード例 #7
0
ファイル: CreateTopicCommand.cs プロジェクト: larsw/Hermes
        public virtual void Execute(Topic topic)
        {
            if (string.IsNullOrWhiteSpace(topic.Name )) throw new ValidationException(Texts.NameMustBeNotNull);
            if (existsTopicByName.Execute(topic.GroupId, topic.Name)) throw new ValidationException(Texts.TopicNameMustBeUnique, topic.Name);
            if (topic.GroupId.HasValue && !entityById.Exist<Group>(topic.GroupId.Value)) throw new ValidationException(Texts.EntityNotFound, typeof(Group).Name, topic.GroupId);

            repository.MakePersistent(topic);
        }
コード例 #8
0
 public void WhenIdIsNull_ThenThrowValidateException()
 {
     var command = CreateUpdateTopicCommand();
     var topic = new Topic { Id = null };
     command.Executing(c => c.Execute(topic))
                             .Throws<ValidationException>()
                             .And
                             .Exception.Message.Should().Be.EqualTo(string.Format(Texts.IdMustNotBeNull));
 }
コード例 #9
0
        public ActionResult Create(EditTopicModel model)
        {
            if (!ModelState.IsValid) return View(model);

            var topic = new Topic();
            ModelToEntity(model, topic);
            createTopicCommand.Execute(topic);
            return RedirectToAction("Index");
        }
コード例 #10
0
        public void CanExecuteIndex()
        {
            var expected = new Topic[]{};
            var topicsController = CreateController(Mock.Of<ITopicsSortedByName>(q => q.Execute() == expected));

            topicsController.Index()
                    .GetModel<IEnumerable<Topic>>()
                    .Should().Be.SameInstanceAs(expected);
        }
コード例 #11
0
        public void WhenJustGroupIsMissing_ThenInsertTheTopic()
        {
            var name = "Test";
            var stubRepository = new StubRepository<Topic>();
            var command = CreateCreateTopicCommand(cudTopic: stubRepository);
            var topic = new Topic { Name = name };
            command.Execute(topic);

            stubRepository.Entities.Should().Contain(topic);
        }
コード例 #12
0
 public void WhenIdIsInvalid_ThenThrowEntityNotFoundException()
 {
     var id = Identity.Random();
     var command = CreateUpdateTopicCommand(entityById: Mock.Of<IEntityById>( q => q.Exist<Topic>(id) == false));
     var topic = new Topic { Id = id };
     command.Executing(c => c.Execute(topic))
                             .Throws<EntityNotFoundException>()
                             .And
                             .Exception.Message.Should().Be.EqualTo(string.Format(Texts.EntityNotFound, typeof(Topic).Name, id));
 }
コード例 #13
0
        public void WhenPostingATopic_ThenMapAndSaveChanges()
        {
            var topic = new Topic { Name = "Topic 1", Description = "Foo", GroupId = SampleGroup.Id.Value };
            var entityById = Mock.Of<IEntityById>(e => e.Get<Topic>(It.IsAny<Identity>()) == topic);

            var topicsController = CreateController(entityById: entityById);

            topicsController.Edit(new EditTopicModel {Description = "Desc", Name = "Tap"});
            topic.Satisfy(t => t.Description == "Desc" && t.Name == "Tap");
        }
コード例 #14
0
        public override void FixtureSetUp()
        {
            base.FixtureSetUp();
            var group = new Group {Description = "Abcd", Name = "hello"};
            mongoDb.GetCollectionByType<Group>().Insert(group);

            topic1 = new Topic { Name = "Zos", GroupId = group.Id.Value, Description = "bbb" };
            topic2 = new Topic { Name = "Bos", GroupId = group.Id.Value, Description = "aaa" };
            topic3 = new Topic { Name = "Acd", GroupId = group.Id.Value, Description = "aaa" };
            mongoDb.GetCollectionByType<Topic>().InsertMany(topic1, topic2, topic3);
        }
コード例 #15
0
        public void WhenTopicExist_ThenReturnViewResultWithTopicAsModel()
        {
            var expected = new Topic {Name = "Topic 1", Description = "Foo", GroupId = SampleGroup.Id.Value, Id = Identity.Random()};
            var entityById = Mock.Of<IEntityById>(e => e.Get<Topic>(It.IsAny<Identity>() ) == expected);

            var topicsController = CreateController(entityById: entityById);

            topicsController.Edit(Identity.Random().ToString())
                .GetModel<EditTopicModel>()
                .Satisfy(t => t.Name == "Topic 1" && t.Description == "Foo");
        }
コード例 #16
0
        public void WhengGroupIdDoesNotExist_ThenThrowException()
        {
            var name = "Test";
            var groupId = Identity.Random();
            var command = CreateCreateTopicCommand(entityById: Mock.Of<IEntityById>(q => q.Exist<Topic>(groupId) == false));

            var topic = new Topic { Name = name, GroupId  = groupId};
            command.Executing(gc => gc.Execute(topic))
                                    .Throws<ValidationException>()
                                    .And
                                    .Exception.Message.Should().Be.EqualTo(string.Format(Texts.EntityNotFound, typeof(Group).Name, groupId));
        }
コード例 #17
0
        public void WhenEverythingIsOK_ThenInsertTheTopic()
        {
            var name = "Test";
            var groupId = Identity.Random();
            var stubRepository = new StubRepository<Topic>();
            var command = CreateCreateTopicCommand(entityById: Mock.Of<IEntityById>(q => q.Exist<Group>(groupId)),
                                    cudTopic: stubRepository);
            var topic = new Topic { Name = name, GroupId = groupId };
            command.Execute(topic);

            stubRepository.Entities.Should().Contain(topic);
        }
コード例 #18
0
        public void WhenEverythingIsOK_ThenUpdateTheTopic()
        {
            var stubRepository = new StubRepository<Topic>();
            var id = Identity.Random();
            var name = "Test";
            var groupId = Identity.Random();
            var command = CreateUpdateTopicCommand(entityById: Mock.Of<IEntityById>(q => q.Exist<Topic>(id) && q.Exist<Group>(groupId)),
                existsTopicByName: Mock.Of<IExistsTopicByName>(q => q.Execute(groupId, name, id) == false), cudTopic: stubRepository);
            var topic = new Topic { Id = id, Name = name, GroupId = groupId };

            command.Execute(topic);

            stubRepository.Updates.Should().Contain(topic);
        }
コード例 #19
0
        public void SetUp()
        {
            var group = new Group{Name = "TheSuperGroup"};
            mongoDb.GetCollectionByType<Group>()
                   .Insert(group);

            topic = new Topic
                            {
                                GroupId = group.Id.Value
                            };

            mongoDb.GetCollectionByType<Topic>()
                   .Insert(topic);
        }
コード例 #20
0
        public void SetUp()
        {
            var topicsCollection = base.mongoDb.GetCollection<Topic>(MongoDbConstants.Collections.Topics);
            var groupsCollection = base.mongoDb.GetCollection<Group>(MongoDbConstants.Collections.Groups);
            topicsCollection.RemoveAll();
            groupsCollection.RemoveAll();

            groupWithTopics = new Group { Id = Identity.Random(12), Name = "With topics" };
            groupsCollection.Insert(groupWithTopics);

            groupWithoutTopics = new Group { Id = Identity.Random(12), Name = "With topics" };
            groupsCollection.Insert(groupWithoutTopics);

            var topic = new Topic {Name = "Topic 1", GroupId = groupWithTopics.Id.Value};
            topicsCollection.Insert(topic);
        }
コード例 #21
0
ファイル: TopicFixture.cs プロジェクト: ashic/Hermes
        public void Should_get_a_topic_by_name_and_without_group()
        {
            var topic = new M.Topic()
            {
                Description = "description",
                Id          = Identity.Random(),
                Name        = "test"
            };

            mockedTopicByName.Setup(r => r.Get(topic.Name, null)).Returns(topic);

            var result = client.ExecuteGet <F.Topic>("/?name=" + topic.Name);

            Assert.AreEqual(topic.Description, result.Description);
            Assert.AreEqual(topic.Id, result.Id.ToModel());
            Assert.AreEqual(topic.Name, result.Name);
        }
コード例 #22
0
ファイル: TopicFixture.cs プロジェクト: ashic/Hermes
        public void Should_get_a_topic_by_name_and_groupId()
        {
            var group = new M.Group { Id = Identity.Random() };
            var topic = new M.Topic()
            {
                Description = "description",
                GroupId = group.Id.Value,
                Id = Identity.Random(),
                Name = "test"
            };
            mockedTopicByName.Setup(r => r.Get(topic.Name, group.Id)).Returns(topic);

            var result = client.ExecuteGet<F.Topic>("/?name=" + topic.Name + "&groupId=" + group.Id);

            Assert.AreEqual(topic.Description, result.Description);
            Assert.AreEqual(topic.Id, result.Id.ToModel());
            Assert.AreEqual(topic.Name, result.Name);
        }
コード例 #23
0
ファイル: TopicFixture.cs プロジェクト: ashic/Hermes
        public void Should_get_a_topic_by_id()
        {
            var group = new M.Group {
                Id = Identity.Random()
            };
            var topic = new M.Topic()
            {
                Description = "description",
                GroupId     = group.Id.Value,
                Id          = Identity.Random(),
                Name        = "test"
            };

            mockedEntityById.Setup(r => r.Get <Topic>(topic.Id.Value)).Returns(topic);

            var result = client.ExecuteGet <F.Topic>("/" + topic.Id);

            Assert.AreEqual(topic.Description, result.Description);
            Assert.AreEqual(topic.Id, result.Id.ToModel());
            Assert.AreEqual(topic.Name, result.Name);
        }
コード例 #24
0
ファイル: TopicsStatisticsTests.cs プロジェクト: ashic/Hermes
        public void SetUp()
        {
            var group = new Group {Name = "aaa"};
            mongoDb.GetCollectionByType<Group>().Insert(group);

            fooTopic = new Topic {Name = "FooTopic", Description = "a", GroupId = group.Id.Value };
            barTopic = new Topic {Name = "BarTopic", Description = "a", GroupId = group.Id.Value };

            mongoDb.GetCollectionByType<Topic>()
                    .InsertMany(fooTopic, barTopic);

            mongoDb.GetCollection<Message>(MongoDbConstants.GetCollectionNameForMessage(fooTopic.Id.Value))
                    .InsertMany(new Message
                                    {
                                        UtcReceivedOn = new DateTime(2011, 1, 1),
                                        TopicId = fooTopic.Id.Value
                                    },
                                    new Message
                                    {
                                        UtcReceivedOn = new DateTime(2011, 2, 2),
                                        TopicId = fooTopic.Id.Value
                                    },
                                    new Message
                                    {
                                        UtcReceivedOn = new DateTime(2011, 10, 2),
                                        TopicId = fooTopic.Id.Value
                                    });

            mongoDb.GetCollection<Message>(MongoDbConstants.GetCollectionNameForMessage(barTopic.Id.Value))
                .InsertMany(new Message
                                {
                                    UtcReceivedOn = new DateTime(2011, 1, 1),
                                    TopicId = barTopic.Id.Value
                                },
                            new Message
                                {
                                    UtcReceivedOn = new DateTime(2011, 2, 2),
                                    TopicId = barTopic.Id.Value
                                });
        }
コード例 #25
0
 private static void ModelToEntity(EditTopicModel model, Topic entity)
 {
     entity.Name = model.Name;
     entity.Description = model.Description;
     if (!string.IsNullOrEmpty(model.Group))
     {
         entity.GroupId = (Identity) model.Group;
     }
 }
コード例 #26
0
ファイル: FeedFixture.cs プロジェクト: jasondentler/Hermes
        private SyndicationFeed GetFeedForMessage(Message message)
        {
            var messageId = message.Id.Value;
            var topicId = message.TopicId;

            var feedEntry = new FeedEntry() { MessageId = messageId, TimeStamp = DateTime.UtcNow };
            var feed = new Feed()
            {
                Entries = new List<FeedEntry>(new[] { feedEntry }),
                Id = Identity.Random(),
                TopicId = topicId,
                Updated = DateTime.UtcNow
            };

            var topic = new Topic()
            {
                Id = topicId,
                Name = "Topic Name",
                Description = "Topic Description",
                GroupId = Identity.Random()
            };

            var key = new MessageKey { MessageId = messageId, TopicId = topicId };

            messageByMessageKey
                .Setup(r => r.Get(It.Is<MessageKey>(k => k.TopicId == key.TopicId && k.MessageId == key.MessageId)))
                .Returns(message);

            getWorkingFeedForTopic
                .Setup(r => r.Execute(topicId))
                .Returns(feed);

            entityById
                .Setup(r => r.Get<Topic>(topicId))
                .Returns(topic);

            var client = new HttpClient(baseUri);

            var response = client.Get(topicId.ToString());
            var formatter = new Atom10FeedFormatter();

            using (var rdr = XmlReader.Create(response.Content.ContentReadStream))
            {
                formatter.ReadFrom(rdr);
                return formatter.Feed;
            }
        }
コード例 #27
0
        public void WhenNameIsNull_ThenThrowValidateException()
        {
            var id = Identity.Random();

            var command = CreateUpdateTopicCommand(entityById: Mock.Of<IEntityById>(q => q.Exist<Topic>(id)));

            var topic = new Topic { Id = id, Name = null };
            command.Executing(c => c.Execute(topic))
                                    .Throws<ValidationException>()
                                    .And
                                    .Exception.Message.Should().Be.EqualTo(string.Format(Texts.NameMustBeNotNull));
        }