public void Should_get_a_group_by_id() { var parent = new M.Group { Id = M.Identity.Random() }; var group = new M.Group { Id = M.Identity.Random(), Name = "sample", Description = "sample group", ParentId = parent.Id }; mockedEntityById.Setup(r => r.Get <Group>(group.Id.Value)).Returns(group); var result = client.ExecuteGet <F.Group>("/" + group.Id); Assert.AreEqual(group.Description, result.Description); Assert.AreEqual(group.Id, result.Id.ToModel()); Assert.AreEqual(group.Name, result.Name); Assert.IsNotEmpty(result.Links); result.Links.Satisfy(ls => ls.Any(l => l.Relation == TellagoStudios.Hermes.RestService.Constants.Relationships.Parent && l.Uri == ResourceLocation.OfGroup(parent.Id.Value).ToString())); }
public void Should_get_all_topic_groups() { var parent = new M.Group { Id = M.Identity.Random() }; var groups = new M.Group[] { new M.Group { Description = "description 1", Id = M.Identity.Random(), Name = "test 1", ParentId = parent.Id }, new M.Group { Description = "description 2", Id = M.Identity.Random(), Name = "test 2", ParentId = parent.Id } }; mockedGenericJsonQuery.Setup(r => r.Execute <Group>(null, null, null)).Returns(groups); var result = client.ExecuteGet <F.Group[]>(""); mockedGenericJsonQuery.Verify(r => r.Execute <Group>(null, null, null)); Assert.IsNotNull(groups); Assert.AreEqual(groups.Length, result.Length); Assert.IsTrue(groups.All(t1 => result.Any(t2 => t1.Id == t2.Id.ToModel() && t1.Name == t2.Name))); }
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 WhenBothGroupsAreTRansientAndRefEquals_ThenAreequals() { var foo = new Group {Id = null}; foo.Equals(foo) .Should().Be.True(); }
public void Should_get_all_topic_groups() { var parent = new M.Group { Id = M.Identity.Random() }; var groups = new M.Group[] { new M.Group{ Description = "description 1", Id = M.Identity.Random(), Name = "test 1", ParentId = parent.Id }, new M.Group{ Description = "description 2", Id = M.Identity.Random(), Name = "test 2", ParentId = parent.Id } }; mockedGenericJsonQuery.Setup(r => r.Execute<Group>(null, null, null)).Returns(groups); var result = client.ExecuteGet<F.Group[]>(""); mockedGenericJsonQuery.Verify(r => r.Execute<Group>(null, null, null)); Assert.IsNotNull(groups); Assert.AreEqual(groups.Length, result.Length); Assert.IsTrue(groups.All(t1 => result.Any(t2 => t1.Id == t2.Id.ToModel() && t1.Name == t2.Name))); }
public void Should_post_a_topic_group() { //TODO fix var groupPost = new F.GroupPost() { Description = "description", Name = "test", ParentId = F.Identity.Random() }; var parent = new M.Group { Id = groupPost.ParentId.ToModel() }; mockedCreateCommand.Setup(r => r.Execute(It.IsAny <M.Group>())) .Callback <M.Group>(g => g.Id = new Identity("4de7e38617b6c420a45a84c4")); var result = client.ExecutePost("", groupPost); mockedCreateCommand.Verify(r => r.Execute(It.Is <M.Group>(g => g.Satisfy(gr => gr != null && gr.Description == groupPost.Description && gr.Name == groupPost.Name && gr.ParentId == groupPost.ParentId.ToModel())))); Assert.IsNotNull(result); }
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 WhenBothHaveDifferentKeys_ThenAreequals() { var foo = new Group { Id = new Identity("Fde7e38617b6c420a45a84c4") }; var bar = new Group { Id = new Identity("Ade7e38617b6c420a45a84c4") }; foo.Equals(bar) .Should().Be.False(); }
public void WhenBothGroupsArePersistedAndHasSameId_ThenAreequals() { var foo = new Group { Id = new Identity("4de7e38617b6c420a45a84c4") }; var bar = new Group { Id = new Identity("4de7e38617b6c420a45a84c4") }; foo.Equals(bar) .Should().Be.True(); }
public void WhenBothGroupsAreTRansientAndNotRefEquals_ThenAreNotEquals() { var foo = new Group { Id = null }; var bar = new Group { Id = null }; foo.Equals(bar) .Should().Be.False(); }
public void WhenOtherIsPersistedAndThisIsTransient_ThenAreNotEquals() { var foo = new Group { Id = null }; var bar = new Group { Id = new Identity("4de7e38617b6c420a45a84c4") }; foo.Equals(bar) .Should().Be.False(); }
public void WhenOtherIsTransientAndThisIsPersisted_ThenAreNotEquals() { var @this = new Group { Id = new Identity("4de7e38617b6c420a45a84c4") }; var other = new Group { Id = null}; @this.Equals(other) .Should().Be.False(); }
public void Execute(Group group) { if (string.IsNullOrWhiteSpace(group.Name)) throw new ValidationException(Texts.NameMustBeNotNull); if (existGroupByGroupName.Execute(group.Name)) throw new ValidationException(Texts.GroupNameMustBeUnique, group.Name); if (group.ParentId.HasValue && !entityById.Exist<Group>(group.ParentId.Value)) throw new ValidationException(Texts.EntityNotFound); repository.MakePersistent(group); }
public void SetUp() { var groupsCollection = base.mongoDb.GetCollection<Group>(MongoDbConstants.Collections.Groups); groupsCollection.RemoveAll(); group = new Group { Name = "A" }; groupsCollection.Save(group); }
public void WhenEverythingIsOK_ThenInsertTheGroup() { var stubRepository = new StubRepository<Group>(); var groupCommand = CreateCreateGroupCommand(cudGroup: stubRepository); var @group = new Group { Name = "test"}; groupCommand.Execute(@group); stubRepository.Entities.Should().Contain(@group); }
public void InsertingShouldWork() { var cudGroup = new Repository<Group>(connectionString); var entity = new Group{Name = "Test", Description = "Abcd"}; cudGroup.MakePersistent(entity); mongoDb.GetCollection(MongoDbConstants.Collections.Groups) .FindOneById(entity.Id.Value.ToBson()) .Should().Not.Be.Null(); }
public void WhenEntityExist_ThenGetReturnsEntity() { var existEntityById = new EntityById(connectionString); var entity = new Group { Name = "Foo" }; mongoDb.GetCollection(MongoDbConstants.Collections.Groups) .Insert(entity); existEntityById.Get<Group>(entity.Id.Value) .Satisfy(e => e != null && e.Name == "Foo"); }
public void WhenParentIdDoesNotExist_ThenThrowException() { var groupCommand = CreateCreateGroupCommand(entityById: Mock.Of<IEntityById>(q => q.Exist<Group>(It.IsAny<Identity>()) == false)); var @group = new Group { Name = "test", ParentId = new Identity(Guid.NewGuid())}; groupCommand.Executing(gc => gc.Execute(@group)) .Throws<ValidationException>() .And .Exception.Message.Should().Be.EqualTo(Texts.EntityNotFound); }
public void WhenIdExist_ThenReturnsTrue() { var existEntityById = new EntityById(connectionString); var entity = new Group { Name = "Foo" }; mongoDb.GetCollection(MongoDbConstants.Collections.Groups) .Insert(entity); existEntityById.Exist<Group>(entity.Id.Value) .Should().Be.True(); }
public void WhenDoesNotIdExist_ThenReturnsFalse() { var existEntityById = new EntityById(connectionString); var entity = new Group { Name = "Foo" }; mongoDb.GetCollection(MongoDbConstants.Collections.Groups) .Insert(entity); existEntityById.Exist<Group>(new Identity("4de7e38617b6c420a45a84c4")) .Should().Be.False(); }
public void Execute(Group group) { if (!group.Id.HasValue) throw new ValidationException(Texts.IdMustNotBeNull); if (!entityById.Exist<Group>(group.Id.Value)) throw new EntityNotFoundException(typeof(Group), group.Id.Value); if (string.IsNullOrWhiteSpace(group.Name)) throw new ValidationException(Texts.NameMustBeNotNull); if (existGroupByGroupName.Execute(group.Name, group.Id)) throw new ValidationException(Texts.GroupNameMustBeUnique, group.Name); if (group.ParentId.HasValue && !entityById.Exist<Group>(group.ParentId.Value)) throw new ValidationException(Texts.EntityNotFound); ValidateCircleReferences(group); repository.Update(group); }
public void SetUp() { var collection = mongoDb.GetCollection(MongoDbConstants.Collections.Groups); collection.RemoveAll(); withChilds = new Group{Id = Identity.Random(12), Name = "With childs"}; collection.Insert(withChilds); withoutChilds = new Group { Id = Identity.Random(12), Name = "Without childs", ParentId = withChilds.Id }; collection.Insert(withoutChilds); }
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 WhenEverythingIsOK_ThenUpdateTheGroup() { var id = Identity.Random(); var stubRepository = new StubRepository<Group>(); var groupCommand = CreateUpdateGroupCommand(entityById: Mock.Of<IEntityById>(q => q.Exist<Group>(id)), cudGroup: stubRepository); var @group = new Group { Id=id, Name = "test" }; groupCommand.Execute(@group); stubRepository.Updates.Should().Contain(@group); }
private void ValidateCircleReferences(Group group) { var parentsId = new HashSet<Identity>(); var currentParentId = group.ParentId; while (currentParentId.HasValue) { if(!parentsId.Add(currentParentId.Value)) break; currentParentId = entityById.Get<Group>(currentParentId.Value).ParentId; } if (parentsId.Contains(group.Id.Value)) throw new ValidationException(string.Format(Texts.GroupCircleReference, group.Id)); }
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 UpdateShouldWork() { var cudGroup = new Repository<Group>(connectionString); var entity = new Group { Name = "Test", Description = "Abcd" }; mongoDb.GetCollection(MongoDbConstants.Collections.Groups).Insert(entity); entity.Name = "Tito"; //act cudGroup.Update(entity); mongoDb.GetCollection<Group>(MongoDbConstants.Collections.Groups) .FindOneById(entity.Id.Value.ToBson()) .Name.Should().Be.EqualTo("Tito"); }
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 override void FixtureSetUp() { base.FixtureSetUp(); var groupCollection = base.mongoDb.GetCollection<Group>(MongoDbConstants.Collections.Groups); //foo => Bar => Baz // => Foz foo = new Group {Name = "foo"}; groupCollection.Insert(foo); bar = new Group {Name = "Bar", ParentId = foo.Id}; groupCollection.Insert(bar); baz = new Group {Name = "Baz", ParentId = bar.Id}; groupCollection.Insert(baz); foz = new Group {Name = "Foz", ParentId = bar.Id}; groupCollection.Insert(foz); }
private IEnumerable<Group> GetEnumeration(Group @group) { while (group != null) { yield return group; if(group.ParentId.HasValue) { group = groupCollection.FindById(group.ParentId.Value); } else { break; } } }
public void Should_get_a_topic_by_name_and_without_group() { var group = new M.Group() { Description = "description", Id = Identity.Random(), Name = "test" }; mockedGroupByName.Setup(r => r.Get(group.Name)).Returns(group); var result = client.ExecuteGet<F.Group>("/?name=" + group.Name); Assert.AreEqual(group.Description, result.Description); Assert.AreEqual(group.Id, result.Id.ToModel()); Assert.AreEqual(group.Name, result.Name); }
public void Should_get_a_topic_by_name_and_without_group() { var group = new M.Group() { Description = "description", Id = Identity.Random(), Name = "test" }; mockedGroupByName.Setup(r => r.Get(group.Name)).Returns(group); var result = client.ExecuteGet <F.Group>("/?name=" + group.Name); Assert.AreEqual(group.Description, result.Description); Assert.AreEqual(group.Id, result.Id.ToModel()); Assert.AreEqual(group.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 ModelToFacadeMapsCorrectly() { var model = new M.Group { Description = _description, Id = _id.ToModel(), Name = _name, ParentId = _parentId.ToModel() }; var facade = model.ToFacade(); Assert.That(facade.Description, Is.EqualTo(_description)); Assert.That(facade.Name, Is.EqualTo(_name)); Assert.That(facade.Id, Is.EqualTo(_id)); facade.Links.Should().Contain(new Link(ResourceLocation.OfGroup(_parentId.ToModel()), TellagoStudios.Hermes.RestService.Constants.Relationships.Parent)); }
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); }