public void DataEnumerator_1000ValuesInData_1000ValuesReturned() { // arrange IEntity entityMock = this.mocks.NewMock<IEntity>(); EntityPropertyStorage storage = new EntityPropertyStorage( entityMock ); int times = 1000; for ( int i = 0; i < times; i++ ) { storage.MainDataStorage.Add( "test_" + i, new object() ); } int enumCount = 0; // act foreach ( KeyValuePair<string, object> kvp in storage.Data ) { enumCount++; } // assert Assert.AreEqual( times, enumCount ); }
public void EntityPropertyStorage_OwnerEntityNull_RaiseArgumentNullException() { // arrange IEntity entityNull = null; EntityPropertyStorage storage; // act storage = new EntityPropertyStorage( entityNull ); // assert }
public void SwapAndFlush_100ThenFlushThen30PublicationsFromSingleThreads_100ValuesToMainDataThen30Updates() { // arrange IEntity entityMock = this.mocks.NewMock<IEntity>(); EntityPropertyStorage storage = new EntityPropertyStorage( entityMock ); int times = 100; IList<Thread> threads = new List<Thread>(); for ( int i = times; i > 0; i-- ) { string key = "test_" + i; Thread t = new Thread( x => { Thread.Sleep( i * 16 ); storage.Publicize( key, new object() ); } ); threads.Add( t ); t.Start(); } foreach ( Thread t in threads ) { t.Join(); } threads.Clear(); Assert.AreEqual( times, storage.UnstableBufferStorage.Count ); // act storage.SwapAndFlush(); Assert.AreEqual( 0, storage.UnstableBufferStorage.Count ); Assert.AreEqual( times, storage.MainDataStorage.Count ); times = 30; for ( int i = times; i > 0; i-- ) { if ( i == 15 ) { Thread swapT = new Thread ( (object x) => { Thread.Sleep( (int)x ); storage.SwapAndFlush(); } ); threads.Add( swapT ); swapT.Start(i); } string key = "test_" + i; Thread t = new Thread( x => { Thread.Sleep( i * 56 ); storage.Publicize( key, new object() ); } ); threads.Add( t ); t.Start(); } foreach ( Thread t in threads ) { t.Join(); } threads.Clear(); Assert.AreEqual( times, storage.UnstableBufferStorage.Count + storage.StableBufferStorage.Count ); storage.SwapAndFlush(); // assert Assert.AreEqual( 0, storage.UnstableBufferStorage.Count ); Assert.AreEqual( 100, storage.MainDataStorage.Count ); }
public void Publicize_2SameKeys_RaiseBufferPublicationException() { // arrange IEntity entityMock = this.mocks.NewMock<IEntity>(); EntityPropertyStorage storage = new EntityPropertyStorage( entityMock ); string key = "testData"; object data = new object(); int times = 2; // act for ( int i = times; i > 0; i-- ) { storage.Publicize( key, data ); } // assert }
public void Publicize_1000ValidKeyValidData_1000Stored() { // arrange IEntity entityMock = this.mocks.NewMock<IEntity>(); EntityPropertyStorage storage = new EntityPropertyStorage( entityMock ); int times = 1000; // act for(int i = 0; i < times; i++) { storage.Publicize( "test_" + i, new object() ); } // assert Assert.AreEqual( times, storage.UnstableBufferStorage.Count ); }
public void EntityPropertyStorage_ValidOwnerEntity_Success() { // arrange IEntity entityMock = this.mocks.NewMock<IEntity>(); EntityPropertyStorage storage; // act storage = new EntityPropertyStorage( entityMock ); // assert Assert.IsNotNull( storage ); Assert.IsInstanceOf<EntityPropertyStorage>( storage ); Assert.AreEqual( entityMock, storage.Owner ); }