Beispiel #1
0
        public void PostLayerRelationRuleTest()
        {
            var expected = _tester.LayerRelationRule;
            var model    = new RelationFormModel()
            {
                SourceId   = expected.SourceLayerId,
                TargetId   = expected.TargetLayerId,
                Color      = expected.Color,
                ArrowStyle = expected.ArrowStyle
            };

            _tester.TestControllerWithMockData(_tester.Supervisor.UId)
            .Calling(c => c.PostLayerRelationRule(model))
            .ShouldHave()
            .DbContext(db => db.WithSet <LayerRelationRule>(relations =>
                                                            relations.Any(actual =>
                                                                          expected.SourceLayerId == actual.SourceLayerId &&
                                                                          expected.TargetLayerId == actual.TargetLayerId &&
                                                                          expected.Color == actual.Color &&
                                                                          expected.ArrowStyle == actual.ArrowStyle
                                                                          )
                                                            ))
            .AndAlso()
            .ShouldReturn()
            .Ok();
        }
Beispiel #2
0
        public void PostTagRelationRuleTest()
        {
            var expected = new RelationFormModel()
            {
                SourceId   = _tester.Tag1.Id,
                TargetId   = _tester.Tag2.Id,
                Title      = "relationName",
                Color      = "schwarzgelb",
                ArrowStyle = "dotted"
            };

            _tester.TestControllerWithMockData()
            .Calling(c => c.PostTagRelationRule(expected))
            .ShouldHave()
            .DbContext(db => db.WithSet <AnnotationTagRelationRule>(relations =>
                                                                    relations.Any(actual =>
                                                                                  actual.SourceTagId == expected.SourceId &&
                                                                                  actual.TargetTagId == expected.TargetId &&
                                                                                  actual.Title == expected.Title &&
                                                                                  actual.Color == expected.Color &&
                                                                                  actual.ArrowStyle == expected.ArrowStyle
                                                                                  )
                                                                    ))
            .AndAlso()
            .ShouldReturn()
            .Ok();
        }
Beispiel #3
0
        public bool RemoveTagRelationRule(RelationFormModel original)
        {
            var entity = DbContext.TagRelationRules.Single(EqualsTagRelationRule(original));

            DbContext.Remove(entity);
            DbContext.SaveChanges();
            return(true);
        }
Beispiel #4
0
 public AnnotationTagInstanceRelation(RelationFormModel model)
 {
     SourceTagId = model.SourceId;
     TargetTagId = model.TargetId;
     Title       = model.Title;
     ArrowStyle  = model.ArrowStyle;
     Color       = model.Color;
 }
Beispiel #5
0
 private static bool TagRulesEqual(AnnotationTagRelationRule actual, RelationFormModel expected)
 {
     return(actual.SourceTagId == expected.SourceId &&
            actual.TargetTagId == expected.TargetId &&
            actual.Title == expected.Title &&
            actual.Description == expected.Description &&
            actual.Color == expected.Color &&
            actual.ArrowStyle == expected.ArrowStyle);
 }
Beispiel #6
0
        public void DeleteTagRelationTest403()
        {
            var model = new RelationFormModel()
            {
                SourceId = _tester.Relation12.SourceTag.Id,
                TargetId = _tester.Relation12.TargetTag.Id
            };

            _tester.TestController(_tester.Student.UId)
            .Calling(c => c.DeleteTagRelation(model))
            .ShouldReturn()
            .Forbid();
        }
Beispiel #7
0
        public void PostTagRelationTest_NoChildToFirstLevelRelation()
        {
            var expected = new RelationFormModel()
            {
                SourceId = _tester.Tag3.Id,
                TargetId = _tester.Tag2.Id,
                Title    = "child-to-toplevel-relation"
            };

            _tester.TestController()
            .WithDbContext(dbContext => dbContext
                           .WithSet <AnnotationTag>(db => db.AddRange(_tester.Tag1, _tester.Tag2, _tester.Tag3))
                           )
            .Calling(c => c.PostTagInstanceRelation(expected))
            .ShouldHave()
            .DbContext(db => db.WithSet <AnnotationTagInstanceRelation>(relations =>
                                                                        !relations.Any(actual => // negated --> NO relation like this exists
                                                                                       actual.SourceTagId == expected.SourceId &&
                                                                                       actual.TargetTagId == expected.TargetId &&
                                                                                       actual.Title == expected.Title
                                                                                       )
                                                                        ))
            .AndAlso()
            .ShouldReturn()
            .NotFound();

            // other way around is also not allowed:
            expected = new RelationFormModel()
            {
                SourceId = _tester.Tag2.Id,
                TargetId = _tester.Tag3.Id,
                Title    = "toplevel-to-child-relation"
            };
            _tester.TestController()
            .WithDbContext(dbContext => dbContext
                           .WithSet <AnnotationTag>(db => db.AddRange(_tester.Tag1, _tester.Tag2, _tester.Tag3))
                           )
            .Calling(c => c.PostTagInstanceRelation(expected))
            .ShouldHave()
            .DbContext(db => db.WithSet <AnnotationTagInstanceRelation>(relations =>
                                                                        !relations.Any(actual => // negated --> NO relation like this exists
                                                                                       actual.SourceTagId == expected.SourceId &&
                                                                                       actual.TargetTagId == expected.TargetId &&
                                                                                       actual.Title == expected.Title
                                                                                       )
                                                                        ))
            .AndAlso()
            .ShouldReturn()
            .NotFound();
        }
Beispiel #8
0
        public void DeleteTagRelationTest404()
        {
            var model = new RelationFormModel()
            {
                SourceId = _tester.Relation12.SourceTag.Id,
                TargetId = _tester.Relation12.TargetTag.Id
            };

            _tester.TestControllerWithMockData()
            // --> no AnnotationTagRelation objects were added to the database
            .Calling(c => c.DeleteTagRelation(model))
            .ShouldReturn()
            .NotFound();
        }
Beispiel #9
0
        public void PostTagRelationTest403()
        {
            var expected = new RelationFormModel()
            {
                SourceId = _tester.Tag1.Id,
                TargetId = _tester.Tag2.Id,
                Title    = "relation-with-nonexisting-tags"
            };

            _tester.TestController(_tester.Student.UId) // id = 2 --> student
            .Calling(c => c.PostTagInstanceRelation(expected))
            .ShouldReturn()
            .Forbid();
        }
Beispiel #10
0
        internal bool RemoveTagRelation(RelationFormModel model)
        {
            var tag1 = DbContext.AnnotationTags.Single(tag => tag.Id == model.SourceId);
            var tag2 = DbContext.AnnotationTags.Single(tag => tag.Id == model.TargetId);

            if (TagRelationExists(tag1, tag2))
            {
                RemoveRelationFor(tag1, tag2);
                DbContext.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #11
0
        internal bool AddTagRelation(RelationFormModel model)
        {
            var tag1 = DbContext.AnnotationTagInstances.Single(tag => tag.Id == model.SourceId);
            var tag2 = DbContext.AnnotationTagInstances.Single(tag => tag.Id == model.TargetId);

            if (tag1 != null && tag2 != null)
            {
                var forwardRelation = new AnnotationTagInstanceRelation(tag1, tag2, model.Title, model.ArrowStyle, model.Color);
                DbContext.AnnotationTagRelations.Add(forwardRelation);
                DbContext.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #12
0
        public void PostTagInstanceRelationTest_NoDuplicateRelations()
        {
            var expected = new RelationFormModel()
            {
                SourceId = _tester.Relation12.SourceTag.Id,
                TargetId = _tester.Relation12.TargetTag.Id,
                Title    = "duplicate-relation"
            };

            _tester.TestController()
            .WithDbContext(dbContext => dbContext
                           .WithSet <AnnotationTagInstance>(db => db.AddRange(_tester.TagInstance1, _tester.TagInstance2))
                           .WithSet <AnnotationTagInstanceRelation>(db => db.Add(_tester.Relation12))
                           )
            .Calling(c => c.PostTagInstanceRelation(expected))
            .ShouldReturn()
            .NotFound();
        }
 public IActionResult DeleteTagRelation([FromBody] RelationFormModel model)
 {
     if (!_annotationPermissions.IsAllowedToEditTags(User.Identity.GetUserIdentity()))
     {
         return(Forbid());
     }
     try
     {
         if (_tagManager.RemoveTagRelation(model))
         {
             return(Ok());
         }
         return(NotFound());
     }
     catch (InvalidOperationException)
     {
         return(NotFound());
     }
 }
        public IActionResult PostLayerRelationRule([FromBody] RelationFormModel model)
        {
            if (!_annotationPermissions.IsAllowedToCreateRelationRules(User.Identity.GetUserIdentity()))
            {
                return(Forbid());
            }

            try
            {
                if (_tagManager.AddLayerRelationRule(model))
                {
                    return(Ok());
                }
                return(NotFound());
            }
            catch (InvalidOperationException)
            {
                return(NotFound());
            }
        }
Beispiel #15
0
        public bool AddTagRelationRule(RelationFormModel model)
        {
            if (!(DbContext.AnnotationTags.Any(t => t.Id == model.SourceId) &&
                  DbContext.AnnotationTags.Any(t => t.Id == model.TargetId)))
            {
                return(false);
            }
            var rule = new AnnotationTagRelationRule()
            {
                SourceTagId = model.SourceId,
                TargetTagId = model.TargetId,
                Title       = model.Title,
                Description = model.Description,
                Color       = model.Color,
                ArrowStyle  = model.ArrowStyle
            };

            DbContext.TagRelationRules.Add(rule);
            DbContext.SaveChanges();
            return(true);
        }
Beispiel #16
0
        internal bool AddLayerRelationRule(RelationFormModel model)
        {
            if (!(DbContext.Layers.Any(l => l.Id == model.SourceId) || DbContext.Layers.Any(l => l.Id == model.TargetId)))
            {
                return(false);
            }
            var rule = new LayerRelationRule()
            {
                SourceLayerId = model.SourceId,
                TargetLayerId = model.TargetId,
                Title         = model.Title,
                Description   = model.Description,
                Color         = model.Color,
                ArrowStyle    = model.ArrowStyle
            };

            DbContext.LayerRelationRules.Add(rule);
            DbContext.SaveChanges();
            Console.Write("added relation:" + model.SourceId + model.TargetId);
            return(true);
        }
Beispiel #17
0
        public void DeleteTagRelationTest()
        {
            var model = new RelationFormModel()
            {
                SourceId = _tester.Relation12.SourceTag.Id,
                TargetId = _tester.Relation12.TargetTag.Id
            };

            _tester.TestController()
            .WithDbContext(dbContext => dbContext
                           .WithSet <AnnotationTag>(db => db.AddRange(_tester.Tag1, _tester.Tag2))
                           .WithSet <AnnotationTagInstanceRelation>(db => db.Add(_tester.Relation12))
                           )
            .Calling(c => c.DeleteTagRelation(model))
            .ShouldHave()
            .DbContext(db => db.WithSet <AnnotationTagInstanceRelation>(rels =>
                                                                        !rels.Any(rel => rel.SourceTagId == model.SourceId && rel.TargetTagId == model.TargetId))
                       )
            .AndAlso()
            .ShouldReturn()
            .Ok();
        }
Beispiel #18
0
        public void PostLayerRelationRuleTest403()
        {
            var expected = _tester.LayerRelationRule;
            var model    = new RelationFormModel()
            {
                SourceId   = expected.SourceLayerId,
                TargetId   = expected.TargetLayerId,
                Color      = expected.Color,
                ArrowStyle = expected.ArrowStyle
            };

            _tester.TestController(_tester.Student.UId)
            .WithDbContext(dbContext => dbContext
                           .WithSet <Layer>(db => db.AddRange(expected.SourceLayer, expected.TargetLayer))
                           )
            .Calling(c => c.PostLayerRelationRule(model))
            .ShouldHave()
            .DbContext(db => db.WithSet <LayerRelationRule>(relations =>
                                                            !relations.Any(actual => actual.Equals(expected))
                                                            ))
            .AndAlso()
            .ShouldReturn()
            .Forbid();
        }
Beispiel #19
0
        public void PostTagRelationTest404()
        {
            var expected = new RelationFormModel()
            {
                SourceId = _tester.Tag1.Id,
                TargetId = _tester.Tag2.Id,
                Title    = "relation-with-nonexisting-tags"
            };

            _tester.TestController()
            // --> tags 1 and 2 were NOT added to the database
            .Calling(c => c.PostTagInstanceRelation(expected))
            .ShouldHave()
            .DbContext(db => db.WithSet <AnnotationTagInstanceRelation>(relations =>
                                                                        !relations.Any(actual => // negated --> NO relation like this exists
                                                                                       actual.SourceTagId == expected.SourceId &&
                                                                                       actual.TargetTagId == expected.TargetId &&
                                                                                       actual.Title == expected.Title
                                                                                       )
                                                                        ))
            .AndAlso()
            .ShouldReturn()
            .NotFound();
        }
Beispiel #20
0
 private static Expression <Func <AnnotationTagRelationRule, bool> > EqualsTagRelationRule(RelationFormModel original)
 {
     return(r => r.SourceTagId == original.SourceId &&
            r.TargetTagId == original.TargetId &&
            r.Title == original.Title);
 }