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); }
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"); }
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"); }
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"); }
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!"); }
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"); }
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(); }
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(); }
public void Target_Expression() { string name = "asdf"; var target = Demand.That(() => name); Assert.AreEqual("name", target.Name); Assert.AreEqual("asdf", target.Value); }
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"); }
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); }
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"); }
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; } }
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); }
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); }
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); }
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); } }
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); }
public void demanding_a_true_expression_succeeds_right_away() { Action vrfy = () => Demand.That(true).Because("it's true!"); vrfy.ShouldNotThrow(); }
public void demanding_true_with_a_specific_exception_does_not_throw() { Action vrfy = () => Demand.That(true).OrThrow <SpecialSnowflakeException>("True is still true"); vrfy.ShouldNotThrow(); }
public void aggregating_demands_that_all_succeed_silently_succeeds() { Action vrfy = () => Demand.That(true).AndThat(true).Because("they're both true!"); vrfy.ShouldNotThrow(); }