public void TestEmptyNameThrowsException() { // ARRANGE Guid paramId = Guid.NewGuid(); const string paramDescription = "Fortnightly MP Pairs"; IOrganisation paramOrganisation = new Organisation( id: Guid.NewGuid(), shortName: "LCBA", mediumName: "LCBA", longName: "Leicestershire Contract Bridge Association", code: "LCBA"); const DayOfWeek paramDayOfWeek = DayOfWeek.Saturday; TimeSpan paramTimeOfDay = new TimeSpan(10, 0, 0); const ETimePeriod paramTimePeriod = ETimePeriod.Morning; // ACT _ = new Competition( id: paramId, name: string.Empty, description: paramDescription, organisation: paramOrganisation, dayOfWeek: paramDayOfWeek, timeOfDay: paramTimeOfDay, timePeriod: paramTimePeriod); }
public void Test_With_Times_Over_24_Hours(int hours, ETimePeriod expectedValue) { // ARRANGE TimeSpan timeToTest = TimeSpan.FromHours(hours).Add(TimeSpan.FromDays(1)); // ACT ETimePeriod timePeriod = timeToTest.ToTimePeriod(); // ASSERT Assert.AreEqual(expectedValue, timePeriod); }
public void Test_With_Various_Times(int hours, ETimePeriod expectedValue) { // ARRANGE TimeSpan timeToTest = TimeSpan.FromHours(hours); // ACT ETimePeriod timePeriod = timeToTest.ToTimePeriod(); // ASSERT Assert.AreEqual(expectedValue, timePeriod); }
public void TestInvalidTimeOfDayPropertyIsValid(ETimePeriod timePeriod) { // ARRANGE ValidTimePeriodAttribute attribute = new ValidTimePeriodAttribute(nameof(TestClass.TimeOfDay)); TestClass testObj = new TestClass(new TimeSpan(5, 0, 0, 0)); // ACT ValidationResult validationResult = attribute.GetValidationResult( value: timePeriod, validationContext: new ValidationContext(testObj)); // ASSERT Assert.AreEqual(ValidationResult.Success, validationResult); }
/// <summary> /// Initializes a new instance of the <see cref="CompetitionDto"/> class. /// </summary> /// <param name="id">Competition Id.</param> /// <param name="name">Competition Name.</param> /// <param name="description">Competition Description.</param> /// <param name="dayOfWeek">Day of Week.</param> /// <param name="timeOfDay">Time of Day.</param> /// <param name="timePeriod">Time Period.</param> /// <param name="organisationId">Organisation Id.</param> public CompetitionDto( Guid id, string name, string description, DayOfWeek dayOfWeek, TimeSpan timeOfDay, ETimePeriod timePeriod, Guid organisationId) { this.Id = id; this.Name = name; this.Description = description; this.DayOfWeek = dayOfWeek; this.TimeOfDay = timeOfDay; this.TimePeriod = timePeriod; this.OrganisationId = organisationId; }
/// <summary> /// Initializes a new instance of the <see cref="Competition"/> class. /// </summary> /// <param name="id">Competition Id.</param> /// <param name="name">Competition Name.</param> /// <param name="description">Description.</param> /// <param name="dayOfWeek">Day of the Week.</param> /// <param name="timeOfDay">Time of the Day.</param> /// <param name="timePeriod">Time Period.</param> /// <param name="organisation">Organisation.</param> public Competition( Guid id, string name, string description, DayOfWeek dayOfWeek, TimeSpan timeOfDay, ETimePeriod timePeriod, IOrganisation organisation) { this.Id = id; this.Name = name; this.Description = description; this.DayOfWeek = dayOfWeek; this.TimeOfDay = timeOfDay; this.TimePeriod = timePeriod; this.Organisation = organisation; Validate(this); }
public void TestNullOrganisationThrowsException() { // ARRANGE Guid paramId = Guid.NewGuid(); const string paramName = "Saturday Pairs"; const string paramDescription = "Fortnightly MP Pairs"; const DayOfWeek paramDayOfWeek = DayOfWeek.Saturday; TimeSpan paramTimeOfDay = new TimeSpan(10, 0, 0); const ETimePeriod paramTimePeriod = ETimePeriod.Morning; // ACT _ = new Competition( id: paramId, name: paramName, description: paramDescription, organisation: null !, dayOfWeek: paramDayOfWeek, timeOfDay: paramTimeOfDay, timePeriod: paramTimePeriod); }
protected override ValidationResult IsValid( object value, ValidationContext validationContext) { PropertyInfo?timeOfDayProperty = validationContext.ObjectType.GetProperty(this.timeOfDayPropertyName); if (timeOfDayProperty == null) { throw new ArgumentException("Time of Day property not found"); } object timeOfDayObj = timeOfDayProperty.GetValue(validationContext.ObjectInstance); ValidTimeOfDayAttribute validTimeOfDayAttribute = new ValidTimeOfDayAttribute(); if (timeOfDayObj == null || !validTimeOfDayAttribute.IsValid(timeOfDayObj)) { return(ValidationResult.Success); } if (!(value is ETimePeriod)) { return(new ValidationResult($"Attribute can only be used on a {nameof(ETimePeriod)}")); } ETimePeriod inputValue = (ETimePeriod)value; ETimePeriod expectedTimePeriod = ((TimeSpan)timeOfDayObj).ToTimePeriod(); if (inputValue == expectedTimePeriod) { return(ValidationResult.Success); } DisplayAttribute timeOfDayDisplayAttr = timeOfDayProperty.GetCustomAttribute <DisplayAttribute>(); string timeOfDayDisplayName = timeOfDayDisplayAttr?.Name ?? this.timeOfDayPropertyName; return(new ValidationResult( $"{validationContext.DisplayName} is inconsistent with {timeOfDayDisplayName}.")); }