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 }); }
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(); }
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))); }
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(); }
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(); }
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))); }
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); }
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)); }
public ActionResult Create(EditTopicModel model) { if (!ModelState.IsValid) return View(model); var topic = new Topic(); ModelToEntity(model, topic); createTopicCommand.Execute(topic); return RedirectToAction("Index"); }
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); }
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); }
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)); }
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"); }
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); }
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"); }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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 }); }
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; } }
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; } }
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)); }