示例#1
0
        public void Success_Messages_Not_Null_By_Default()
        {
            IOutcome outcome = Outcomes.Success();

            Assert.True(outcome.Success);
            Assert.NotNull(outcome.Messages);
            Assert.True(outcome.ToString() == string.Empty);
        }
示例#2
0
        private async Task <IOutcome> SendOverMultipleSmtpServersAsync(EmailMessage message)
        {
            var errors = new List <string>();
            var smtpServerConfigurations = _mailSettingsConfig.Smtp.Servers;
            var wasSentSuccessfully      = false;

            foreach (var smtpServerConfiguration in smtpServerConfigurations)
            {
                try
                {
                    if (wasSentSuccessfully)
                    {
                        continue;
                    }

                    var createRequest = new MailMessageCreateRequest()
                    {
                        EmailMessage           = message,
                        SmtpServerConfig       = smtpServerConfiguration,
                        IsReadSenderFromConfig = true,
                        RequiredRecipients     = _mailSettingsConfig.Smtp.RequiredRecipients,
                    };
                    var mailMessage = await _mailMessageFactory.CreateAsync(createRequest);

                    using (var smtpClient = _smtpClientFactory.Create(smtpServerConfiguration))
                    {
                        await smtpClient.SendAsync(mailMessage);

                        wasSentSuccessfully = true;
                    }
                }
                catch (Exception ex)
                {
                    wasSentSuccessfully = false;

                    var error = ex.Message;
                    if (ex.InnerException != null)
                    {
                        var innerEx = ex.InnerException;
                        while (innerEx.InnerException != null)
                        {
                            innerEx = innerEx.InnerException;
                        }

                        error = innerEx.Message;
                    }

                    errors.Add($"SMTP {smtpServerConfiguration.Host} throw an error: {error}");
                }
            }

            if (wasSentSuccessfully)
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure().WithMessagesFrom(errors.Distinct()));
        }
        public IOutcome Accept(Payment payment)
        {
            if (Math.Floor(Math.Log10(payment.CreditCardNotMasked.CVV) + 1) == 3)
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"Credit card CVV is invalid."));
        }
        public IOutcome Accept(Payment payment)
        {
            if (payment.CreditCardNotMasked.Number.Length == 16)
            {
                return(Outcomes.Success());
            }

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

            Assert.IsTrue(outcome.Success);
            Assert.IsNotNull(outcome.Messages);
            Assert.IsTrue(outcome.Value == 0);
            Assert.IsTrue(outcome.ToString() == string.Empty);
        }
示例#6
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");
        }
示例#7
0
        public IOutcome Accept(Payment payment)
        {
            if (payment.Amount.Value > 0)
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"The payment amount must be greater than 0."));
        }
示例#8
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 IOutcome Accept(NewPaymentCommand payment)
        {
            if (payment.CreditCard.ExpireDate > DateTime.Now)
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"Credit card invalid, it´s expired since {payment.CreditCard.ExpireDate}."));
        }
示例#10
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);
        }
示例#11
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);
        }
示例#12
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));
        }
示例#13
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 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."));
        }
示例#15
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!");
        }
示例#16
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."));
        }
示例#17
0
        public void Success_WithKeysFrom_Works()
        {
            var outcome1 = Outcomes.Success <int>()
                           .WithKey("test", 35);

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

            Assert.True(outcome1.Keys["test"].Equals(35));
            Assert.True(outcome2.Keys["test"].Equals(35));
            Assert.True(outcome3.Keys["test"].Equals(35));
        }
示例#18
0
        public ActionResult DeleteAllModSets(int id)
        {
            var db = new ZelusDbContext();

            var sets = db.PlayerModSets
                       .Where(m => m.PlayerId == id)
                       .ToList();

            db.PlayerModSets.RemoveRange(sets);
            db.SaveChanges();

            return(Json(Outcomes.Success(), JsonRequestBehavior.AllowGet));
        }
示例#19
0
        public IOutcome Accept(MerchantCommand newEntity)
        {
            var result = this.findMerchantRepository.GetAsync(newEntity.Id).GetAwaiter();

            var merchant = result.GetResult();

            if (merchant is null)
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"Merchant ID is alredy in use!"));
        }
示例#20
0
        public void Failure_Messages_Prepend_Works()
        {
            IOutcome outcome = Outcomes.Success()
                               .WithMessage("Test!");

            var newOutcome = Outcomes.Failure()
                             .FromOutcome(outcome)
                             .PrependMessage("This should be first since it's prepended!");

            Assert.True(newOutcome.Failure);
            Assert.True(newOutcome.Messages.Count == 2);
            Assert.True(newOutcome.Messages[0] == "This should be first since it's prepended!");
            Assert.True(newOutcome.Messages[1] == "Test!");
        }
示例#21
0
        public IOutcome Accept(Merchant newEntity)
        {
            var findMerchantQuery = new FindMerchantQuery(newEntity.Name);

            var task = this.findMerchantQueryHandler.GetAllAsync(findMerchantQuery).GetAwaiter();
            IEnumerable <Merchant> merchant = task.GetResult();

            if (merchant is null || !merchant.Any())
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"Merchant name is alredy in use!"));
        }
示例#22
0
        public IOutcome Accept(Merchant newEntity)
        {
            var findMerchantQuery = new FindMerchantQuery(newEntity.ID);

            var result = this.findMerchantQueryHandler.GetAsync(findMerchantQuery).GetAwaiter();

            var merchant = result.GetResult();

            if (merchant is null)
            {
                return(Outcomes.Success());
            }

            return(Outcomes.Failure <int[]>().WithMessage($"Merchant ID is alredy in use!"));
        }
示例#23
0
        /// <summary>
        /// Creates an <see cref="JobConstraint"/> instance with a specified name and value.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        /// <returns>An <see cref="Outcome"/> indicating the outcome of the create method.</returns>
        public static Outcome <JobConstraint> Create(string name, string value)
        {
            var errors = new[]
            {
                ValidateName(name),
                ValidateValue(value),
            };

            if (!Exceptions.Any(errors))
            {
                return(Outcomes.Success(new JobConstraint(name, value)));
            }

            return(Outcomes.Failure <JobConstraint>(errors));
        }
        /// <summary>
        /// Creates a <see cref="DeliveryEventWebhook"/> with the specified values.
        /// </summary>
        /// <param name="eventName">The name of the event.</param>
        /// <param name="url">The URL to be called when the event occurs.</param>
        /// <returns>An <see cref="Outcome"/> indicating the outcome of the create method.</returns>
        public static Outcome <DeliveryEventWebhook> Create(string eventName, Uri url)
        {
            var errors = new[]
            {
                ValidateEventName(eventName),
                ValidateUrl(url),
            };

            if (!Exceptions.Any(errors))
            {
                return(Outcomes.Success(new DeliveryEventWebhook(eventName, url)));
            }

            return(Outcomes.Failure <DeliveryEventWebhook>(errors));
        }
示例#25
0
        public JsonResult DeleteModSet(int setId)
        {
            if (setId == 0)
            {
                return(Json(Outcomes.Failure().WithMessage("Cannot delete a modset without its id."), JsonRequestBehavior.AllowGet));
            }

            var db  = new ZelusDbContext();
            var set = db.PlayerModSets.Single(s => s.Id == setId);

            db.PlayerModSets.Remove(set);
            db.SaveChanges();

            return(Json(Outcomes.Success(), JsonRequestBehavior.AllowGet));
        }
示例#26
0
        public override IOutcome <StrategyResultViewModel> Plan(Player player, List <PlayerCharacterViewModel> topGuildCharacters)
        {
            var playerTopCharacters = topGuildCharacters.Where(pc => pc.PlayerId == player.Id)
                                      .ToList();

            var model = new StrategyResultViewModel();

            model.IsVisible              = true;
            model.LastSyncHumanized      = player.LastCollectionSync.Humanize();
            model.LastSyncDateTime       = player.LastCollectionSync.ToString("r");
            model.NumberOfDefensiveTeams = playerTopCharacters.Count() / 5;
            model.TopCharacters          = playerTopCharacters;

            return(Outcomes.Success <StrategyResultViewModel>()
                   .WithValue(model));
        }
示例#27
0
        public void Success_Basic_Chaining_Works()
        {
            var messages = new List <string> {
                "test2", "test3"
            };
            var outcome = Outcomes.Success <int>().WithValue(32)
                          .WithStatusCode(401)
                          .WithMessage("test1")
                          .WithMessage(messages);

            Assert.IsTrue(outcome.Success);
            Assert.IsTrue(outcome.Value == 32);
            Assert.IsTrue(outcome.StatusCode == 401);
            Assert.IsTrue(outcome.Messages.Count == 3);
            Assert.IsTrue(outcome.ToString() == "test1test2test3");
            Assert.IsTrue(outcome.ToMultiLine("<br>") == "test1<br>test2<br>test3<br>");
        }
示例#28
0
        private IOutcome <string> DoExecute()
        {
            var unitSync    = new UnitSynchronizer();
            var unitOutcome = unitSync.Execute();

            if (unitOutcome.Failure)
            {
                return(Outcomes.Failure <string>()
                       .WithMessage("The swgoh.gg synchronizer failed while trying to retrieve units.")
                       .WithMessagesFrom(unitOutcome));
            }

            var playerSync    = new PlayerSynchronizer();
            var playerOutcome = playerSync.Execute();

            if (playerOutcome.Failure)
            {
                return(Outcomes.Failure <string>()
                       .WithMessage("The swgoh.gg synchronizer failed while trying to retrieve players.")
                       .WithMessagesFrom(playerOutcome));
            }

            var collectionSync    = new CollectionSynchronizer();
            var collectionOutcome = collectionSync.Execute();

            if (collectionOutcome.Failure)
            {
                return(Outcomes.Failure <string>()
                       .WithMessage("The swgoh.gg synchronizer failed while trying to retrieve collections.")
                       .WithMessagesFrom(collectionOutcome));
            }

            var modSync    = new ModSynchronizer();
            var modOutcome = modSync.Execute();

            if (modOutcome.Failure)
            {
                return(Outcomes.Failure <string>()
                       .WithMessage("The swgoh.gg synchronizer failed while trying to retrieve mods.")
                       .WithMessagesFrom(modOutcome));
            }

            return(Outcomes.Success <string>()
                   .WithMessage("Successfully ran the swgoh.gg synchronizer."));
        }
        public async Task HandleCommand_WithRaiseEvent_Success()
        {
            //ARRANGE
            var mockMerchantValidation = new Mock <ICommandValidation <MerchantCommand> >();

            mockMerchantValidation
            .Setup(p => p.ValidateCommand(It.IsAny <NewMerchantCommand>()))
            .Returns(Outcomes.Success());

            var newMerchantCommand = new NewMerchantCommand(merchantID, "Merchant Test", "Test", currency, country, true, true, mockMerchantValidation.Object);

            var merchantCommandHandler = ReturnMerchantCommandHandlerObject();

            //ACT
            var result = await merchantCommandHandler.Handle(newMerchantCommand, CancellationToken.None);

            //ASSERT
            result.Should().BeTrue();
        }
        /// <summary>
        /// Creates a new <see cref="ExtraAddressDetails"/> instance with a specified values.
        /// </summary>
        /// <param name="stateProvince">The state or province.</param>
        /// <param name="country">The country.</param>
        /// <param name="suburbLocality">The suburb locality.</param>
        /// <param name="postcode">The postcode.</param>
        /// <param name="latitude">The latitude.</param>
        /// <param name="longitude">The longitude.</param>
        /// <returns>An <see cref="Outcome"/> indicating the outcome of the create method.</returns>
        public static Outcome <ExtraAddressDetails> Create(string stateProvince, string country, string suburbLocality, string postcode, decimal latitude, decimal longitude)
        {
            var errors = new[]
            {
                ValidateStateProvince(stateProvince),
                ValidateCountry(country),
                ValidateSuburbLocality(suburbLocality),
                ValidatePostcode(postcode),
            };

            if (!Exceptions.Any(errors))
            {
                return(Outcomes.Success(new ExtraAddressDetails(stateProvince, country, suburbLocality, postcode, latitude, longitude)));
            }

            return(Outcomes
                   .Failure <ExtraAddressDetails>()
                   .WithError(errors));
        }