public void when_reading_file_with_decimal_numbers_then_conversion_is_successfully() { var path = @"Files\number_format.csv"; var metadata = new DocumentMetadata { DocumentName = "ValidFile", Columns = new List <DocumentColumnMetadata> { new DocumentColumnMetadata { ColumnNumber = 0, Name = "nombre", Type = typeof(string).Name }, new DocumentColumnMetadata { ColumnNumber = 1, Name = "valor", Type = typeof(double).Name } }, HasHeader = true }; var document = this.reader.Read(path, metadata); var expectedNumbers = File.ReadAllLines(path).Skip(1).Select(l => l.Split(';').Skip(1).First()); Assert.NotNull(document); Assert.Equal(9, document.Rows.Count()); var convertedNumbers = document.Rows.Select(r => r.Cells.Skip(1).First().Value); }
public void Test_EmtyInstanceEqulity() { var meta1 = new DocumentMetadata(); var meta2 = new DocumentMetadata(); Assert.That(meta1, Is.EqualTo(meta2), "Instances created by default constructor should be equal"); }
/// <summary> /// Creates a new IODocument with the specified parameters. /// </summary> /// <param name="size">The size of the document.</param> /// <param name="components">Components the document contains.</param> public IODocument(Size size, IEnumerable <IOComponent> components, IEnumerable <IOWire> wires) { Metadata = new DocumentMetadata(); Size = size; Components = new List <IOComponent>(components); Wires = new List <IOWire>(wires); }
private void ValidateDocumentColumns(DocumentMetadata metadata, string[] fields, long line) { if (fields.Length > metadata.Columns.Count()) { throw new DocumentFormatException(string.Format(Resources.CsvDocumentReader_ExpectedColumnsFailed, metadata.Columns.Count(), fields.Length, line, metadata.DocumentName)); } }
public void PropertyGroupDescriptionForProjectNamesIsAddedWhenGroupByProjectIsTrue() { // Arrange var builder = new UserPreferencesBuilder(); var preferences = builder.CreateUserPreferences(); preferences.GroupByProject = true; var collection = new DocumentMetadata[0]; var view = new ListCollectionView(collection); var reaction = new GroupByProjectReaction(); // Act reaction.UpdateCollection(view, preferences); // Assert Assert.That(view.GroupDescriptions.Count, Is.EqualTo(1)); var description = (PropertyGroupDescription)view.GroupDescriptions[0]; const string propertyName = nameof(DocumentMetadata.ProjectNames); Assert.That(description.PropertyName, Is.EqualTo(propertyName)); }
private DocumentMetadata GetDocumentMetadata(string filename) { Logger.LogMessage($"Get document metadata for '{filename}'"); DocumentMetadata documentMetadata = null; var filenameHelper = new FilenameHelper(); var hasId = filenameHelper.HasId(filename); var id = 0; if (hasId) { id = int.Parse(filenameHelper.GetId(filename)); } foreach (var metadataEntry in metadata) { if ((hasId && id == metadataEntry.DocumentId) || (metadataEntry.DocumentFilename.Equals(filename, StringComparison.InvariantCultureIgnoreCase))) { documentMetadata = metadataEntry; break; } } return(documentMetadata); }
public override void OnBeforeStart() { _log.Info("Creating the document storage started."); var documentTypes = _metadataApi.GetMetadataItemNames("Documents"); foreach (var documentType in documentTypes) { var documentMetadata = new DocumentMetadata { Type = documentType }; var documentIndexes = _metadataApi.GetDocumentIndexes(documentType); if (documentIndexes != null) { documentMetadata.Indexes = documentIndexes.Select(i => _jsonObjectSerializer.ConvertFromDynamic <DocumentIndex>(i)).ToArray(); } // Специально для Mono пришлось выполнять создание коллекций в последовательном режиме AsyncHelper.RunSync(() => CreateStorageAsync(documentMetadata)); } _log.Info("Creating the document storage successfully completed."); }
public void ConsumerConsumesPatient(XElement documentXEl, Person expected) { DocumentMetadata doc = XDMetadataConsumer.ConsumeDocument(documentXEl); Assert.Equal(expected, doc.Patient); Assert.Equal(expected.Address, doc.Patient.Address); }
public DocumentMetadata GetMetadata(string key) { DocumentMetadata metadata = null; Cache.TryGetValue(key, out metadata); return(metadata); }
public string GetActionName(Webpage webpage, string httpMethod) { if (webpage == null) { return(null); } if (!webpage.Published && !_userUIPermissionsService.IsCurrentUserAllowed(webpage)) { return(null); } DocumentMetadata metadata = GetMetadata(webpage); if (metadata == null) { return(null); } switch (httpMethod) { case "GET": case "HEAD": return(metadata.WebGetAction); case "POST": return(metadata.WebPostAction); default: return(null); } }
private DocumentMetadata GetDocumentMetadata <T>(T instance) { DocumentMetadata value; if (entitiesAndMetadata.TryGetValue(instance, out value) == false) { string id; if (TryGetIdFromInstance(instance, out id) #if !NET_3_5 || (instance is IDynamicMetaObjectProvider && TryGetIdFromDynamic(instance, out id)) #endif ) { var jsonDocument = GetJsonDocument(id); entitiesByKey[id] = instance; entitiesAndMetadata[instance] = value = new DocumentMetadata { ETag = UseOptimisticConcurrency ? (Guid?)Guid.Empty : null, Key = id, OriginalMetadata = jsonDocument.Metadata, Metadata = (RavenJObject)jsonDocument.Metadata.CloneToken(), OriginalValue = new RavenJObject() }; } else { throw new InvalidOperationException("Could not find the document key for " + instance); } } return(value); }
public void SettingIsActiveToSameValueDoesNotRaisePropertyChanged() { // Arrange const bool isActive = true; var propertyChangedRaised = false; var info = new DocumentMetadataInfo(); var metadata = new DocumentMetadata(info, string.Empty, null) { IsActive = isActive }; var handler = new PropertyChangedEventHandler((s, e) => { propertyChangedRaised = true; }); metadata.PropertyChanged += handler; // Act metadata.IsActive = isActive; metadata.PropertyChanged -= handler; // Assert Assert.IsFalse(propertyChangedRaised); }
/// <summary> /// Creates a new IODocument with the specified parameters. /// </summary> /// <param name="size">The size of the document.</param> /// <param name="components">Components the document contains.</param> public IODocument(Size size, IEnumerable<IOComponent> components, IEnumerable<IOWire> wires) { Metadata = new DocumentMetadata(); Size = size; Components = new List<IOComponent>(components); Wires = new List<IOWire>(wires); }
public void SettingUsageOrderToDifferentValueRaisesPropertyChanged() { // Arrange var propertyChangedRaised = false; var info = new DocumentMetadataInfo(); var metadata = new DocumentMetadata(info, string.Empty, null) { UsageOrder = 0.3 }; var handler = new PropertyChangedEventHandler((s, e) => { propertyChangedRaised = true; }); metadata.PropertyChanged += handler; // Act metadata.UsageOrder = 0.7; metadata.PropertyChanged -= handler; // Assert Assert.IsTrue(propertyChangedRaised); }
public void SettingDisplayNameToSameValueDoesNotRaisePropertyChanged() { // Arrange const string displayName = "DisplayName"; var propertyChangedRaised = false; var info = new DocumentMetadataInfo(); var metadata = new DocumentMetadata(info, string.Empty, null) { DisplayName = displayName }; var handler = new PropertyChangedEventHandler((s, e) => { propertyChangedRaised = true; }); metadata.PropertyChanged += handler; // Act metadata.DisplayName = displayName; metadata.PropertyChanged -= handler; // Assert Assert.IsFalse(propertyChangedRaised); }
private string GetCreateTableScript(DocumentMetadata metadata) { var scriptBuilder = new StringBuilder(); scriptBuilder.Append("CREATE TABLE "); scriptBuilder.Append(metadata.DocumentName); scriptBuilder.Append("("); var i = 1; foreach (var columnMetadaData in metadata.Columns.OrderBy(c => c.ColumnNumber)) { scriptBuilder.Append(string.Format("{0} {1}", columnMetadaData.Name, this.GetSQLiteType(columnMetadaData))); if (i < metadata.Columns.Count()) { scriptBuilder.Append(", "); } i++; } scriptBuilder.Append(");"); return(scriptBuilder.ToString()); }
/// <summary> /// Determines if the entity have changed. /// </summary> /// <param name="entity">The entity.</param> /// <param name="documentMetadata">The document metadata.</param> /// <returns></returns> protected bool EntityChanged(object entity, DocumentMetadata documentMetadata) { if (documentMetadata == null) { return(true); } string id; if (TryGetIdFromInstance(entity, out id) && string.Equals(documentMetadata.Key, id, StringComparison.InvariantCultureIgnoreCase) == false) { return(true); } // prevent saves of a modified read only entity if (documentMetadata.OriginalMetadata.ContainsKey(Constants.RavenReadOnly) && documentMetadata.OriginalMetadata.Value <bool>(Constants.RavenReadOnly) && documentMetadata.Metadata.ContainsKey(Constants.RavenReadOnly) && documentMetadata.Metadata.Value <bool>(Constants.RavenReadOnly)) { return(false); } var newObj = ConvertEntityToJson(entity, documentMetadata.Metadata); return(RavenJToken.DeepEquals(newObj, documentMetadata.OriginalValue) == false || RavenJToken.DeepEquals(documentMetadata.Metadata, documentMetadata.OriginalMetadata) == false); }
public void SetDocumentWithExistingWrongSizeThrowsError() { DocumentMetadata m = new DocumentMetadata(); m.Size = 1000000000; Assert.Throws <FormatException>(() => m.SetDocument("abc")); }
public void PinnedMetadataIsRemovedBeforeClosingSolutionIfNoMetadataIsPinned() { // Arrange const string solutionFullName = "SolutionFullName"; var metadata = new DocumentMetadata[0]; var metadataView = new ListCollectionView(metadata); var storageService = Mock.Of <IPinnedItemStorageService>(); var service = new SolutionEventsService( Mock.Of <DTE2>(d => d.Solution.FullName == solutionFullName), Mock.Of <IDocumentMetadataManager>(m => m.PinnedDocumentMetadata == metadataView), storageService, Mock.Of <IProjectBrushService>(), Mock.Of <IUserPreferences>()); // Act service.BeforeClosing(); // Assert Mock.Get(storageService).Verify(s => s.Remove(solutionFullName)); Mock.Get(storageService).Verify(s => s.Write( It.IsAny <IEnumerable <DocumentMetadata> >(), It.IsAny <string>()), Times.Never); }
public void SetDocumentWithExistingWrongHashThrowsError() { DocumentMetadata m = new DocumentMetadata(); m.Hash = "abc123"; Assert.Throws <FormatException>(() => m.SetDocument("abc")); }
public void SetDocumentSetsSize() { DocumentMetadata m = new DocumentMetadata(); m.SetDocument(new byte[] { 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100 }); Assert.Equal(11, m.Size); }
public void DocumentStringHasStringRepresentation() { DocumentMetadata m = new DocumentMetadata(); m.SetDocument("abc123"); Assert.Equal("abc123", m.DocumentString); }
/// <summary> /// Tracks the entity. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key">The key.</param> /// <param name="document">The document.</param> /// <param name="metadata">The metadata.</param> /// <returns></returns> public T TrackEntity <T>(string key, RavenJObject document, RavenJObject metadata) { document.Remove("@metadata"); object entity; if (entitiesByKey.TryGetValue(key, out entity) == false) { entity = ConvertToEntity <T>(key, document, metadata); } else { // the local instance may have been changed, we adhere to the current Unit of Work // instance, and return that, ignoring anything new. return((T)entity); } var etag = metadata.Value <string>("@etag"); if (metadata.Value <bool>("Non-Authoritative-Information") && AllowNonAuthoritativeInformation == false) { throw new NonAuthoritativeInformationException("Document " + key + " returned Non Authoritative Information (probably modified by a transaction in progress) and AllowNonAuthoritativeInformation is set to false"); } entitiesAndMetadata[entity] = new DocumentMetadata { OriginalValue = document, Metadata = metadata, OriginalMetadata = (RavenJObject)metadata.CloneToken(), ETag = new Guid(etag), Key = key }; entitiesByKey[key] = entity; return((T)entity); }
public async Task ShouldDropStorageAsync() { // Given const string collectionName = nameof(ShouldDropStorageAsync); var connection = MongoTestHelpers.GetConnection(); var database = connection.GetDatabase(); database.DropCollection(collectionName); var documentMetadata = new DocumentMetadata { Type = collectionName }; // When var storageManager = new MongoDocumentStorageManager(connection); await storageManager.CreateStorageAsync(documentMetadata); var collection = database.GetCollection <DynamicWrapper>(collectionName); var collectionContent = new[] { new DynamicWrapper(), new DynamicWrapper(), new DynamicWrapper() }; collection.InsertMany(collectionContent); var collectionCountBeforeDrop = collection.Count(Builders <DynamicWrapper> .Filter.Empty); await storageManager.DropStorageAsync(collectionName); var collectionCountAfterDrop = collection.Count(Builders <DynamicWrapper> .Filter.Empty); // Then Assert.AreEqual(collectionContent.Length, collectionCountBeforeDrop); Assert.AreEqual(0, collectionCountAfterDrop); }
/// <summary> /// Creates the put entity command. /// </summary> /// <param name="entity">The entity.</param> /// <param name="documentMetadata">The document metadata.</param> /// <returns></returns> protected ICommandData CreatePutEntityCommand(object entity, DocumentMetadata documentMetadata) { string id; if (TryGetIdFromInstance(entity, out id) && documentMetadata.Key != null && documentMetadata.Key.Equals(id, StringComparison.InvariantCultureIgnoreCase) == false) { throw new InvalidOperationException("Entity " + entity.GetType().FullName + " had document key '" + documentMetadata.Key + "' but now has document key property '" + id + "'." + Environment.NewLine + "You cannot change the document key property of a entity loaded into the session"); } var json = ConvertEntityToJson(entity, documentMetadata.Metadata); var etag = UseOptimisticConcurrency || documentMetadata.ForceConcurrencyCheck ? (documentMetadata.ETag ?? Guid.Empty) : (Guid?)null; return(new PutCommandData { Document = json, Etag = etag, Key = documentMetadata.Key, Metadata = documentMetadata.Metadata, }); }
public string EquellaUpdate_Description(IRibbonControl button) { try { if (Integ.CurrentDocument != null) { if (string.IsNullOrEmpty(Integ.CurrentDocument.Metadata.ItemUuid)) { return("You need to have an existing scrapbook document open to use the update feature"); } else { DocumentWrapper doc = Integ.CurrentDocument; DocumentMetadata meta = doc.Metadata; string name = (string.IsNullOrEmpty(meta.ItemName) ? doc.FileName : meta.ItemName); return("Updates the existing \"" + name + "\" scrapbook resource on the EQUELLA server"); } } else { return("You have no open document to publish"); } } catch (Exception e) { Utils.ShowError(e); return("Updates an existing scrapbook resource on the EQUELLA server"); } }
public void SettingUsageOrderToSameValueDoesNotRaisePropertyChanged() { // Arrange const double value = 0.7; var propertyChangedRaised = false; var info = new DocumentMetadataInfo(); var metadata = new DocumentMetadata(info, string.Empty, null) { UsageOrder = value }; var handler = new PropertyChangedEventHandler((s, e) => { propertyChangedRaised = true; }); metadata.PropertyChanged += handler; // Act metadata.UsageOrder = value; metadata.PropertyChanged -= handler; // Assert Assert.IsFalse(propertyChangedRaised); }
public void ConsumerConsumesClass(XElement documentXEl, CodedValue code) { DocumentMetadata doc = XDMetadataConsumer.ConsumeDocument(documentXEl); Assert.Equal(code.ToString(), doc.Class.ToString()); Assert.True(code.Equals(doc.Class)); }
public void SettingProjectBrushToDifferentValueRaisesPropertyChanged() { // Arrange var propertyChangedRaised = false; var info = new DocumentMetadataInfo(); var metadata = new DocumentMetadata(info, string.Empty, null) { ProjectBrush = Brushes.MidnightBlue }; var handler = new PropertyChangedEventHandler((s, e) => { propertyChangedRaised = true; }); metadata.PropertyChanged += handler; // Act metadata.ProjectBrush = Brushes.White; metadata.PropertyChanged -= handler; // Assert Assert.IsTrue(propertyChangedRaised); }
public void SettingDisplayNameToDifferentValueRaisesPropertyChanged() { // Arrange var propertyChangedRaised = false; var info = new DocumentMetadataInfo(); var metadata = new DocumentMetadata(info, string.Empty, null) { DisplayName = "DisplayName" }; var handler = new PropertyChangedEventHandler((s, e) => { propertyChangedRaised = true; }); metadata.PropertyChanged += handler; // Act metadata.DisplayName = "NewDisplayName"; metadata.PropertyChanged -= handler; // Assert Assert.IsTrue(propertyChangedRaised); }
public void ConsumerConsumesAuthorPerson(XElement documentXEl, Person expected) { DocumentMetadata doc = XDMetadataConsumer.ConsumeDocument(documentXEl); Assert.Equal(expected.ToString(), doc.Author.Person.ToString()); Assert.True(expected.Equals(doc.Author.Person)); }
public async Task<string> createDocument(DocumentMetadata document) { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/api/document"); var keyValues = new List<KeyValuePair<string, string>>(); keyValues.Add(new KeyValuePair<string, string>("title", document.Title)); keyValues.Add(new KeyValuePair<string, string>("content", document.Content)); keyValues.Add(new KeyValuePair<string, string>("format", document.Format)); keyValues.Add(new KeyValuePair<string, string>("charset", document.Charset)); keyValues.Add(new KeyValuePair<string, string>("locale_code", document.LocaleCode)); keyValues.Add(new KeyValuePair<string, string>("project_id", document.ProjectId)); request.Content = new FormUrlEncodedContent(keyValues); var documentId = String.Empty; await this.Client.SendAsync(request) .ContinueWith(responseTask => { Console.WriteLine("\tResponse status: {0}", responseTask.Result.StatusCode); JavaScriptSerializer jsonSerialization = new JavaScriptSerializer(); var data = jsonSerialization.Deserialize<Dictionary<string,dynamic>>(responseTask.Result.Content.ReadAsStringAsync().Result); documentId = data["properties"]["id"]; Console.WriteLine("\tDocument ID: {0}", documentId); }); return documentId; }
static public void Main () { Console.OutputEncoding = Encoding.UTF8; using (Lingotek lingotek = new Lingotek() { Host = "https://cms.lingotek.com", AccessToken = "b068b8d9-c35b-3139-9fe2-e22ee7998d9f", // sandbox token CommunityId = "f49c4fca-ff93-4f01-a03e-aa36ddb1f2b8", // sandbox community ProjectId = "103956f4-17cf-4d79-9d15-5f7b7a88dee2", // sandbox project }) { // Let's read a community info. Console.WriteLine("COMMUNITY"); lingotek.requestCommunity().Wait(); // Let's read a project info. Console.WriteLine("PROJECT"); lingotek.requestProject().Wait(); // Create a document Console.WriteLine("DOCUMENT"); // This is the document that we need to translate. Dictionary<string, string> document = new Dictionary<string, string>(); document.Add("title", "This is my demo document"); document.Add("body", "This is the body of my demo document"); // This is the document metadata needed for the TMS. DocumentMetadata metadata = new DocumentMetadata() { Title = "This is my demo document", Content = JsonConvert.SerializeObject(document).ToString(), Format = "json", Charset = "utf-8", LocaleCode = "en-US", ProjectId = lingotek.ProjectId, }; var documentId = lingotek.createDocument(metadata).Result; // Check the status of our document. Console.WriteLine("IMPORT STATUS"); bool imported = false; var import_status_message = "\t{0} | check status: => {1}"; for (int i = 0; i < 30 && !imported; i++) { System.Threading.Thread.Sleep(3000); var result = lingotek.checkImportStatus(documentId).Result; if (result) { imported = true; Console.WriteLine(import_status_message, i, "imported!"); } else { Console.WriteLine(import_status_message, i, "importing..."); } } if (!imported) { Console.WriteLine("\tDocument never completed imported."); Environment.Exit(2); } // Request a translation of our document. Console.WriteLine("REQUEST TRANSLATION"); var locale = "zh-CN"; lingotek.requestTranslation(documentId, locale).Wait(); // Check the status of our document translation. Console.WriteLine("TRANSLATION STATUS"); bool translated = false; var translation_status_message = "\t{0} | progress: => {1}%"; for (int i = 0; i < 50 && !translated; i++) { System.Threading.Thread.Sleep(3000); var status = lingotek.checkTranslationStatus(documentId, locale).Result; Console.WriteLine(translation_status_message, i, status); if (status == 100) { translated = true; } } if (!translated) { Console.WriteLine("\tDocument never completed translation."); Environment.Exit(3); } // Download the translation of our document. Console.WriteLine("DOWNLOAD TRANSLATION"); lingotek.downloadTranslation(documentId, locale).Wait(); // Delete document from the server. Console.WriteLine("CLEANUP"); lingotek.delete(documentId).Wait(); } }
/// <summary> /// Creates a new IODocument. /// </summary> public IODocument() { Metadata = new DocumentMetadata(); Components = new List<IOComponent>(); Wires = new List<IOWire>(); }