Esempio n. 1
0
        public R.ResultVm <bool> AddCheckin(string serverName, Checkin checkin)
        {
            var result = new R.ResultVm <bool>().FromEmptyFailure();

            Demand <string> .That(serverName, "serverName").HasNonEmptyValue().HasMaxChars(255).Result(result);

            Demand <double> .That(checkin.RamUtilization, "checkin.RamUtilization").IsGreaterThan(0.0D).Result(result);

            Demand <double> .That(checkin.CpuUtilization, "checkin.CpuUtilization").IsGreaterThan(0.0D).IsLessThanOrEqualTo(1.0D).Result(result);

            //Demand<DateTime>.That(checkin.SampleTime, "checkin.SampleTime").IsAfter(DateTime.Now.AddMinutes(-10.0D)).IsBefore(DateTime.Now.AddMinutes(10.00D)).Result(result);

            if (result.Errors.Count == 0)
            {
                try
                {
                    result = new ResultVm <bool>().FromSuccessObject(_repo.AddCheckin(serverName, checkin));
                }
                catch (Exception ex)
                {
                    result = new ResultVm <bool>().FromException(ex);
                }
            }
            else
            {
                result.Data = false;
            }

            return(result);
        }
Esempio n. 2
0
        public void aggregating_a_mix_of_true_and_false_demands_still_throws()
        {
            Action vrfy = () => Demand.That(true).AndThat(false).Because("something failed");

            vrfy.ShouldThrow <DemandUnmetException>()
            .WithMessage("something failed");
        }
Esempio n. 3
0
        public void aggregating_demands_that_all_fail_throws_right_away()
        {
            Action vrfy = () => Demand.That(false).AndThat(false).Because("we're making sure this works");

            vrfy.ShouldThrow <DemandUnmetException>()
            .WithMessage("we're making sure this works");
        }
Esempio n. 4
0
        public void aggregating_false_before_true_still_works()
        {
            Action vrfy = () => Demand.That(false).AndThat(true).Because("this is still valid");

            vrfy.ShouldThrow <DemandUnmetException>()
            .WithMessage("this is still valid");
        }
Esempio n. 5
0
        public void demanding_false_with_a_specific_exception_throws_the_right_thing()
        {
            Action vrfy = () => Demand.That(false).OrThrow <SpecialSnowflakeException>("Not special enough!");

            vrfy.ShouldThrow <SpecialSnowflakeException>()
            .WithMessage("Not special enough!");
        }
Esempio n. 6
0
        public void demanding_a_false_expression_throws_right_away()
        {
            Action vrfy = () => Demand.That(false).Because("false throws right away");

            vrfy.ShouldThrow <DemandUnmetException>()
            .WithMessage("false throws right away");
        }
Esempio n. 7
0
        public void demanding_a_true_predicate_silently_succeeds()
        {
            var trueIsSuccess = Demand.That(() => true);

            Action vrfy = () => trueIsSuccess.Because("We don't throw on success");

            vrfy.ShouldNotThrow();
        }
Esempio n. 8
0
        public void demanding_a_special_exception_for_a_true_predicate_silently_succeeds()
        {
            var trueIsSuccess = Demand.That(() => true);

            Action vrfy = () => trueIsSuccess
                          .OrThrow <SpecialSnowflakeException>("Throwing on success _would_ be special");

            vrfy.ShouldNotThrow();
        }
Esempio n. 9
0
        public void Target_Expression()
        {
            string name = "asdf";

            var target = Demand.That(() => name);

            Assert.AreEqual("name", target.Name);
            Assert.AreEqual("asdf", target.Value);
        }
Esempio n. 10
0
        public void demanding_a_false_predicate_throws()
        {
            var falseIsFailure = Demand.That(() => false);

            Action vrfy = () => falseIsFailure.Because("We throw on failure");

            vrfy.ShouldThrow <DemandUnmetException>()
            .WithMessage("We throw on failure");
        }
Esempio n. 11
0
        public void Target_Explicit()
        {
            string name  = "asdf";
            string value = "fdsa";

            var target = Demand.That(name, value);

            Assert.AreEqual(name, target.Name);
            Assert.AreEqual(value, target.Value);
        }
Esempio n. 12
0
        public void demanding_a_special_exception_for_a_false_predicate_throws_the_right_thing()
        {
            var falseIsFailure = Demand.That(() => false);

            Action vrfy = () => falseIsFailure
                          .OrThrow <SpecialSnowflakeException>("Snowflake specialness below threshold");

            vrfy.ShouldThrow <SpecialSnowflakeException>()
            .WithMessage("Snowflake specialness below threshold");
        }
Esempio n. 13
0
        public void Target_Explicit_EmptyName()
        {
            string name  = string.Empty;
            string value = "asdf";

            try
            {
                var target = Demand.That(name, value);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual("name", e.ParamName);
                Assert.AreEqual("name cannot be null or empty\r\nParameter name: name", e.Message);
                throw;
            }
        }
Esempio n. 14
0
        public R.ResultVm <bool> RemoveServer(string name)
        {
            var result = new R.ResultVm <bool>().FromEmptyFailure();

            Demand <string> .That(name, "name").HasNonEmptyValue().Result(result);

            if (result.Errors.Count == 0)
            {
                try
                {
                    return(new ResultVm <bool>().FromSuccessObject(_repo.RemoveServer(name)));
                }
                catch (Exception ex)
                {
                    return(new ResultVm <bool>().FromException(ex));
                }
            }

            return(result);
        }
Esempio n. 15
0
        public R.ResultVm <bool> UpdateServer(string serverName, string address)
        {
            var result = new R.ResultVm <bool>().FromEmptyFailure();

            Demand <string> .That(serverName, "serverName").HasNonEmptyValue().Result(result);

            if (result.Errors.Count == 0)
            {
                try
                {
                    return(new ResultVm <bool>().FromSuccessObject(_repo.UpdateServer(serverName, address)));
                }
                catch (Exception ex)
                {
                    return(new ResultVm <bool>().FromException(ex));
                }
            }

            return(result);
        }
Esempio n. 16
0
        public R.ResultVm <Server> GetServerMetrics(string serverName, DateTime start, DateTime end)
        {
            var result = new R.ResultVm <Server>().FromEmptyFailure();

            Demand <string> .That(serverName, "serverName").HasNonEmptyValue().Result(result);

            Demand <DateTime> .That(start, "start").IsBefore(end).Result(result);

            if (result.Errors.Count == 0)
            {
                try
                {
                    return(new ResultVm <Server>().FromSuccessObject(_repo.GetServerMetrics(serverName, start, end)));
                }
                catch (Exception ex)
                {
                    return(new ResultVm <Server>().FromException(ex));
                }
            }

            return(result);
        }
Esempio n. 17
0
        public R.ResultVm <bool> AddServer(ServerOnlyVm server)
        {
            var rv = new ResultVm <bool>().FromEmptyFailure();

            Demand <string> .That(server.Name, "server.Name").HasNonEmptyValue().Result(rv);

            if (rv.Errors.Count == 0)
            {
                try
                {
                    return(new ResultVm <bool>().FromSuccessObject(_repo.AddServer(server.ToDataModel())));
                }
                catch (Exception ex)
                {
                    return(new ResultVm <bool>().FromException(ex));
                }
            }
            else
            {
                return(rv);
            }
        }
Esempio n. 18
0
        public R.ResultVm <bool> ClearLogs(string serverName)
        {
            var result = new R.ResultVm <bool>().FromEmptyFailure();

            Demand <string> .That(serverName, "serverName").HasNonEmptyValue().Result(result);

            if (result.Errors.Count == 0)
            {
                try
                {
                    return(new ResultVm <bool>().FromSuccessObject(_repo.ClearLogs(serverName)));
                }
                catch (Exception ex)
                {
                    return(new ResultVm <bool>().FromException(ex));
                }
            }
            else
            {
                result.Data = false;
            }

            return(result);
        }
Esempio n. 19
0
        public void demanding_a_true_expression_succeeds_right_away()
        {
            Action vrfy = () => Demand.That(true).Because("it's true!");

            vrfy.ShouldNotThrow();
        }
Esempio n. 20
0
        public void demanding_true_with_a_specific_exception_does_not_throw()
        {
            Action vrfy = () => Demand.That(true).OrThrow <SpecialSnowflakeException>("True is still true");

            vrfy.ShouldNotThrow();
        }
Esempio n. 21
0
        public void aggregating_demands_that_all_succeed_silently_succeeds()
        {
            Action vrfy = () => Demand.That(true).AndThat(true).Because("they're both true!");

            vrfy.ShouldNotThrow();
        }