public void TestCreateAndGetAll()
        {
            ICountryDao countryDao = new CountryDao(_graphClient);
            Country country = new Country() {Name = "D"};
            countryDao.Create(country);

            IRoutesDao routeDao = new RouteDao(_graphClient);
            Route route = new Route() {Name = "Route1"};
            routeDao.CreateIn(country, route);

            IDifficultyLevelScaleDao scaleDao = new DifficultyLevelScaleDao(_graphClient);
            DifficultyLevelScale scale = new DifficultyLevelScale() {Name = "sächsisch"};
            scaleDao.Create(scale);

            IDifficultyLevelDao levelDao = new DifficultyLevelDao(_graphClient);
            DifficultyLevel level = new DifficultyLevel() {Name = "7b"};
            levelDao.Create(scale, level);

            IVariationDao variationDao = new VariationDao(_graphClient);
            Variation variation = new Variation() {Name = "Ein Weg der Route1 als 7b"};
            Variation created = variationDao.Create(variation, route, level);

            IList<Variation> variationsOnRoute = variationDao.GetAllOn(route);
            Assert.AreEqual(1, variationsOnRoute.Count);
            Assert.AreEqual(variation.Name, variationsOnRoute.First().Name);
            Assert.AreEqual(variation.Id, variationsOnRoute.First().Id);
            Assert.AreEqual(created.Id, variationsOnRoute.First().Id);
        }
        public void Execute(string name, DifficultyLevelScale scale, DifficultyLevel level)
        {
            Name = name;
            DifficultyLevel = level;


            NameAndLevelInputView view = AppContext.Container.Resolve<NameAndLevelInputView>();
            INameAndLevelInputViewModel vm = AppContext.Container.Resolve<INameAndLevelInputViewModel>();
            view.DataContext = vm;

            vm.RequestCloseAfterCancel += delegate { view.Close(); };
            vm.RequestCloseAfterOk += delegate
            {
                view.Close();
                Name = vm.Name;
                DifficultyLevel = vm.SelectedDifficultyLevel;
            };

            vm.LoadData();

            vm.PresetValues(name, scale, level);

            view.Owner = WindowParentHelper.Instance.GetWindowBySpecificType(typeof(MainView));

            view.ShowDialog();
        }
 /// <summary>
 ///     Liefert ob ein Schwierigkeitsgrad aktuell verwendet wird
 /// </summary>
 /// <param name="difficultyLevel"></param>
 /// <returns></returns>
 public bool IsInUse(DifficultyLevel difficultyLevel)
 {
     long usages = GraphClient.Cypher.Match("".DifficultyLevel("dl").AnyInboundRelationsAs("usage").Variation())
         .Where((DifficultyLevel dl)=>dl.Id == difficultyLevel.Id)
         .Return(usage => usage.Count())
         .Results.First();
     return usages >0;
 }
 /// <summary>
 ///     Löscht den Schwierigkeitsgrad, wenn dieser nicht mehr verwendet wird
 /// </summary>
 /// <param name="difficultyLevel"></param>
 public void Delete(DifficultyLevel difficultyLevel)
 {
     if (IsInUse(difficultyLevel))
     {
         throw new NodeInUseException();
     }
     GraphClient.Cypher.Match("".DifficultyLevel("dl").AnyInboundRelationsAs("usage").DifficultyLevelScale()).Where((DifficultyLevel dl)=>dl.Id == difficultyLevel.Id).Delete("dl, usage").ExecuteWithoutResults();
 }
 /// <summary>
 ///     Löscht den Schwierigkeitsgrad, wenn dieser nicht verwendet wird.
 /// </summary>
 /// <param name="difficultyLevel"></param>
 public void Delete(DifficultyLevel difficultyLevel)
 {
     if (_difficultyLevelDao.IsInUse(difficultyLevel))
     {
         throw new NodeInUseException();
     }
     _difficultyLevelDao.Delete(difficultyLevel);
 }
        /// <summary>
        ///     Erstellt einen neuen Schwierigkeitsgrad in einer Skala
        /// </summary>
        public DifficultyLevel Create(DifficultyLevelScale difficultyLevelScale, DifficultyLevel difficultyLevel)
        {
            ICypherFluentQuery query = GraphClient.Cypher
                .Match("".DifficultyLevelScale("dls"))
                .Where((DifficultyLevelScale dls) => dls.Id == difficultyLevelScale.Id)
                .Create("dls".Has().DifficultyLevelWithParam())
                .WithParam("difficultyLevel", difficultyLevel);

            return query.Return(dl=>dl.As<DifficultyLevel>()).Results.First();
        }
        /// <summary>
        ///     Erstellt eine neue Variation einer Route zu einer bestimmen Schwierigkeit
        /// </summary>
        public Variation Create(Variation variation, Route route, DifficultyLevel difficultyLevel)
        {
            var query = GraphClient.Cypher
                .Match("(r:Route),(dl:DifficultyLevel)")
                .Where((Route r, DifficultyLevel dl) => r.Id == route.Id && dl.Id == difficultyLevel.Id)
                .Create("".Node("r").Has().VariationWithParam().Has().Node("dl"))
                .WithParam("variation", variation);

            return query.Return(v => v.As<Variation>()).Results.First();
        }
        public void TestIsInUseNormal()
        {
            Mock<IDifficultyLevelDao> difficultyLevelDaoMock = new Mock<IDifficultyLevelDao>();
            difficultyLevelDaoMock.Setup(x => x.IsInUse(It.IsAny<DifficultyLevel>())).Returns(true);

            DifficultyLevel difficultyLevel = new DifficultyLevel();
            IDifficultyLevelService difficultyLevelService = new DifficultyLevelService(difficultyLevelDaoMock.Object);
            bool isInUse = difficultyLevelService.IsInUse(difficultyLevel);

            difficultyLevelDaoMock.Verify(x=>x.IsInUse(difficultyLevel), Times.Once);
            Assert.IsTrue(isInUse);
        }
        public void TestChangeDifficultyLevel()
        {
            Mock<IVariationDao> variationDaoMock = new Mock<IVariationDao>();
            variationDaoMock.Setup(x => x.ChangeDifficultyLevel(It.IsAny<Variation>(), It.IsAny<DifficultyLevel>()));

            Variation variation = new Variation();
            DifficultyLevel newLevel = new DifficultyLevel();

            IVariationService variationService = new VariationService(variationDaoMock.Object);
            variationService.ChangeDifficultyLevel(variation, newLevel);

            variationDaoMock.Verify(x => x.ChangeDifficultyLevel(variation, newLevel), Times.Once);
        }
        public void TestCreateMissingName(string name, bool useRoute, bool useLevel)
        {
            Route route = null;
            if (useRoute)
            {
                route = new Route();
            }
            DifficultyLevel level = null;
            if (useLevel)
            {
                level = new DifficultyLevel();
            }

            Mock<IVariationDao> variationDaoMock = new Mock<IVariationDao>();

            new VariationService(variationDaoMock.Object).Create(route, level, name);            
        }
        public void TestChangeDifficultyLevelWithNull(bool variationExists, bool levelExists)
        {
            Variation variation = null;
            DifficultyLevel level = null;

            if (variationExists)
            {
                variation = new Variation();
            }

            if (levelExists)
            {
                level = new DifficultyLevel();
            }

            Action action = () => new VariationService(null).ChangeDifficultyLevel(variation, level);
            action.ShouldThrow<ArgumentNullException>();
        }
        public void TestDelete(bool isInUse)
        {
            Mock<IDifficultyLevelDao> difficultyLevelDaoMock = new Mock<IDifficultyLevelDao>();
            difficultyLevelDaoMock.Setup(x => x.IsInUse(It.IsAny<DifficultyLevel>())).Returns(isInUse);
            difficultyLevelDaoMock.Setup(x => x.Delete(It.IsAny<DifficultyLevel>()));

            DifficultyLevel difficultyLevel = new DifficultyLevel();
            IDifficultyLevelService difficultyLevelService = new DifficultyLevelService(difficultyLevelDaoMock.Object);
            difficultyLevelService.Delete(difficultyLevel);

            difficultyLevelDaoMock.Verify(x=>x.IsInUse(difficultyLevel), Times.Once);
            difficultyLevelDaoMock.Verify(x=>x.Delete(difficultyLevel), Times.Once);
        }
 /// <summary>
 ///     Ändert den Schwierigkeitsgrad einer Variation
 /// </summary>
 /// <param name="variation"></param>
 /// <param name="newLevel"></param>
 public void ChangeDifficultyLevel(Variation variation, DifficultyLevel newLevel)
 {
     if (variation == null) throw new ArgumentNullException(nameof(variation));
     if (newLevel == null) throw new ArgumentNullException(nameof(newLevel));
     _variationDao.ChangeDifficultyLevel(variation, newLevel);
 }
        public void TestGetForVariation()
        {
            DifficultyLevel level = new DifficultyLevel();
            Mock<IDifficultyLevelDao> difficultyLevelDaoMock = new Mock<IDifficultyLevelDao>();
            difficultyLevelDaoMock.Setup(x => x.GetLevelOnVariation(It.IsAny<Variation>())).Returns(level);

            Variation variation = new Variation();

            IDifficultyLevelService difficultyLevelService = new DifficultyLevelService(difficultyLevelDaoMock.Object);
            DifficultyLevel levelForVariation = difficultyLevelService.GetForVariation(variation);

            levelForVariation.Should().NotBeNull();
            levelForVariation.Id.Should().Be(level.Id);

            difficultyLevelDaoMock.Verify(x=>x.GetLevelOnVariation(variation), Times.Once);

        }
        public void TestGetForLevel()
        {
            DifficultyLevelScale scaleToReturn = new DifficultyLevelScale();
            Mock<IDifficultyLevelScaleDao> difficultyLevelScaleDaoMock = new Mock<IDifficultyLevelScaleDao>();
            difficultyLevelScaleDaoMock.Setup(x => x.GetForDifficultyLevel(It.IsAny<DifficultyLevel>()))
                .Returns(scaleToReturn);

            DifficultyLevel levelToGetScaleFor = new DifficultyLevel();

            DifficultyLevelScale scale = new DifficultyLevelScaleService(difficultyLevelScaleDaoMock.Object).GetForDifficultyLevel(levelToGetScaleFor);

            scale.Should().Be(scaleToReturn);
            difficultyLevelScaleDaoMock.Verify(x=>x.GetForDifficultyLevel(levelToGetScaleFor), Times.Once);
        }
 /// <summary>
 ///     Liefert die Skale eines Schwierigkeitsgrades
 /// </summary>
 /// <param name="difficultyLevel"></param>
 /// <returns></returns>
 public DifficultyLevelScale GetForDifficultyLevel(DifficultyLevel difficultyLevel)
 {
     return GraphClient.Cypher.Match("".DifficultyLevelScale("dls").Has().DifficultyLevel("dl"))
         .Where((DifficultyLevel dl) => dl.Id == difficultyLevel.Id)
         .Return(dls => dls.As<DifficultyLevelScale>()).Results.FirstOrDefault();
 }
 public Variation CreateVariation(DifficultyLevel difficultyLevel = null,Route route = null, string name = "Variation")
 {
     if (difficultyLevel == null)
     {
         difficultyLevel = CreateDifficultyLevel();
     }
     if (route == null)
     {
         route = CreateRouteInCountry();
     }
     return new VariationDao(_graphClient).Create(new Variation() {Name = name}, route, difficultyLevel);
 }
        /// <summary>
        ///     Ändert den Schwierigkeitsgrad der Variation
        /// </summary>
        /// <param name="variation"></param>
        /// <param name="newLevel"></param>
        public void ChangeDifficultyLevel(Variation variation, DifficultyLevel newLevel)
        {
            GraphClient.Cypher.Match("".Variation("v").Has("dlc").DifficultyLevel())
                .Where((Variation v)=>v.Id == variation.Id)
                .Delete("dlc")
                .ExecuteWithoutResults();

            GraphClient.Cypher
                .Match("(v:Variation),(dl:DifficultyLevel)")
                .Where((Variation v, DifficultyLevel dl) => v.Id == variation.Id && dl.Id == newLevel.Id)
                .Create("".Node("v").Has().Node("dl"))
                .ExecuteWithoutResults();
        }
 /// <summary>
 ///     Liefert ob der Schwierigkeitsgrad verwendet wird
 /// </summary>
 /// <param name="difficultyLevel"></param>
 /// <returns></returns>
 public bool IsInUse(DifficultyLevel difficultyLevel)
 {
     return _difficultyLevelDao.IsInUse(difficultyLevel);
 }
 /// <summary>
 ///     Setzt vorbestimmte Werte
 /// </summary>
 /// <param name="name"></param>
 /// <param name="scale"></param>
 /// <param name="level"></param>
 public void PresetValues(string name, DifficultyLevelScale scale, DifficultyLevel level)
 {
     Name = name;
     if (DifficultyLevelScales.Any())
     {
         SelectedDifficultyLevelScale = DifficultyLevelScales.FirstOrDefault(x => x.Id == scale.Id);
     }
     if (SelectedDifficultyLevelScale != null)
     {
         SelectedDifficultyLevel = DifficultyLevels.FirstOrDefault(x => x.Id == level.Id);
     }
 }
 /// <summary>
 ///     Erstellt eine neue Variation einer Route mit einem Schwierigkeitsgrad
 /// </summary>
 /// <param name="route"></param>
 /// <param name="difficultyLevel"></param>
 /// <param name="variationName"></param>
 public void Create(Route route, DifficultyLevel difficultyLevel, string variationName)
 {
     if (route == null) throw new ArgumentNullException(nameof(route));
     if (difficultyLevel == null) throw new ArgumentNullException(nameof(difficultyLevel));
     _variationDao.Create(new Variation() {Name = variationName}, route, difficultyLevel);
 }
        public void TestCreate()
        {
            Mock<IVariationDao> variationDaoMock = new Mock<IVariationDao>();
            variationDaoMock.Setup(x => x.Create(It.IsAny<Variation>(), It.IsAny<Route>(), It.IsAny<DifficultyLevel>()));

            Route fakeRoute = new Route();
            DifficultyLevel fakeLevel = new DifficultyLevel();

            IVariationService variationService = new VariationService(variationDaoMock.Object);
            variationService.Create(fakeRoute, fakeLevel, "Variation 1");

            variationDaoMock.Verify(
                x => x.Create(It.Is<Variation>(y => y.Name == "Variation 1"), fakeRoute, fakeLevel), Times.Once);
        }
        public void TestSave()
        {
            Mock<IDifficultyLevelDao> difficultyLevelDaoMock = new Mock<IDifficultyLevelDao>();
            difficultyLevelDaoMock.Setup(x => x.Save(It.IsAny<DifficultyLevel>()));

            DifficultyLevel level = new DifficultyLevel();
            new DifficultyLevelService(difficultyLevelDaoMock.Object).Save(level);

            difficultyLevelDaoMock.Verify(x=>x.Save(level), Times.Once);
        }
 /// <summary>
 ///     Liefert die Sakale zu einer Skala
 /// </summary>
 /// <param name="difficultyLevel"></param>
 /// <returns></returns>
 public DifficultyLevelScale GetForDifficultyLevel(DifficultyLevel difficultyLevel)
 {
     if (difficultyLevel == null) throw new ArgumentNullException(nameof(difficultyLevel));
     return _difficultyLevelScaleDao.GetForDifficultyLevel(difficultyLevel);
 }
 /// <summary>
 ///     Speichert den Schwierigkeitsgrad
 /// </summary>
 /// <param name="difficultyLevel"></param>
 public void Save(DifficultyLevel difficultyLevel)
 {
     GraphClient.Cypher.Match("".DifficultyLevel("dl")).Where((DifficultyLevel dl)=>dl.Id == difficultyLevel.Id)
         .Set("dl.Name={Name}, dl.Score={Score}").WithParams(new Dictionary<string, object> { {"Name", difficultyLevel.Name}, {"Score", difficultyLevel.Score} })
         .ExecuteWithoutResults();
 }
 /// <summary>
 ///     Setzt vorbestimmte Werte
 /// </summary>
 /// <param name="name"></param>
 /// <param name="scale"></param>
 /// <param name="level"></param>
 public void PresetValues(string name, DifficultyLevelScale scale, DifficultyLevel level)
 {
     throw new System.NotImplementedException();
 }
 /// <summary>
 ///     Speichert den Schwierigkeitsgrad
 /// </summary>
 /// <param name="difficultyLevel"></param>
 public void Save(DifficultyLevel difficultyLevel)
 {
     if (difficultyLevel == null) throw new ArgumentNullException(nameof(difficultyLevel));
     _difficultyLevelDao.Save(difficultyLevel);
 }