public void ShouldThrowExceptionWhenFkDependencyNotSatisfy()
        {
            Db.CreateManyToMany <Trajectory, Graphic, TrajectoryGraphicRelationalTable>(tgr => tgr.Trajectory.Id, tgr => tgr.Graphic.Id);

            var trajectory        = new Trajectory();
            var graphic           = new Graphic();
            var trajectoryGraphic = new TrajectoryGraphicRelationalTable(trajectory, graphic);

            Db.Insert(trajectory);
            Db.Insert(graphic);
            Db.Insert(trajectoryGraphic);

            Assert.True(1 == Db.Count <Trajectory>());
            Assert.True(1 == Db.Count <Graphic>());
            Assert.True(1 == Db.Count <TrajectoryGraphicRelationalTable>());

            Assert.Equal(trajectory.Id, Db.GetAll <TrajectoryGraphicRelationalTable>().First().Trajectory.Id);
            Assert.Equal(graphic.Id, Db.GetAll <TrajectoryGraphicRelationalTable>().First().Graphic.Id);

            trajectoryGraphic.Trajectory = new Trajectory();

            var ex = Assert.Throws <InvalidOperationException>(() => { Db.Update(trajectoryGraphic); });

            Assert.Equal("Invalid FK", ex.Message);

            Assert.True(1 == Db.Count <Trajectory>());
            Assert.True(1 == Db.Count <Graphic>());
            Assert.True(1 == Db.Count <TrajectoryGraphicRelationalTable>());

            Assert.Equal(trajectory.Id, Db.GetAll <TrajectoryGraphicRelationalTable>().First().Trajectory.Id);
            Assert.Equal(graphic.Id, Db.GetAll <TrajectoryGraphicRelationalTable>().First().Graphic.Id);
        }
        public void ShouldUpdateIfFkSatisfy()
        {
            Db.CreateManyToMany <Trajectory, Graphic, TrajectoryGraphicRelationalTable>(tgr => tgr.Trajectory.Id, tgr => tgr.Graphic.Id);

            var trajectory        = new Trajectory();
            var trajectory2       = new Trajectory();
            var graphic           = new Graphic();
            var trajectoryGraphic = new TrajectoryGraphicRelationalTable(trajectory, graphic);

            Db.Insert(trajectory);
            Db.Insert(trajectory2);
            Db.Insert(graphic);
            Db.Insert(trajectoryGraphic);

            Assert.True(2 == Db.Count <Trajectory>());
            Assert.True(1 == Db.Count <Graphic>());
            Assert.True(1 == Db.Count <TrajectoryGraphicRelationalTable>());

            Assert.Equal(trajectory.Id, Db.GetAll <TrajectoryGraphicRelationalTable>().First().Trajectory.Id);
            Assert.Equal(graphic.Id, Db.GetAll <TrajectoryGraphicRelationalTable>().First().Graphic.Id);

            trajectoryGraphic.Trajectory = trajectory2;
            Db.Update(trajectoryGraphic);

            Assert.True(2 == Db.Count <Trajectory>());
            Assert.True(1 == Db.Count <Graphic>());
            Assert.True(1 == Db.Count <TrajectoryGraphicRelationalTable>());

            Assert.Equal(trajectory2.Id, Db.GetAll <TrajectoryGraphicRelationalTable>().First().Trajectory.Id);
            Assert.Equal(graphic.Id, Db.GetAll <TrajectoryGraphicRelationalTable>().First().Graphic.Id);
        }
Exemple #3
0
        public void ShouldDeleteInCascateWithMultipleManyToManyDeletingRelationalTable()
        {
            Db.CreateManyToMany <Trajectory, Graphic, TrajectoryGraphicRelationalTable>(tgr => tgr.Trajectory.Id, tgr => tgr.Graphic.Id);

            var trajectory1        = new Trajectory();
            var trajectory2        = new Trajectory();
            var graphic1           = new Graphic();
            var graphic2           = new Graphic();
            var trajectoryGraphic1 = new TrajectoryGraphicRelationalTable(trajectory1, graphic1);
            var trajectoryGraphic2 = new TrajectoryGraphicRelationalTable(trajectory2, graphic2);

            Db.Insert(trajectory1);
            Db.Insert(trajectory2);
            Db.Insert(graphic1);
            Db.Insert(graphic2);
            Db.Insert(trajectoryGraphic1);
            Db.Insert(trajectoryGraphic2);

            Assert.True(2 == Db.Count <Trajectory>());
            Assert.True(2 == Db.Count <Graphic>());
            Assert.True(2 == Db.Count <TrajectoryGraphicRelationalTable>());

            Db.Delete(trajectoryGraphic1);

            Assert.True(2 == Db.Count <Trajectory>());
            Assert.True(2 == Db.Count <Graphic>());
            Assert.True(1 == Db.Count <TrajectoryGraphicRelationalTable>());
        }
Exemple #4
0
        public void ShouldDeleteInCascateDeletingTable1()
        {
            var trajectory        = new Trajectory();
            var graphic           = new Graphic();
            var trajectoryGraphic = new TrajectoryGraphicRelationalTable(trajectory, graphic);

            Db.CreateManyToMany <Trajectory, Graphic, TrajectoryGraphicRelationalTable>(tgr => tgr.Trajectory.Id, tgr => tgr.Graphic.Id);

            Db.Insert(trajectory);
            Db.Insert(graphic);
            Db.Insert(trajectoryGraphic);

            Assert.True(1 == Db.Count <Trajectory>());
            Assert.True(1 == Db.Count <Graphic>());
            Assert.True(1 == Db.Count <TrajectoryGraphicRelationalTable>());

            Db.Delete(trajectory);

            Assert.True(0 == Db.Count <Trajectory>());
            Assert.True(1 == Db.Count <Graphic>());
            Assert.True(0 == Db.Count <TrajectoryGraphicRelationalTable>());
        }