public bool AddFact([NotNull] Fact fact)
        {
            bool result = false;

            var schema       = GetSchema();
            var propertyType = schema?.GetPropertyType("Facts");

            if (propertyType != null)
            {
                var property = _model.GetProperty(propertyType) ?? _model.AddProperty(propertyType, null);
                if (property is IPropertyJsonSerializableObject jsonSerializableObject)
                {
                    if (jsonSerializableObject.Value is FactContainer container)
                    {
                        result = container.Add(fact);
                    }
                    else
                    {
                        container = new FactContainer();
                        result    = container.Add(fact);
                        jsonSerializableObject.Value = container;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        TextAsset questionData = Resources.Load <TextAsset>("Quiz/questions");
        TextAsset factsData    = Resources.Load <TextAsset>("Quiz/facts");

        questions = JsonUtility.FromJson <QuestionContainer>(questionData.text);
        facts     = JsonUtility.FromJson <FactContainer>(factsData.text);

        factsList     = facts.text.ToArray();
        questionsList = questions.Questions.ToList();
        Array.Resize(ref aquiredFacts, factsList.Length);
        for (int i = 0; i < factsList.Length; ++i)
        {
            factsLeft.Add(i);
        }
        //Debug.Log(questionsList.Count);
    }
Ejemplo n.º 3
0
        public async Task CalculatingCostBuyingMovie_WithAsyncRule()
        {
            // We have information about the user's mail and the identifier of the film, what he wants to buy.
            string email   = "*****@*****.**";
            int    movieId = 1;

            // Let's tell the factory what we know
            var container = new FactContainer
            {
                new UserEmailFact(email),
                new MovieIdFact(movieId),
            };

            // We ask the factory to calculate the cost of buying a movie for our user.
            var price = await Factory.DeriveFactAsync <MoviePurchasePriceFactAsync>(container);

            // For this user, the discount for this movie is not configured. Therefore we expect full value.
            Assert.AreEqual(MovieDB.Single(m => m.Id == movieId).Cost, price, "We expected a different purchase price.");
        }
Ejemplo n.º 4
0
        public void CalculatingCostBuyingMovie_1()
        {
            // We have information about the user's mail and the identifier of the film, what he wants to buy.
            string email   = "*****@*****.**";
            int    movieId = 1;

            // Let's tell the factory what we know
            var container = new FactContainer
            {
                new UserEmailFact(email),
                new MovieIdFact(movieId),
            };

            // We ask the factory to calculate the cost of buying a movie for our user.
            int price = Factory.DeriveFact <MoviePurchasePriceFact>(container).Value;

            // If we look at the database, we will see that for this user the discount on the purchase of this film is 5. The movie itself costs 11.
            Assert.AreEqual(6, price, "We expected a different purchase price.");
        }
Ejemplo n.º 5
0
        public void CalculatingCostBuyingMovie_2()
        {
            // We have information about the user's mail and the identifier of the film, what he wants to buy.
            string email   = "*****@*****.**";
            int    movieId = 1;

            // Let's tell the factory what we know
            var container = new FactContainer
            {
                new UserEmailFact(email),
                new MovieIdFact(movieId),
            };

            // We ask the factory to calculate the cost of buying a movie for our user.
            int price = Factory.DeriveFact <MoviePurchasePriceFact>(container).Value;

            // For this user, the discount for this movie is not configured. Therefore we expect full value.
            Assert.AreEqual(0, price, "Everything should be free for John.");
        }
Ejemplo n.º 6
0
        public void CalculatingCostBuyingMovie_3()
        {
            // We have information about the user's mail and the identifier of the film, what he wants to buy.
            string email   = "*****@*****.**";
            int    movieId = 1;

            // Let's tell the factory what we know
            var container = new FactContainer
            {
                new UserEmailFact(email),
                new MovieIdFact(movieId),
            };

            // We ask the factory to calculate the cost of buying a movie for our user.
            int price = Factory.DeriveFact <MoviePurchasePriceFact, Version2020>(container).Value;

            // Calculate the cost of the movie "My Hero's Academy: Rise of the Heroes" for the user "Judy Gonzalez" according to the new rule.
            Assert.AreEqual(MovieDB.First(movie => movie.Id == movieId).Cost, price, "We expected a different purchase price.");
        }
Ejemplo n.º 7
0
 public SatisfactionEvaluator(FactSourceContainer factSourceContainer)
 {
     mFactSourceContainer = factSourceContainer;
     mFactContainer       = new FactContainer();
 }
Ejemplo n.º 8
0
 internal abstract void GatherFacts(FactContainer container);
Ejemplo n.º 9
0
 internal abstract EvaluationContext StartEvaluation(FactContainer container);
Ejemplo n.º 10
0
 internal override void GatherFacts(FactContainer container)
 {
     // ComposedConditions don't need to gather facts...
 }
Ejemplo n.º 11
0
 internal override EvaluationContext StartEvaluation(FactContainer container)
 {
     return(new EvaluationContext(
                this,
                mChildrenConditions.Select(c => c.StartEvaluation(container))));
 }