Compare() private method

private Compare ( object object1, object object2 ) : bool
object1 object
object2 object
return bool
Ejemplo n.º 1
1
        public void TestPartSerialzationDeserialization()
        {
            SceneObjectPart rootPart = new SceneObjectPart(UUID.Zero, new OpenSim.Framework.PrimitiveBaseShape(), new Vector3(1, 2, 3), Quaternion.Identity, Vector3.Zero, false);
            rootPart.Name = "RootPart";
            SceneObjectPart part = Util.RandomSOP("ChildPart", 2);

            var pgrp1 = new SceneObjectGroup(rootPart);
            pgrp1.AddPart(part);

            part.InventorySerial = 1;
            part.Rezzed = DateTime.Now;
            part.TextColor = System.Drawing.Color.FromArgb(1,2,3,4);
            
            byte[] bytes = serEngine.SceneObjectSerializer.SerializePartToBytes(part, OpenSim.Region.Framework.Scenes.Serialization.SerializationFlags.None);

            SceneObjectPart rootPart2 = new SceneObjectPart(UUID.Zero, new OpenSim.Framework.PrimitiveBaseShape(), new Vector3(1, 2, 3), Quaternion.Identity, Vector3.Zero, false);
            rootPart2.Name = "RootPart2";
            SceneObjectPart deserPart = serEngine.SceneObjectSerializer.DeserializePartFromBytes(bytes);
            var pgrp2 = new SceneObjectGroup(rootPart2);
            pgrp2.AddPart(deserPart);
            deserPart.Rezzed = part.Rezzed;

            CompareObjects comp = new CompareObjects();
            comp.CompareStaticFields = false;
            comp.CompareStaticProperties = false;
            comp.ElementsToIgnore = PrimCompareIgnoreList;

            Assert.IsTrue(comp.Compare(part, deserPart), comp.DifferencesString);
        }
Ejemplo n.º 2
0
        public void Ingredients_PersistanceTest()
        {
            var compare = new CompareObjects();
            compare.IgnoreObjectTypes = true;

            InAutoRollbackTransaction(uof =>
                {
                    Ingredient ing = new Ingredient { StockQuantity = 1, PricePerUnit = 0.1M, NormalWeight = 1, Name = "ING", ExtraWeight = 2, Recipies = new List<Recipe>() };

                    uof.Db.Ingredients.Insert(ing);
                    uof.Db.Commit();
                    uof.Db.ObjectContext().DetachAll();

                    Ingredient ing2 = uof.Db.Ingredients.Get(ing.IngredientID);

                    Assert.IsTrue(ing != ing2);
                    Assert.IsTrue(compare.Compare(ing, ing2));

                    ing2.Name = "ING2";
                    uof.Db.Commit();
                    uof.Db.ObjectContext().DetachAll();

                    ing = uof.Db.Ingredients.Get(ing.IngredientID);
                    Assert.IsTrue(ing != ing2);
                    Assert.IsFalse(compare.Compare(ing, ing2));

                });
        }
        public void Template_InsertTemplate_SucessfullyInserted()
        {
            //Arrange
            Fixture fixture = new Fixture();
            var temp = fixture.CreateAnonymous<Template>();

            //Template temp = new Template
            //                    {
            //                        Name = "welcome",
            //                        Body = "Dear [FirstName], I'm glad you could join our family. Best Regards, Chuck Conway",
            //                        Title = "Welcome to Momntz"
            //                    };

            //Act
            Sessions.Artifact.Save(temp);
            Sessions.Artifact.Flush();

            Template temp2 = Sessions.Artifact.QueryOver<Template>()
                .Where((u) => u.Name == temp.Name)
                .SingleOrDefault();

            //Assert
            CompareObjects compare = new CompareObjects();
            bool equal = compare.Compare(temp, temp2);
            Assert.IsTrue(equal);
        }
Ejemplo n.º 4
0
        public void TestGroupSerializationDeserialization()
        {
            var sop1 = SceneUtil.RandomSOP("Root", 1);
            var sop2 = SceneUtil.RandomSOP("Child1", 2);
            var sop3 = SceneUtil.RandomSOP("Child2", 3);

            SceneObjectGroup group = new SceneObjectGroup(sop1);
            group.AddPart(sop2);
            group.AddPart(sop3);

            SceneObjectGroup deserGroup = null;
            string grpBytes = null;

            Assert.DoesNotThrow(() =>
            {
                grpBytes = SceneObjectSerializer.ToXml2Format(group, true);
            });

            Assert.NotNull(grpBytes);

            Assert.DoesNotThrow(() =>
            {
                deserGroup = SceneObjectSerializer.FromXml2Format(grpBytes);
            });

            CompareObjects comp = new CompareObjects();
            comp.CompareStaticFields = false;
            comp.CompareStaticProperties = false;
            comp.ElementsToIgnore = PrimCompareIgnoreList;

            Assert.IsTrue(comp.Compare(group, deserGroup), comp.DifferencesString);
        }
Ejemplo n.º 5
0
        public object CreateObject(string typeName, bool isSingleton = false, params object[] parameters)
        {
            var type = Type.GetType(typeName, true);
            if (isSingleton)
            {
                List<KeyValuePair<object[], object>> existingInsts;
                if (_instances.TryGetValue(type, out existingInsts) && existingInsts != null)
                {
                    var compareObjects = new CompareObjects();
                    var instance = existingInsts.FirstOrDefault(ei => compareObjects.Compare(ei.Key, parameters));

                    if (!instance.Equals(default(KeyValuePair<object[], object>)))
                    {
                        return instance.Value;
                    }
                }
                else
                {
                    existingInsts = new List<KeyValuePair<object[], object>>();
                    _instances.Add(type, existingInsts);
                }

                var newInst = Activator.CreateInstance(type, parameters);
                existingInsts.Add(new KeyValuePair<object[], object>(parameters, newInst));
                return newInst;
            }
            return Activator.CreateInstance(type, parameters);
        }
Ejemplo n.º 6
0
 public void given_a_GET_request_for_session_speakers_it_returns_speakers()
 {
     var speakers = GetConferenceSessionSpeakers(codemashs.slug, phonegap.slug);
       var compareObjects = new CompareObjects();
       var areSame = compareObjects.Compare(speakers, phonegap.speakers);
       if (!areSame)
       {
     Assert.Fail(compareObjects.DifferencesString);
       }
 }
Ejemplo n.º 7
0
 public void given_a_GET_request_for_a_single_session_it_returns_a_session_with_child_collections()
 {
     var session = GetConferenceSession(codemashs.slug, phonegap.slug);
       var compareObjects = new CompareObjects();
       var areSame = compareObjects.Compare(session, phonegap);
       if (!areSame)
       {
     Assert.Fail(compareObjects.DifferencesString);
       }
 }
        public static void ShouldBeEqualTo(this ISomeServiceComplexRequest m1, ISomeServiceComplexRequest m2)
        {
            var comparer = new CompareObjects();
            comparer.ElementsToIgnore.Add("IsPooled");

            if(!comparer.Compare(m1, m2))
            {
                throw new Exception("Messages are not equal, Details:" + comparer.DifferencesString);
            }
        }
Ejemplo n.º 9
0
 public void given_a_GET_request_for_conference_speakers_it_returns_all_speakers()
 {
     var speakers = GetConferenceSpeakers(codemashs.slug);
       var compareObjects = new CompareObjects();
       var areSame = compareObjects.Compare(speakers.Count, 100);
       if (!areSame)
       {
     Assert.Fail(compareObjects.DifferencesString);
       }
 }
Ejemplo n.º 10
0
 public void given_a_GET_request_for_resources_it_returns_resources()
 {
     var resources = GetConferenceSessionResources(codemashs.slug, phonegap.slug);
       var compareObjects = new CompareObjects();
       var areSame = compareObjects.Compare(resources, new List<string>());
       if (!areSame)
       {
     Assert.Fail(compareObjects.DifferencesString);
       }
 }
Ejemplo n.º 11
0
 public void given_a_GET_request_for_a_single_conference_it_returns_general_info_with_a_link_to_sessions()
 {
     var conference = GetConference(new ConferencesRequest() { conferenceSlug = codemash.slug } );
       var compareObjects = new CompareObjects();
       var areSame = compareObjects.Compare(conference, codemash);
       if (!areSame)
       {
     Assert.Fail(compareObjects.DifferencesString);
       }
 }
Ejemplo n.º 12
0
 public void given_a_GET_request_for_a_single_conference_sessions_it_returns_sessions_with_speakers()
 {
     var sessions = GetConferenceSessions(codemashs.slug);
       var compareObjects = new CompareObjects();
       var areSame = compareObjects.Compare(sessions.Count, 156);
       if (!areSame)
       {
     Assert.Fail(compareObjects.DifferencesString);
       }
 }
Ejemplo n.º 13
0
 public void given_a_GET_request_for_a_single_session_speaker_it_returns_the_speaker()
 {
     var speaker = GetConferenceSessionSpeaker(codemashs.slug, phonegap.slug, andrewGlover.slug);
       var compareObjects = new CompareObjects();
       var areSame = compareObjects.Compare(speaker, andrewGlover);
       if (!areSame)
       {
     Assert.Fail(compareObjects.DifferencesString);
       }
 }
Ejemplo n.º 14
0
 public void given_a_GET_request_for_all_conferences_it_returns_subset_of_conference_info()
 {
     //GetConferences().FirstOrDefault().IsTheSameAs(codemashs).ShouldBeTrue();
       var conference = GetConferences(new ConferencesRequest()).FirstOrDefault();
       var compareObjects = new CompareObjects();
       var areSame = compareObjects.Compare(conference, codemashs);
       if (!areSame)
       {
     Assert.Fail(compareObjects.DifferencesString);
       }
 }
Ejemplo n.º 15
0
 public void given_a_GET_request_for_a_schedule_it_returns_the_schedule_with_sessions()
 {
     //GetConferences().FirstOrDefault().IsTheSameAs(codemashs).ShouldBeTrue();
       var schedule = GetSchedule(new ScheduleRequest() { conferenceSlug = "CodeMash-2012", userSlug = "rob-gibbens" });
       var compareObjects = new CompareObjects();
       var areSame = compareObjects.Compare(schedule, robsSchedule);
       if (!areSame)
       {
     Assert.Fail(compareObjects.DifferencesString);
       }
 }
		public void CompareUnmatchedParents()
		{
			var parent1 = new Parent("Parent1", 1, 2);
			var parent2 = new Parent("Parent2", 1, 2);

			var comparer = new CompareObjects();

			bool compare = comparer.Compare(parent1, parent2);

			Assert.IsTrue(compare, comparer.DifferencesString);
		}
		public void CompareMatchedParents()
		{
			var parent1 = new Parent("Parent1", 1, 2);
			var parent2 = new Parent("Parent1", 1, 2);

			var comparer = new CompareObjects();
			AddIgnoreElements(comparer, "Key");

			bool compare = comparer.Compare(parent1, parent2);

			Assert.IsTrue(compare, comparer.DifferencesString);
		}
Ejemplo n.º 18
0
        /// <summary>
        /// Performs a deep comparison and returns true if the objects are equal. Assert fails if they are  not.
        /// </summary>
        /// <param name="expected">Expected value.</param>
        /// <param name="actual">Actual value.</param>
        public static void AreEqual(object expected, object actual)
        {
            CompareObjects comparer = new CompareObjects();
            bool result = comparer.Compare(expected, actual);

            // if they're different, list the differences
            if (result == false)
            {
                StringBuilder message = new StringBuilder();
                foreach (string difference in comparer.Differences)
                    message.Append(difference);
                throw new AssertFailedException("Objects are not equal. " + message.ToString());
            }
        }
		public void CompareIgnoreChildParents()
		{
			var parent1 = new Parent("Parent1", 1, 2);
			parent1.AddChild("Child1", 1);

			var parent2 = new Parent("Parent1", 1, 2);

			var comparer = new CompareObjects();
			AddIgnoreElements(comparer, "Key", "m_Children");

			bool compare = comparer.Compare(parent1, parent2);

			Assert.IsTrue(compare, comparer.DifferencesString);
		}
        public void DocumentationTest()
        {
            //This is the comparison class
            CompareObjects compareObjects = new CompareObjects();

            //Create a couple objects to compare
            Person person1 = new Person();
            person1.DateCreated = DateTime.Now;
            person1.Name = "Greg";

            Person person2 = new Person();
            person2.Name = "John";
            person2.DateCreated = person1.DateCreated;

            //These will be different, write out the differences
            if (!compareObjects.Compare(person1, person2))
                Console.WriteLine(compareObjects.DifferencesString);
        }
Ejemplo n.º 21
0
        private void CompareRecordInfo(IRecordInfo recordInfo1, IRecordInfo recordInfo2)
        {
            var comp = new CompareObjects();
            comp.CompareChildren = true;
            comp.ElementsToIgnore.Add("Cache");
            comp.ElementsToIgnore.Add("RecordType");
            comp.ElementsToIgnore.Add("FieldTypeInternal");
            comp.ElementsToIgnore.Add("FieldInfo");
            comp.ElementsToIgnore.Add("Operations");

            comp.ElementsToIgnore.Add("FieldType");
            comp.ElementsToIgnore.Add("TypeId");

            comp.CompareFields = true;
            //comp.ComparePrivateFields = true;
            comp.ComparePrivateProperties = true;
            comp.CompareReadOnly = true;

            Check.That(comp.Compare(recordInfo1, recordInfo2)).IsTrue();
        }
Ejemplo n.º 22
0
        public void TestGroupInventorySerializationDeserialization()
        {
            var sop1 = Util.RandomSOP("Root", 1);
            var sop2 = Util.RandomSOP("Child1", 2);
            var sop3 = Util.RandomSOP("Child2", 3);

            SceneObjectGroup group = new SceneObjectGroup(sop1);
            group.AddPart(sop2);
            group.AddPart(sop3);

            var grpBytes = serEngine.InventoryObjectSerializer.SerializeGroupToInventoryBytes(group, SerializationFlags.None);

            SceneObjectGroup deserGroup = serEngine.InventoryObjectSerializer.DeserializeGroupFromInventoryBytes(grpBytes);

            CompareObjects comp = new CompareObjects();
            comp.CompareStaticFields = false;
            comp.CompareStaticProperties = false;
            comp.ElementsToIgnore = PrimCompareIgnoreList;

            Assert.IsTrue(comp.Compare(group, deserGroup), comp.DifferencesString);
        }
Ejemplo n.º 23
0
        public void Test()
        {
            var newMessages = new List<object>();
            var bus = new MessageBus();
            bus.RegisterHandler<object>(newMessages.Add);

            var eventStore = new InMemoryEventStore(bus, GivenTheseEvents());
            var repository = new DomainRepository(eventStore);

            RegisterHandler(bus, repository);

            try
            {
                bus.Handle(WhenThisHappens());
            }
            catch(Exception e)
            {
                var expectedException = ThisExceptionShouldOccur();
                if(expectedException == null)
                    Assert.Fail(e.Message);

                if(expectedException.GetType().IsAssignableFrom(e.GetType()))
                {
                    Assert.AreEqual(expectedException.Message, e.Message);
                    return;
                }

                Assert.Fail("Expected exception of type {0} with message {1} but got exception of type {2} with message {3}", expectedException.GetType(), expectedException.Message, e.GetType(), e.Message);
            }

            var expectedEvents = TheseEventsShouldOccur().ToList();

            var comparer = new CompareObjects();

            if(!comparer.Compare(expectedEvents, newMessages))
            {
                Assert.Fail(comparer.DifferencesString);
            }
        }
        public SavedCommandItem AddCommand(object command, string serviceBus, string transport, string server, string queue)
        {
            SavedCommandItem item = null;

              var co = new CompareObjects();

              foreach( var c in _items ) {

            if( co.Compare(c.SentCommand, command) ) {
              item = c; // TODO: When we show what ServiceBus/Server/Queue the command has been sent to,
              // then also compare those values
              break;
            }
              }

              if( item == null ) {
            item = new SavedCommandItem(command.GetType().GetDisplayName(command).CutEnd(70), null, false, DateTime.Now);

            SavedCommand2 cmd = new SavedCommand2();
            cmd.Command = command;

            cmd.ServiceBus = serviceBus;
            cmd.Transport = transport;
            cmd.Server = server;
            cmd.Queue = queue;

            item.SetCommand(cmd);

            _items.Insert(0, item);
              }

              item.LastSent = DateTime.Now;

              Save();

              return item;
        }
Ejemplo n.º 25
0
        public void TestBasicCacheRetrieval()
        {
            Cache.DiskWriteBackCache wbc = new Cache.DiskWriteBackCache();

            AssetBase baseAsset = new AssetBase();

            baseAsset.Data = new byte[] { 0xA, 0x9, 0x8, 0x7, 0x6, 0x5, 0xA, 0x9, 0x8, 0x7, 0x6, 0x5 };
            baseAsset.Name = "Name";
            baseAsset.Description = "Description";
            baseAsset.FullID = UUID.Random();
            baseAsset.Local = true;
            baseAsset.Temporary = true;
            baseAsset.Type = 5;
            baseAsset.Metadata.CreationDate = DateTime.Now;

            var stAsset = StratusAsset.FromAssetBase(baseAsset);

            wbc.StoreAsset(stAsset);

            CompareObjects comp = new CompareObjects();
            comp.CompareStaticFields = false;
            comp.CompareStaticProperties = false;

            var cacheAsset = wbc.GetAsset(baseAsset.FullID.Guid);

            Assert.IsTrue(comp.Compare(cacheAsset, stAsset), comp.DifferencesString);
            CollectionAssert.AreEqual(cacheAsset.Data, stAsset.Data);
        }
Ejemplo n.º 26
0
        public void TestCFTimeoutAndWritePathWithImmediateStaleDeletes()
        {
            if (!_runTests) return;

            //delete any leftover files in the writeback cache
            foreach (var file in Directory.EnumerateFiles("cache/cf_writeback"))
            {
                File.Delete(file);
            }

            AssetBase baseAsset = new AssetBase();

            baseAsset.Data = new byte[] { 0xA, 0x9, 0x8, 0x7, 0x6, 0x5, 0xA, 0x9, 0x8, 0x7, 0x6, 0x5 };
            baseAsset.Name = "Name";
            baseAsset.Description = "Description";
            baseAsset.FullID = UUID.Random();
            baseAsset.Local = true;
            baseAsset.Temporary = true;
            baseAsset.Type = 5;
            baseAsset.Metadata.CreationDate = DateTime.Now;

            try
            {
                Config.Settings.Instance.UnitTest_ThrowTimeout = true;
                Config.Settings.Instance.UnitTest_DeleteOldCacheFilesImmediately = true;

                _client.StoreAsset(baseAsset);

                System.Threading.Thread.Sleep(5000);

                //confirm the asset is now missing from the writeback cache
                Assert.IsNull(_client.DiskWriteBackCache.GetAsset(baseAsset.FullID.Guid));
            }
            finally
            {
                Config.Settings.Instance.UnitTest_ThrowTimeout = false;
                Config.Settings.Instance.UnitTest_DeleteOldCacheFilesImmediately = false;
            }

            //we should now be able to get the asset from CF since it should've been written back
            //by the write back recovery code
            AssetBase cfAsset = _client.RequestAssetSync(baseAsset.FullID);

            CompareObjects comp = new CompareObjects();
            comp.CompareStaticFields = false;
            comp.CompareStaticProperties = false;

            Assert.IsTrue(comp.Compare(baseAsset, cfAsset), comp.DifferencesString);
            CollectionAssert.AreEqual(baseAsset.Data, cfAsset.Data);
        }
Ejemplo n.º 27
0
        public void TestWriteToCF()
        {
            if (!_runTests) return;

            //delete any leftover files in the writeback cache
            foreach (var file in Directory.EnumerateFiles("cache/cf_writeback"))
            {
                File.Delete(file);
            }

            Cache.DiskWriteBackCache wbc = new Cache.DiskWriteBackCache();

            AssetBase baseAsset = new AssetBase();

            baseAsset.Data = new byte[] { 0xA, 0x9, 0x8, 0x7, 0x6, 0x5, 0xA, 0x9, 0x8, 0x7, 0x6, 0x5 };
            baseAsset.Name = "Name";
            baseAsset.Description = "Description";
            baseAsset.FullID = UUID.Random();
            baseAsset.Local = true;
            baseAsset.Temporary = true;
            baseAsset.Type = 5;
            baseAsset.Metadata.CreationDate = DateTime.Now;

            var stAsset = StratusAsset.FromAssetBase(baseAsset);

            wbc.StoreAsset(stAsset);

            wbc.DoWriteCycle();

            //the asset should still be in the WB cache
            Assert.IsNotNull(wbc.GetAsset(baseAsset.FullID.Guid));

            //... but we should now be able to get the asset from CF
            AssetBase cfAsset = _client.RequestAssetSync(baseAsset.FullID);

            CompareObjects comp = new CompareObjects();
            comp.CompareStaticFields = false;
            comp.CompareStaticProperties = false;

            Assert.IsTrue(comp.Compare(baseAsset, cfAsset), comp.DifferencesString);
            CollectionAssert.AreEqual(baseAsset.Data, cfAsset.Data);
        }
Ejemplo n.º 28
0
        public void TestWriteAndRetrieveAssets()
        {
            if (!_runTests) return;

            AssetBase baseAsset = new AssetBase();

            baseAsset.Data = new byte[] { 0xA, 0x9, 0x8, 0x7, 0x6, 0x5, 0xA, 0x9, 0x8, 0x7, 0x6, 0x5 };
            baseAsset.Name = "Name1234567 ΏΏ";
            baseAsset.Description = "Description TEstttt ΏΏΏÿÿ";
            baseAsset.FullID = UUID.Random();
            baseAsset.Local = true;
            baseAsset.Temporary = true;
            baseAsset.Type = 5;
            baseAsset.Metadata.CreationDate = DateTime.Now;

            int start = Environment.TickCount;
            _client.StoreAsset(baseAsset);
            Console.WriteLine("Time to store: {0}", Environment.TickCount - start);

            start = Environment.TickCount;
            AssetBase cfAsset = _client.RequestAssetSync(baseAsset.FullID);
            Console.WriteLine("Time to read: {0}", Environment.TickCount - start);

            CompareObjects comp = new CompareObjects();
            comp.CompareStaticFields = false;
            comp.CompareStaticProperties = false;

            Assert.IsTrue(comp.Compare(baseAsset, cfAsset), comp.DifferencesString);
            CollectionAssert.AreEqual(baseAsset.Data, cfAsset.Data);

            start = Environment.TickCount;
            //cleanup
            _client.PurgeAssetSync(baseAsset.FullID);
            Console.WriteLine("Time to purge: {0}", Environment.TickCount - start);
        }
Ejemplo n.º 29
0
        public void TestWriteThenReadManyTimes()
        {
            if (!_runTests) return;

            Random random = new Random();
            List<AssetBase> assets = new List<AssetBase>();

            int start;

            try
            {
                for (int i = 0; i < 25; i++)
                {
                    AssetBase baseAsset = new AssetBase();

                    var arr = new byte[512 * 1024];
                    random.NextBytes(arr);

                    baseAsset.Data = arr;
                    baseAsset.Name = "Name1234567 ΏΏ";
                    baseAsset.Description = "Description TEstttt ΏΏΏÿÿ";
                    baseAsset.FullID = UUID.Random();
                    baseAsset.Local = true;
                    baseAsset.Temporary = true;
                    baseAsset.Type = 5;
                    baseAsset.Metadata.CreationDate = DateTime.Now;

                    start = Environment.TickCount;
                    _client.StoreAsset(baseAsset);
                    Console.WriteLine("Time to store: {0}", Environment.TickCount - start);

                    assets.Add(baseAsset);
                }

                // Use ConcurrentQueue to enable safe enqueueing from multiple threads. 
                var exceptions = new ConcurrentQueue<Exception>();

                System.Threading.Tasks.Parallel.For(0, 10, i =>
                {
                    try
                    {
                        foreach (var baseAsset in assets)
                        {
                            start = Environment.TickCount;
                            AssetBase cfAsset = _client.RequestAssetSync(baseAsset.FullID);
                            Console.WriteLine("Time to read: {0}", Environment.TickCount - start);

                            CompareObjects comp = new CompareObjects();
                            comp.CompareStaticFields = false;
                            comp.CompareStaticProperties = false;

                            Assert.IsTrue(comp.Compare(baseAsset, cfAsset), comp.DifferencesString);
                            CollectionAssert.AreEqual(baseAsset.Data, cfAsset.Data);
                        }
                    }
                    catch (Exception e)
                    {
                        exceptions.Enqueue(e);
                    }
                });

                if (exceptions.Count > 0) throw new AggregateException(exceptions);
            }
            finally
            {
                foreach (var baseAsset in assets)
                {
                    start = Environment.TickCount;
                    //cleanup
                    _client.PurgeAssetSync(baseAsset.FullID);
                    Console.WriteLine("Time to purge: {0}", Environment.TickCount - start);
                }
            }
        }
Ejemplo n.º 30
0
        public void TestWriteTHENRetrieveLargeAssets()
        {
            if (!_runTests) return;

            Random random = new Random();
            List<AssetBase> assets = new List<AssetBase>();

            int start;

            try
            {
                for (int i = 0; i < 25; i++)
                {
                    AssetBase baseAsset = new AssetBase();

                    var arr = new byte[1 * 1024 * 1024];
                    random.NextBytes(arr);

                    baseAsset.Data = arr;
                    baseAsset.Name = "Name1234567 ΏΏ";
                    baseAsset.Description = "Description TEstttt ΏΏΏÿÿ";
                    baseAsset.FullID = UUID.Random();
                    baseAsset.Local = true;
                    baseAsset.Temporary = true;
                    baseAsset.Type = 5;
                    baseAsset.Metadata.CreationDate = DateTime.Now;

                    start = Environment.TickCount;
                    _client.StoreAsset(baseAsset);
                    Console.WriteLine("Time to store: {0}", Environment.TickCount - start);

                    assets.Add(baseAsset);
                }


                foreach (var baseAsset in assets)
                {
                    start = Environment.TickCount;
                    AssetBase cfAsset = _client.RequestAssetSync(baseAsset.FullID);
                    Console.WriteLine("Time to read: {0}", Environment.TickCount - start);

                    CompareObjects comp = new CompareObjects();
                    comp.CompareStaticFields = false;
                    comp.CompareStaticProperties = false;

                    Assert.IsTrue(comp.Compare(baseAsset, cfAsset), comp.DifferencesString);
                    CollectionAssert.AreEqual(baseAsset.Data, cfAsset.Data);
                }

            }
            finally
            {
                foreach (var baseAsset in assets)
                {
                    start = Environment.TickCount;
                    //cleanup
                    _client.PurgeAssetSync(baseAsset.FullID);
                    Console.WriteLine("Time to purge: {0}", Environment.TickCount - start);
                }
            }
        }