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);
        }
예제 #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);
        }
예제 #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");
     }
 }