Пример #1
0
 private void SetupActionWithFailedConstraintsAndTriggerWithException(string failMessage)
 {
     var levelConstraint = new LevelBasedConstraint { ValueToCompare = 2 };
     levelConstraint.BooleanOperation = BooleanOperations.GreaterOrEquals;
     levelConstraint.Description = failMessage;
     var pointsConstraint = new PointsBasedConstraint { ValueToCompare = 102 };
     pointsConstraint.BooleanOperation = BooleanOperations.GreaterThan;
     this.gameAction.QtyBasedConstraints.Add(levelConstraint);
     this.gameAction.QtyBasedConstraints.Add(pointsConstraint);
     var trigger = new Mock<ActionTrigger>();
     trigger.Protected().Setup("RaiseTriggerAction", ItExpr.IsAny<Gamer>())
         .Callback((Gamer g) => { throw new InvalidOperationException("Trigger is fired"); });
     this.gameAction.TriggersToCall.Add(trigger.Object);
 }
Пример #2
0
        public void ShouldSaveEnumValuesToDb()
        {
            var levelBasedConstraint = new LevelBasedConstraint();
            levelBasedConstraint.BooleanOperation = BooleanOperations.Equals;
            this.qtyBasedConstraintsRepository.AddPhysically(levelBasedConstraint);

            var pointsBasedConstraint = new PointsBasedConstraint();
            pointsBasedConstraint.BooleanOperation = BooleanOperations.GreaterOrEquals;
            this.qtyBasedConstraintsRepository.AddPhysically(pointsBasedConstraint);

            this.qtyBasedConstraintsRepository.ClearContext();
            var constraints = this.qtyBasedConstraintsRepository.ToList();

            var levelBsdFromDb = (LevelBasedConstraint)constraints.FirstOrDefault(x => x.Id == levelBasedConstraint.Id);
            var pointsBsdFromDb = (PointsBasedConstraint)constraints.FirstOrDefault(x => x.Id == pointsBasedConstraint.Id);
            levelBsdFromDb.BooleanOperation.Should().Be.EqualTo(BooleanOperations.Equals);
            pointsBsdFromDb.BooleanOperation.Should().Be.EqualTo(BooleanOperations.GreaterOrEquals);
        }
Пример #3
0
        public void WhenSaveDifferentTypesOfQtyBasedConstraints_ShouldGetFromDatabaseRightType()
        {
            var levelBasedConstraint = new LevelBasedConstraint();
            levelBasedConstraint.ValueToCompare = 10;
            levelBasedConstraint.Description = "needed level when user get 'God' status";
            this.qtyBasedConstraintsRepository.AddPhysically(levelBasedConstraint);

            var pointsBasedConstraint = new PointsBasedConstraint();
            pointsBasedConstraint.ValueToCompare = 2000;
            pointsBasedConstraint.Description = "needed points when user get 10 level";
            this.qtyBasedConstraintsRepository.AddPhysically(pointsBasedConstraint);

            Assert.That(levelBasedConstraint.Id, Is.GreaterThan(0));
            Assert.That(pointsBasedConstraint.Id, Is.GreaterThan(0));

            this.qtyBasedConstraintsRepository.ClearContext();
            var constraints = this.qtyBasedConstraintsRepository.ToList();

            var levelBsdFromDb = (LevelBasedConstraint)constraints.FirstOrDefault(x => x.Id == levelBasedConstraint.Id);
            var pointsBsdFromDb = (PointsBasedConstraint)constraints.FirstOrDefault(x => x.Id == pointsBasedConstraint.Id);
            levelBsdFromDb.Should().Be.EqualTo(levelBasedConstraint);
            pointsBsdFromDb.Should().Be.EqualTo(pointsBasedConstraint);
        }