Beispiel #1
0
        public void Attack(Attack attack)
        {
            if (State == States.PlayerTurn)
            {
                Monster.DecreaseHealth(attack.GetDamage());

                if (Monster.GetHealth() <= 0)
                {
                    Outcome = Outcomes.PlayerWon;
                    State = States.EndBattle;
                }

                State = States.EnemyTurn;
            }
            else if (State == States.EnemyTurn)
            {
                ActivePlayerMonster.DecreaseHealth(attack.GetDamage());

                if (ActivePlayerMonster.GetHealth() <= 0)
                {
                    Outcome = Outcomes.EnemyWon;
                    State = States.EndBattle;
                }

                State = States.PlayerTurn;
            }
        }
Beispiel #2
0
        public void Failure_Keys_WithKey_Works()
        {
            var outcome = Outcomes.Failure()
                          .WithKey("test1", "value1")
                          .WithKey("test2", "value2");

            Assert.True(outcome.Keys["test1"].ToString() == "value1");
            Assert.True(outcome.Keys["test2"].ToString() == "value2");
        }
        public IOutcome Accept(NewPaymentCommand payment)
        {
            if (Math.Floor(Math.Log10(payment.CreditCard.CVV) + 1) == 3)
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"Credit card CVV is invalid."));
        }
Beispiel #4
0
        public void Failure_OfT_Messages_Not_Null_By_Default()
        {
            IOutcome <int> outcome = Outcomes.Failure <int>();

            Assert.IsFalse(outcome.Success);
            Assert.IsNotNull(outcome.Messages);
            Assert.IsTrue(outcome.Value == 0);
            Assert.IsTrue(outcome.ToString() == string.Empty);
        }
        public IOutcome Accept(PaymentCommand payment)
        {
            if (payment.Amount.Value > 0)
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"The payment amount must be greater than 0."));
        }
        private void Clear()
        {
            Date = DateTime.Today;

            SelectedMode               = Modes.OrderBy(x => x.Rank).FirstOrDefault();
            SelectedOutcome            = Outcomes.OrderBy(x => x.Rank).FirstOrDefault();
            SelectedReasonNotContacted = ReasonsNotContacted.OrderBy(x => x.Rank).FirstOrDefault();
            ReasonNotContactedOther    = string.Empty;
        }
Beispiel #7
0
        public IOutcome Accept(NewPaymentCommand payment)
        {
            if (payment.CreditCard.Number.Length == 16)
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"Credit card number is invalid {payment.CreditCard.Number}. It must have 16 characters"));
        }
Beispiel #8
0
        public void Success_Messages_OfT_Not_Null_By_Default()
        {
            IOutcome <int> outcome = Outcomes.Success <int>();

            Assert.True(outcome.Success);
            Assert.NotNull(outcome.Messages);
            Assert.True(outcome.Value == 0);
            Assert.True(outcome.ToString() == string.Empty);
        }
Beispiel #9
0
        public void Success_Keys_WithKey_Works()
        {
            var outcome = Outcomes.Success(23123.32M)
                          .WithKey("test1", "value1")
                          .WithKey("test2", "value2");

            Assert.True((string)outcome.Keys["test1"] == "value1");
            Assert.True((string)outcome.Keys["test2"] == "value2");
        }
Beispiel #10
0
        internal void Merge(MarketDescriptionDTO dto, CultureInfo culture)
        {
            Contract.Requires(dto != null);
            Contract.Requires(culture != null);

            lock (_lock)
            {
                _names[culture] = dto.Name;
                if (!string.IsNullOrEmpty(dto.Description))
                {
                    _descriptions[culture] = dto.Description;
                }
                Variant = dto.Variant;

                if (dto.Outcomes != null)
                {
                    foreach (var outcomeDto in dto.Outcomes)
                    {
                        var existingOutcome = Outcomes?.FirstOrDefault(o => o.Id == outcomeDto.Id);
                        if (existingOutcome != null)
                        {
                            existingOutcome.Merge(outcomeDto, culture);
                        }
                        else
                        {
                            ExecutionLog.Warn($"Could not merge outcome[Id={outcomeDto.Id}] for lang={culture.TwoLetterISOLanguageName} on marketDescription[Id={Id}] because the specified outcome does not exist on stored market description.");
                            ComparePrint(dto, culture);
                        }
                    }
                }

                if (dto.Mappings != null)
                {
                    foreach (var mappingDto in dto.Mappings)
                    {
                        var existingMapping = Mappings?.FirstOrDefault(m => MarketMappingsMatch(m, mappingDto));
                        if (existingMapping != null)
                        {
                            existingMapping.Merge(mappingDto, culture);
                        }
                        else
                        {
                            ExecutionLog.Warn($"Could not merge mapping[MarketId={mappingDto.MarketTypeId}:{mappingDto.MarketSubTypeId}] for lang={culture.TwoLetterISOLanguageName} on marketDescription[Id={dto.Id}]because the specified mapping does not exist on stored market description.");
                            ComparePrint(dto, culture);
                        }
                    }
                }

                OutcomeType = dto.OutcomeType;

                Groups = dto.Groups == null ? null : new ReadOnlyCollection <string>(dto.Groups.ToList());

                FetchedLanguages.Add(culture);

                LastDataReceived = DateTime.Now;
            }
        }
Beispiel #11
0
        public Program(string id, string name, TimeSpan duration, bool isCOOP, Outcomes outcome) : base(id)
        {
            Name     = name;
            Duration = duration;
            IsCOOP   = isCOOP;
            Outcome  = outcome;

            Reconnect();
        }
Beispiel #12
0
        public void Success_Messages_Prepend_With_Empty_Message_Collection()
        {
            IOutcome outcome = Outcomes.Success()
                               .PrependMessage("This should not throw an error.");

            Assert.True(outcome.Success);
            Assert.True(outcome.Messages.Count == 1);
            Assert.True(outcome.Messages[0] == "This should not throw an error.");
        }
        public void RockAlwaysTiesRock()
        {
            IPlayer playerOne = new RockPlayer();
            IPlayer playerTwo = new RockPlayer();

            GameFlow game   = new GameFlow(playerOne, playerTwo);
            Outcomes result = game.GetGameOutcome();

            Assert.AreEqual(Outcomes.Draw, result);
        }
        public void RockAlwaysBeatsScissors()
        {
            IPlayer playerOne = new RockPlayer();
            IPlayer playerTwo = new ScissorsPlayer();

            GameFlow game   = new GameFlow(playerOne, playerTwo);
            Outcomes result = game.GetGameOutcome();

            Assert.AreEqual(Outcomes.PlayerOneWin, result);
        }
        public void ScissorsAlwaysTiesScissors()
        {
            IPlayer playerOne = new ScissorsPlayer();
            IPlayer playerTwo = new ScissorsPlayer();

            GameFlow game   = new GameFlow(playerOne, playerTwo);
            Outcomes result = game.GetGameOutcome();

            Assert.AreEqual(Outcomes.Draw, result);
        }
Beispiel #16
0
        public void Success_WithValue_Works_Even_If_Generic_Not_Specified()
        {
            var outcome = Outcomes.Success(23123.32M);

            Assert.IsTrue(outcome.Success);
            Assert.IsTrue(outcome.Messages.Count == 0);
            Assert.IsTrue(outcome.Value == 23123.32M);
            Assert.IsTrue(outcome.ToString() == string.Empty);
            Assert.IsTrue(outcome.ToMultiLine("<br>") == string.Empty);
        }
Beispiel #17
0
        public void Success_WithValue_Works()
        {
            var outcome = Outcomes.Success <Decimal>(23123.32M);

            Assert.IsTrue(outcome.Success);
            Assert.IsTrue(outcome.Messages.Count == 0);
            Assert.IsTrue(outcome.Value == 23123.32M);
            Assert.IsTrue(outcome.ToString() == string.Empty);
            Assert.IsTrue(outcome.ToMultiLine("<br>") == string.Empty);
        }
        public void Failure_FromException_Works()
        {
            var exception = new InvalidOperationException("test message");

            var outcome = Outcomes.Failure().FromException(exception);

            Assert.False(outcome.Success);
            Assert.True(outcome.Messages.Count == 1);
            Assert.True(outcome.ToMultiLine("<br>") == "System.InvalidOperationException: test message<br>");
        }
        // Loads all eligible outcome selections based on the selected Protocol.
        public void loadOutcomes()
        {
            List <ProtocolOutcome> protocolOutcomes;

            foreach (Protocol protocol in Protocols)
            {
                protocolOutcomes = database.getProtocolOutcome(SelectedProtocol);
                protocolOutcomes.ForEach(po => Outcomes.Add(po.Outcome));
            }
        }
        public void PaperAlwaysBeatsRock()
        {
            IPlayer playerOne = new RockPlayer();
            IPlayer playerTwo = new PaperPlayer();

            GameFlow game   = new GameFlow(playerOne, playerTwo);
            Outcomes result = game.GetGameOutcome();

            Assert.AreEqual(Outcomes.PlayerTwoWin, result);
        }
Beispiel #21
0
 private void LoadTest()
 {
     if (null != TestResult)
     {
         Id              = TestResult.Id;
         Date            = TestResult.Date;
         SelectedMode    = Modes.FirstOrDefault(x => x.ItemId == TestResult.Mode);
         SelectedOutcome = Outcomes.FirstOrDefault(x => x.ItemId == TestResult.Outcome);
     }
 }
 public ProgramViewModel(ICourseInfoRepository courseRepository)
 {
     this.courseRepository = courseRepository ?? throw new ArgumentNullException(nameof(courseRepository));
     refreshCourses();
     SelectedOutcome = Outcomes.FirstOrDefault();
     FilterText      = string.Empty;
     MessengerInstance.Register <RefreshDatabaseMessage>(this, (m) => refreshCourses());
     SaveButtonContent = defaultSaveButtonContent;
     CanSave           = true;
     IsDirty           = false;
 }
Beispiel #23
0
 public Task <IOutcome> NotifyAsync(EmailMessage message)
 {
     try
     {
         return(SendOverMultipleSmtpServersAsync(message));
     }
     catch (Exception ex)
     {
         return(Task.FromResult((IOutcome)Outcomes.Failure().WithMessage(ex.Message)));
     }
 }
Beispiel #24
0
        public IOutcome Accept(PaymentCommand payment)
        {
            var merchantExists = FindMerchantByID(payment.MerchantID).GetAwaiter();

            if (merchantExists.GetResult())
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"Merchant not found to process the payment."));
        }
Beispiel #25
0
        public void Success_WithValue_And_Message_Works()
        {
            var outcome = Outcomes.Success <string>()
                          .WithValue("9An@nsd!d")
                          .WithMessage("Encrypted value retrieved in 5s!");

            Assert.IsTrue(outcome.Success);
            Assert.IsTrue(outcome.Value == "9An@nsd!d");
            Assert.IsTrue(outcome.Messages.Count == 1);
            Assert.IsTrue(outcome.ToMultiLine() == "Encrypted value retrieved in 5s!");
        }
Beispiel #26
0
        /// <summary>
        /// Creates a new <see cref="TimeFrame"/> instance with the given times.
        /// </summary>
        /// <param name="earliestTime">The earliest time for delivery.</param>
        /// <param name="latestTime">The latest time for delivery.</param>
        /// <returns>An <see cref="Outcome"/> indicating the outcome of the create method.</returns>
        public static Outcome <TimeFrame> Create(DateTime earliestTime, DateTime latestTime)
        {
            var error = Exceptions.WhenOutOfRange(latestTime, earliestTime, nameof(latestTime));

            if (error == null)
            {
                return(Outcomes.Success(new TimeFrame(earliestTime, latestTime)));
            }

            return(Outcomes.Failure <TimeFrame>(error));
        }
Beispiel #27
0
        private void Clear()
        {
            BookingDate = Date = DateTime.Today;

            SelectedMode    = Modes.OrderBy(x => x.Rank).FirstOrDefault();
            SelectedOutcome = Outcomes.OrderBy(x => x.Rank).FirstOrDefault();
            if (null != Consents)
            {
                SelectedConsent = Consents.OrderBy(x => x.Rank).FirstOrDefault();
            }
        }
        public IOutcome Accept(PaymentCommand payment)
        {
            var shopperExists = FindShopperByID(payment.ShopperID).GetAwaiter();

            if (shopperExists.GetResult())
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"Shopper not found to process the payment."));
        }
Beispiel #29
0
        /// <summary>
        /// Creates a new <see cref="Email"/> instance with a specified <paramref name="value"/>.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>An <see cref="Outcome"/> indicating the outcome of the create method.</returns>
        public static Outcome <Email> Create(string value)
        {
            var error = ValidateValue(value);

            if (error == null)
            {
                return(Outcomes.Success(new Email(value)));
            }

            return(Outcomes.Failure <Email>(error));
        }
        public void Failure_FromException_Chaining_Works()
        {
            var exception = new InvalidOperationException("test");

            var outcome = Outcomes.Failure().WithMessage("prefix")
                          .FromException(exception)
                          .WithMessage("suffix");

            Assert.False(outcome.Success);
            Assert.True(outcome.Messages.Count == 3);
            Assert.True(outcome.ToMultiLine("<br>") == "prefix<br>System.InvalidOperationException: test<br>suffix<br>");
        }
        public void Failure_WithKeysFrom_Works()
        {
            var outcome1 = Outcomes.Failure()
                           .WithKey("test", 35);

            var outcome2 = Outcomes.Failure().WithKeysFrom(outcome1);
            var outcome3 = Outcomes.Failure().FromOutcome(outcome1);

            Assert.True(outcome1.Keys["test"].Equals(35));
            Assert.True(outcome2.Keys["test"].Equals(35));
            Assert.True(outcome3.Keys["test"].Equals(35));
        }