public void AddsObjectsMetadataToHolder()
        {
            var object1 = new object();
            var object2 = new object();

            var metadata1 = new UriResolvedMetadata(new Uri("tst://p1/md1/vw1"), Substitute.For <IDisposable>());
            var metadata2 = new UriResolvedMetadata(new Uri("tst://p2/md2/vw2"), Substitute.For <IDisposable>());

            var holder = new UriResolvedObjectHolder();

            holder.Add(object1, metadata1);
            holder.Add(object2, metadata2);

            var holderMetadata1 = holder.GetMetadata(object1);
            var holderMetadata2 = holder.GetMetadata(object2);

            // Идентификатор назначается холдером, поэтому придется изменить
            // локальные метаданные, ипользуя сведения от GetMetadata.
            // Подобное допустимо, т.к. нас интересуют не идентификаторы,
            // а все остальные поля.
            metadata1 = metadata1.AssignId(holderMetadata1.ResolvedId);
            metadata2 = metadata2.AssignId(holderMetadata2.ResolvedId);

            Assert.AreEqual(metadata1, holderMetadata1);
            Assert.AreEqual(metadata2, holderMetadata2);
        }
Ejemplo n.º 2
0
        public void AssignIdReturnsTheSameMetadataWithTheSpecifiedId()
        {
            var metadata1 = new UriResolvedMetadata(new Uri("about:blank"), Substitute.For <IDisposable>());
            var metadata2 = metadata1.AssignId(1005);

            Assert.AreEqual(1005, metadata2.ResolvedId);
            Assert.AreEqual(metadata1.Disposable, metadata2.Disposable);
            Assert.AreEqual(metadata1.Uri, metadata2.Uri);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds the new object opened via an URI.
 /// </summary>
 /// <param name="resolved">The added object.</param>
 /// <param name="metadata">The metadata of the added object.</param>
 public void Add(object resolved, UriResolvedMetadata metadata)
 {
     try
     {
         this._data.Add(resolved, metadata.AssignId(this.GenerateNewId()));
     }
     catch (ArgumentException)
     {
         throw new ArgumentException(
                   string.Format(Properties.Resources.UriResolvedObjectAlreadyExists, resolved, typeof(IUriResolvedObjectHolder).Name),
                   "resolved");
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the class <see cref="UriResolvedMetadata"/>.
 /// </summary>
 /// <param name="source">The metadata used as a source for the new metadata.</param>
 /// <param name="resolvedId">The identifier of the object resolved via an URI.</param>
 private UriResolvedMetadata(UriResolvedMetadata source, int resolvedId)
 {
     this             = source;
     this._resolvedId = resolvedId;
 }
Ejemplo n.º 5
0
 public void Add(object resolved, UriResolvedMetadata metadata)
 {
     Contract.Requires <ArgumentNullException>(resolved != null);
     Contract.Requires <ArgumentNullException>(metadata.Uri != null);
     Contract.Requires <ArgumentNullException>(metadata.Disposable != null);
 }
 public void Initialize()
 {
     this._uriResolvedMetadata = new UriResolvedMetadata(new Uri("tst://p/m/v"), Substitute.For <IDisposable>());
 }