public void VerifyFormatOfDateParameterType() { var dateParameterType = new DateParameterType(); var format = NumberFormat.Format(dateParameterType); Assert.AreEqual("yyyy-mm-dd", format); }
public void Setup() { this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>(); this.permissionService = new Mock <IPermissionService>(); this.session = new Mock <ISession>(); this.requirement = new Requirement(Guid.NewGuid(), null, null); this.simpleParameterValue = new SimpleParameterValue(Guid.NewGuid(), null, null) { Scale = new CyclicRatioScale { Name = "a", ShortName = "e" }, ParameterType = new BooleanParameterType { Name = "a", ShortName = "a" } }; this.testParameterType = new DateParameterType(Guid.NewGuid(), null, null) { Name = "testPT", ShortName = "tpt" }; this.simpleParameterValue.ParameterType = this.testParameterType; var values = new List <string> { "1", "2" }; this.simpleParameterValue.Value = new ValueArray <string>(values); this.requirement.ParameterValue.Add(this.simpleParameterValue); this.permissionService.Setup(x => x.CanWrite(ClassKind.Term, It.IsAny <Thing>())).Returns(true); this.session.Setup(x => x.DataSourceUri).Returns(this.uri.ToString); }
public void VerifThatConvertDoubleToDateTimeObjectConvertsAsExpected() { var timeOfDayParameterType = new TimeOfDayParameterType(Guid.NewGuid(), null, null); DateTime expectedDate; var stringValue = "-"; var stringValueAsObject = (object)stringValue; ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref stringValueAsObject, timeOfDayParameterType); Assert.AreEqual("-", stringValueAsObject); var timeDoubleValue = 0.11111111111111111111111111111d; var timeDoubleValueAsObject = (object)timeDoubleValue; ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref timeDoubleValueAsObject, timeOfDayParameterType); expectedDate = new DateTime(1, 1, 1, 2, 40, 0); Assert.AreEqual(expectedDate, timeDoubleValueAsObject); var dateParameterType = new DateParameterType(Guid.NewGuid(), null, null); var dateDoubleValue = 0.11111111111111111111111111111d; var dateDoubleValueAsObject = (object)dateDoubleValue; ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref dateDoubleValueAsObject, dateParameterType); expectedDate = new DateTime(1899, 12, 30, 2, 40, 0); Assert.AreEqual(expectedDate, dateDoubleValueAsObject); }
public void SetUp() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; this.uri = new Uri("http://www.rheagroup.com"); this.cache = new ConcurrentDictionary <CDP4Common.Types.CacheKey, Lazy <Thing> >(); this.ratioScale = new RatioScale(Guid.NewGuid(), this.cache, this.uri); var valuedefLow = new EnumerationValueDefinition(Guid.NewGuid(), this.cache, this.uri); valuedefLow.ShortName = "low"; var valuedefMedium = new EnumerationValueDefinition(Guid.NewGuid(), this.cache, this.uri); valuedefMedium.ShortName = "medium"; this.booleanParameterType = new BooleanParameterType(Guid.NewGuid(), this.cache, this.uri); this.dateParameterType = new DateParameterType(Guid.NewGuid(), this.cache, this.uri); this.dateTimeParameterType = new DateTimeParameterType(Guid.NewGuid(), this.cache, this.uri); this.enumerationParameterType = new EnumerationParameterType(Guid.NewGuid(), this.cache, this.uri); this.enumerationParameterType.Name = "test"; this.enumerationParameterType.ValueDefinition.Add(valuedefLow); this.enumerationParameterType.ValueDefinition.Add(valuedefMedium); this.simpleQuantityKind = new SimpleQuantityKind(Guid.NewGuid(), this.cache, this.uri); this.simpleQuantityKind.PossibleScale.Add(this.ratioScale); this.simpleQuantityKind.DefaultScale = this.ratioScale; this.textParameterType = new TextParameterType(Guid.NewGuid(), this.cache, this.uri); this.timeOfDayParameterType = new TimeOfDayParameterType(Guid.NewGuid(), this.cache, this.uri); }
/// <summary> /// Validates the <param name="value"></param> to check whether it is a <see cref="DateTime"/> that does not contain any time data. /// </summary> /// <param name="parameterType"> /// A <see cref="DateParameterType"/> /// </param> /// <param name="value"> /// the string representation of a <see cref="DateTime"/> value that only contains date data and not any time data. /// </param> /// <returns> /// a <see cref="ValidationResult"/> that carries the <see cref="ValidationResultKind"/> and an optional message. /// </returns> public static ValidationResult Validate(this DateParameterType parameterType, string value) { ValidationResult result; if (value == DefaultValue) { result.ResultKind = ValidationResultKind.Valid; result.Message = string.Empty; return(result); } DateTime dateTime; var isDateTime = DateTime.TryParseExact(value, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime); if (isDateTime) { result.ResultKind = ValidationResultKind.Valid; result.Message = string.Empty; return(result); } else { result.ResultKind = ValidationResultKind.Invalid; result.Message = string.Format("{0} is not a valid Date, valid dates are specified in ISO 8601 YYYY-MM-DD", value); return(result); } }
public void VerifyParameterTypeToDescriptionConverter() { string shortName = "d"; string name = "date"; var dateParameterType = new DateParameterType() { ShortName = shortName, Name = name }; var result = (string)this.parameterTypeToDescriptionConverter.Convert(dateParameterType, null, null, null); Assert.AreEqual("d - date", result); }
public void Setup() { RxApp.MainThreadScheduler = Scheduler.CurrentThread; this.serviceLocator = new Mock <IServiceLocator>(); this.navigation = new Mock <IThingDialogNavigationService>(); ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object); this.serviceLocator.Setup(x => x.GetInstance <IThingDialogNavigationService>()).Returns(this.navigation.Object); this.session = new Mock <ISession>(); var person = new Person(Guid.NewGuid(), null, null) { Container = this.siteDir }; this.session.Setup(x => x.ActivePerson).Returns(person); this.permissionService = new Mock <IPermissionService>(); this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true); this.siteDir = new SiteDirectory(Guid.NewGuid(), null, null); this.siteDir.Person.Add(person); var rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null) { Name = "testRDL", ShortName = "test" }; this.dateParameterType = new DateParameterType(Guid.NewGuid(), null, null) { Name = "booleanParameterType", ShortName = "cat" }; var cat = new Category(Guid.NewGuid(), null, null) { Name = "category1", ShortName = "cat1" }; rdl.DefinedCategory.Add(cat); this.siteDir.SiteReferenceDataLibrary.Add(rdl); var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir); this.transaction = new ThingTransaction(transactionContext, null); this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir); this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object); this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary)); var dal = new Mock <IDal>(); this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0)); this.session.Setup(x => x.Dal).Returns(dal.Object); dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider()); }
/// <summary> /// Validates the <param name="value"></param> to check whether it is a <see cref="DateTime"/> that does not contain any time data. /// </summary> /// <param name="parameterType"> /// A <see cref="DateParameterType"/> /// </param> /// <param name="value"> /// the string representation of a <see cref="DateTime"/> value that only contains date data and not any time data. /// </param> /// <returns> /// a <see cref="ValidationResult"/> that carries the <see cref="ValidationResultKind"/> and an optional message. /// </returns> public static ValidationResult Validate(this DateParameterType parameterType, object value) { ValidationResult result; var stringValue = value as string; if (stringValue != null) { if (stringValue == DefaultValue) { result.ResultKind = ValidationResultKind.Valid; result.Message = string.Empty; return(result); } DateTime dateTime; var isDateTime = DateTime.TryParseExact(stringValue, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime); if (isDateTime) { result.ResultKind = ValidationResultKind.Valid; result.Message = string.Empty; return(result); } } try { var dateValue = Convert.ToDateTime(value); if (dateValue.Hour == 0 && dateValue.Minute == 0 && dateValue.Second == 0 && dateValue.Millisecond == 0) { result.ResultKind = ValidationResultKind.Valid; result.Message = string.Empty; return(result); } } catch (Exception ex) { Logger.Trace(ex); } result.ResultKind = ValidationResultKind.Invalid; result.Message = $"{value} is not a valid Date, valid dates are specified in ISO 8601 YYYY-MM-DD"; return(result); }
/// <summary> /// Serialize the <see cref="DateParameterType"/> /// </summary> /// <param name="dateParameterType">The <see cref="DateParameterType"/> to serialize</param> /// <returns>The <see cref="JObject"/></returns> private JObject Serialize(DateParameterType dateParameterType) { var jsonObject = new JObject(); jsonObject.Add("alias", this.PropertySerializerMap["alias"](dateParameterType.Alias.OrderBy(x => x, this.guidComparer))); jsonObject.Add("category", this.PropertySerializerMap["category"](dateParameterType.Category.OrderBy(x => x, this.guidComparer))); jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), dateParameterType.ClassKind))); jsonObject.Add("definition", this.PropertySerializerMap["definition"](dateParameterType.Definition.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](dateParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer))); jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](dateParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer))); jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](dateParameterType.HyperLink.OrderBy(x => x, this.guidComparer))); jsonObject.Add("iid", this.PropertySerializerMap["iid"](dateParameterType.Iid)); jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](dateParameterType.IsDeprecated)); jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](dateParameterType.ModifiedOn)); jsonObject.Add("name", this.PropertySerializerMap["name"](dateParameterType.Name)); jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](dateParameterType.RevisionNumber)); jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](dateParameterType.ShortName)); jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](dateParameterType.Symbol)); jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](dateParameterType.ThingPreference)); return(jsonObject); }
public void SetUp() { this.domainOfExpertise = new DomainOfExpertise { ShortName = "SYS", Name = "System" }; this.session = new Mock <ISession>(); this.session.Setup(x => x.QuerySelectedDomainOfExpertise(It.IsAny <Iteration>())) .Returns(this.domainOfExpertise); this.engineeringModelSetup = new EngineeringModelSetup { ShortName = "TST", Name = "Test" }; this.iterationSetup = new IterationSetup { IterationNumber = 1 }; this.engineeringModelSetup.IterationSetup.Add(this.iterationSetup); this.engineeringModel = new EngineeringModel { EngineeringModelSetup = this.engineeringModelSetup }; this.iteration = new Iteration { IterationSetup = this.iterationSetup }; this.engineeringModel.Iteration.Add(this.iteration); this.dateParameterType = new DateParameterType { ShortName = "LD", Name = "Launch Date" }; this.ratioScale = new RatioScale { ShortName = "kg", Name = "kilogram" }; this.simpleQuantityKind = new SimpleQuantityKind { ShortName = "m", Name = "mass" }; this.booleanParameterType = new BooleanParameterType { ShortName = "C", Name = "Compliant" }; }
public void VerifyToDtoMethodWithListThing() { var dateParameterType = new DateParameterType { Iid = new Guid() }; dateParameterType.Container = this.srdl; var hyperlink = new HyperLink(Guid.NewGuid(), null, null); var hyperlink2 = new HyperLink(Guid.NewGuid(), null, null); dateParameterType.HyperLink.Add(hyperlink); dateParameterType.HyperLink.Add(hyperlink2); var dto = dateParameterType.ToDto() as CDP4Common.DTO.DateParameterType; Assert.IsNotNull(dto); Assert.AreEqual(2, dto.HyperLink.Count); Assert.AreEqual(dateParameterType.HyperLink[1].Iid, dto.HyperLink[1]); Assert.AreEqual(dateParameterType.HyperLink[0].Iid, dto.HyperLink[0]); Assert.AreEqual(dateParameterType.Route, dto.Route); Assert.AreEqual(dateParameterType, dto.QuerySourceThing()); }
/// <summary> /// Initializes a new instance of the <see cref="DateParameterTypeDialogViewModel"/> class /// </summary> /// <param name="dateParameterType"> /// The <see cref="DateParameterType"/> that is the subject of the current view-model. This is the object /// that will be either created, or edited. /// </param> /// <param name="thingTransaction"> /// The <see cref="ThingTransaction"/> that contains the log of recorded changes. /// </param> /// <param name="session"> /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated /// </param> /// <param name="isRoot"> /// Assert if this <see cref="DialogViewModelBase{T}"/> is the root of all <see cref="DialogViewModelBase{T}"/> /// </param> /// <param name="thingDialogKind"> /// The kind of operation this <see cref="DialogViewModelBase{T}"/> performs /// </param> /// <param name="thingDialogNavigationService"> /// The <see cref="IThingDialogNavigationService"/> that is used to navigate to a dialog of a specific <see cref="Thing"/>. /// </param> /// <param name="container"> /// The <see cref="Thing"/> that contains the created <see cref="Thing"/> in this Dialog /// </param> /// <param name="chainOfContainers"> /// The optional chain of containers that contains the <paramref name="container"/> argument /// </param> public DateParameterTypeDialogViewModel(DateParameterType dateParameterType, IThingTransaction thingTransaction, ISession session, bool isRoot, ThingDialogKind thingDialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null) : base(dateParameterType, thingTransaction, session, isRoot, thingDialogKind, thingDialogNavigationService, container, chainOfContainers) { }
/// <summary> /// Persist the <see cref="DateParameterType"/> containment tree to the ORM layer. Update if it already exists. /// This is typically used during the import of existing data to the Database. /// </summary> /// <param name="transaction"> /// The current <see cref="NpgsqlTransaction"/> to the database. /// </param> /// <param name="partition"> /// The database partition (schema) where the requested resource will be stored. /// </param> /// <param name="dateParameterType"> /// The <see cref="DateParameterType"/> instance to persist. /// </param> /// <returns> /// True if the persistence was successful. /// </returns> private bool UpsertContainment(NpgsqlTransaction transaction, string partition, DateParameterType dateParameterType) { var results = new List <bool>(); foreach (var alias in this.ResolveFromRequestCache(dateParameterType.Alias)) { results.Add(this.AliasService.UpsertConcept(transaction, partition, alias, dateParameterType)); } foreach (var definition in this.ResolveFromRequestCache(dateParameterType.Definition)) { results.Add(this.DefinitionService.UpsertConcept(transaction, partition, definition, dateParameterType)); } foreach (var hyperLink in this.ResolveFromRequestCache(dateParameterType.HyperLink)) { results.Add(this.HyperLinkService.UpsertConcept(transaction, partition, hyperLink, dateParameterType)); } return(results.All(x => x)); }