Exemplo n.º 1
0
        public void WhenTransformResultsHasAnError()
        {
            using (var ds = NewDocumentStore())
            {
                using (var s = ds.OpenSession())
                {
                    var entity = new User {
                        Name = "Ayende"
                    };
                    s.Store(entity);
                    s.Store(new User {
                        Name = "Oren", PartnerId = entity.Id
                    });
                    s.SaveChanges();
                }

                IndexCreation.CreateIndexes(
                    new CompositionContainer(new TypeCatalog(typeof(Users))),
                    ds);

                using (var s = ds.OpenSession())
                {
                    var exception = Assert.Throws <InvalidOperationException>(() => s.Query <User, Users>()
                                                                              .Customize(x => x.WaitForNonStaleResults())
                                                                              .Where(x => x.Name == "Ayende")
                                                                              .As <UserWithPartner>()
                                                                              .First());

                    dynamic dynamicNullObject = new DynamicNullObject();
                    var     expectedError     = Assert.Throws <RuntimeBinderException>(() => dynamicNullObject / 1);

                    Assert.Equal("The transform results function failed.\r\nDoc 'users/1', Error: " + expectedError.Message, exception.Message);
                }
            }
        }
Exemplo n.º 2
0
		public dynamic LoadDocument(string key)
		{
			if (key == null)
				return new DynamicNullObject();

			var source = Source;
			if (source == null)
				throw new ArgumentException(
					"LoadDocument can only be called as part of the Map stage of the index, but was called with " + key +
					" without a source.");
			var id = source.__document_id as string;
			if (string.IsNullOrEmpty(id))
				throw new ArgumentException(
					"LoadDocument can only be called as part of the Map stage of the index, but was called with " + key +
					" without a document. Current source: " + source);

			if (string.Equals(key, id))
				return source;

			HashSet<string> set;
			if(ReferencedDocuments.TryGetValue(id, out set) == false)
				ReferencedDocuments.Add(id, set = new HashSet<string>(StringComparer.OrdinalIgnoreCase));
			set.Add(key);

			dynamic value;
			if (docsCache.TryGetValue(key, out value))
				return value;

			var doc = database.Documents.Get(key, null);

			if (doc == null)
            {
			    log.Debug("Loaded document {0} by document {1} for index {2} could not be found", key, id, index);

				ReferencesEtags.Add(key, Etag.Empty);
				value = new DynamicNullObject();
            }
			else
			{
				log.Debug("Loaded document {0} with etag {3} by document {1} for index {2}\r\n{4}", key, id, index, doc.Etag, doc.ToJson());

				ReferencesEtags.Add(key, doc.Etag);
				value = new DynamicJsonObject(doc.ToJson());
			}

			docsCache[key] = value;
			return value;
		}
Exemplo n.º 3
0
        public dynamic LoadDocument(string key)
        {
            if (key == null)
            {
                return(new DynamicNullObject());
            }

            var source = Source;

            if (source == null)
            {
                throw new ArgumentException(
                          "LoadDocument can only be called as part of the Map stage of the index, but was called with " + key +
                          " without a source.");
            }
            var id = source.__document_id as string;

            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentException(
                          "LoadDocument can only be called as part of the Map stage of the index, but was called with " + key +
                          " without a document. Current source: " + source);
            }

            if (string.Equals(key, id))
            {
                return(source);
            }

            HashSet <string> set;

            if (ReferencedDocuments.TryGetValue(id, out set) == false)
            {
                ReferencedDocuments.Add(id, set = new HashSet <string>(StringComparer.OrdinalIgnoreCase));
            }
            set.Add(key);

            dynamic value;

            if (docsCache.TryGetValue(key, out value))
            {
                return(value);
            }

            var doc = database.Documents.Get(key, null);

            if (doc == null)
            {
                log.Debug("Loaded document {0} by document {1} for index {2} could not be found", key, id, index);

                ReferencesEtags.Add(key, Etag.Empty);
                value = new DynamicNullObject();
            }
            else
            {
                log.Debug("Loaded document {0} with etag {3} by document {1} for index {2}\r\n{4}", key, id, index, doc.Etag, doc.ToJson());

                ReferencesEtags.Add(key, doc.Etag);
                value = new DynamicJsonObject(doc.ToJson());
            }

            docsCache[key] = value;
            return(value);
        }