public void ChangeEntry_InvalidIndexValidComponent_IndexOutOfRangeException() { IStorage <UnitTestComponent> storage = new Storage <UnitTestComponent>(); UnitTestComponent component = new UnitTestComponent(); Assert.Throws <IndexOutOfRangeException>(() => storage.ChangeEntry(0, component)); }
public void DestroyAllEntitiesWithComponents_NoParameter_Successful() { Mock <ICacheManager> cacheManagerMock = new Mock <ICacheManager>(); Mock <IStorageManager> storageManagerMock = new Mock <IStorageManager>(); IContext context = new Context(cacheManagerMock.Object, storageManagerMock.Object); UnitTestComponent component = new UnitTestComponent(); UnitTestComponent2 component2 = new UnitTestComponent2(); cacheManagerMock.Setup((cm) => cm.GetItemFromCache <Entity>()).Returns(new Entity()); cacheManagerMock.Setup((cm) => cm.GetItemFromCache <UnitTestComponent>()).Returns(component); cacheManagerMock.Setup((cm) => cm.GetItemFromCache <UnitTestComponent2>()).Returns(component2); IEntity entity = context.CreateEntity(); IEntity entity2 = context.CreateEntity(); entity.AddComponent <UnitTestComponent>(); entity2.AddComponent <UnitTestComponent2>(); cacheManagerMock.Setup(cm => cm.AddItemToCache(It.Is <Entity>(e => e.Equals(entity)))).Verifiable(); cacheManagerMock.Setup(cm => cm.AddItemToCache(It.Is <object>(c => c.Equals(component)))).Verifiable(); cacheManagerMock.Setup(cm => cm.AddItemToCache(It.Is <object>(c => c.Equals(component2)))).Verifiable(); context.DestroyAllEntities(); cacheManagerMock.VerifyAll(); }
public void TestCreateNewMultipleStorageView_NoResultsExpected() { Mock <IStorageManager> storageManagerMock = new Mock <IStorageManager>(); Mock <IStorage <UnitTestComponent> > storageMock = new Mock <IStorage <UnitTestComponent> >(); Mock <IStorage <UnitTestComponent2> > storage2Mock = new Mock <IStorage <UnitTestComponent2> >(); UnitTestComponent component = new UnitTestComponent(); UnitTestComponent2 component2 = new UnitTestComponent2(); int number = 0; List <ValueTuple <UnitTestComponent, UnitTestComponent2> > resultingComponents = new List <ValueTuple <UnitTestComponent, UnitTestComponent2> >(); storageManagerMock.Setup(sm => sm.GetStorage <UnitTestComponent2>()).Returns(storage2Mock.Object); storageManagerMock.Setup(sm => sm.GetStorage <UnitTestComponent>()).Returns(storageMock.Object); storageManagerMock.Setup(sm => sm.DataLength).Returns(5); storageMock.Setup(s => s.GetEntry(It.IsIn(0, 1, 4))).Returns(component); storage2Mock.Setup(s => s.GetEntry(It.IsIn(2, 3))).Returns(component2); Func <IStorageManager, IEnumerable <ValueTuple <UnitTestComponent, UnitTestComponent2> > > storageView = StorageViewBuilder.CreateNewStorageView <ValueTuple <UnitTestComponent, UnitTestComponent2> >(); foreach (ValueTuple <UnitTestComponent, UnitTestComponent2> result in storageView(storageManagerMock.Object)) { resultingComponents.Add(result); number++; } storageMock.Verify(s => s.GetEntry(It.IsAny <int>()), Times.Exactly(5)); storage2Mock.Verify(s => s.GetEntry(It.IsAny <int>()), Times.Exactly(3)); Assert.Equal(0, number); Assert.Empty(resultingComponents); }
public void UpdateFamily_AddFatherAndAMother_ThePatientHasAFatherAndAMother() { var cmp = new UnitTestComponent(this.Session); var users = cmp.GetPatientsByNameLight("*", SearchOn.FirstAndLastName); Assert.Greater(users.Count, 4, "Not enought data to execute the test"); var family = new FamilyDto() { Current = users[0], }; family.Father = users[1]; this.ComponentUnderTest.AddNewParent(users[1], users[2]); var persistedFamily = this.ComponentUnderTest.GetFamily(users[0]); Assert.AreEqual(users[1].Id, family.Father.Id, "The father has an unexpected ID"); var family2 = new FamilyDto() { Current = users[0], }; family.Mother = users[2]; this.ComponentUnderTest.AddNewParent(users[1], users[3]); var persistedFamily2 = this.ComponentUnderTest.GetFamily(users[0]); Assert.AreEqual(users[1].Id, family.Father.Id, "The father has an unexpected ID"); Assert.AreEqual(users[2].Id, family.Mother.Id, "The child has an unexpected ID"); }
public void TestAdd_ValidObjectAsObject_Successful() { Cache <UnitTestComponent> cache = new Cache <UnitTestComponent>(); UnitTestComponent component = new UnitTestComponent(); cache.Add((object)component); Assert.Equal(1, cache.Count); }
public void TestGetNext_FilledCache_ReusedObject() { Cache <UnitTestComponent> cache = new Cache <UnitTestComponent>(); UnitTestComponent component = new UnitTestComponent(); cache.Add(component); Assert.Equal(component, cache.GetNext()); Assert.Equal(0, cache.Count); }
public void TestAddItemToCache_TypeValidItem_Successful() { ICacheManager cacheManager = new CacheManager(); IComponent component = new UnitTestComponent(); cacheManager.AddItemToCache(component); Assert.True(cacheManager.HasItemInCache <UnitTestComponent>()); }
public void GetEntry_ValidIndexExistingComponent_ComponentData() { IStorage <UnitTestComponent> storage = new Storage <UnitTestComponent>(); UnitTestComponent component = new UnitTestComponent(); storage.AddEntry(); storage.ChangeEntry(0, component); Assert.Equal(component, storage.GetEntry(0)); }
public void IsComponentAvailable_ValidIndexComponent_True() { IStorage <UnitTestComponent> storage = new Storage <UnitTestComponent>(); UnitTestComponent component = new UnitTestComponent(); storage.AddEntry(); storage.ChangeEntry(0, component); Assert.True(storage.IsComponentAvailable(0)); }
public void TestAddItemToCache_UnittestComponentNoregisteredItems_NewItem() { ICacheManager cacheManager = new CacheManager(); UnitTestComponent result = cacheManager.GetItemFromCache <UnitTestComponent>(); Assert.False(cacheManager.HasItemInCache <UnitTestComponent>()); Assert.NotNull(result); Assert.IsType <UnitTestComponent>(result); }
public void TestGetItemToCache_UnittestComponentRegisteredItems_Successful() { ICacheManager cacheManager = new CacheManager(); UnitTestComponent component = new UnitTestComponent(); cacheManager.AddItemToCache(component); UnitTestComponent result = cacheManager.GetItemFromCache <UnitTestComponent>(); Assert.False(cacheManager.HasItemInCache <UnitTestComponent>()); Assert.Equal(component, result); }
public void TestCreateComponent_NoParameter_ValidComponent() { Mock <ICacheManager> cacheManagerMock = new Mock <ICacheManager>(); Mock <IStorageManager> storageManagerMock = new Mock <IStorageManager>(); IContext context = new Context(cacheManagerMock.Object, storageManagerMock.Object); UnitTestComponent component = new UnitTestComponent(); cacheManagerMock.Setup((cm) => cm.GetItemFromCache <UnitTestComponent>()).Returns(component); UnitTestComponent result = context.CreateComponent <UnitTestComponent>(); cacheManagerMock.Verify((cm) => cm.GetItemFromCache <UnitTestComponent>(), Times.Once); Assert.Equal(component, result); }
public void RemoveEntry_ValidIndexExistingComponent_Successful() { IStorage <UnitTestComponent> storage = new Storage <UnitTestComponent>(); UnitTestComponent component = new UnitTestComponent(); storage.AddEntry(); storage.ChangeEntry(0, component); var e = Assert.Raises <StorageEntryEventArgs>(handler => storage.EntryRemoved += handler, handler => storage.EntryRemoved -= handler, () => storage.RemoveEntry(0)); Assert.Equal(0, e.Arguments.Index); Assert.Equal(component, e.Arguments.Value); }
public void TestAddComponent_ValidExistingComponent_ThrowsArgumentException() { Entity entity = new Entity(); UnitTestComponent component = new UnitTestComponent(); void handler(object sender, ComponentRequestEventArgs args) => args.SetComponent(component); entity.ComponentRequested += handler; entity.AddComponent <UnitTestComponent>(); Assert.Throws <ArgumentException>(() => entity.AddComponent <UnitTestComponent>()); entity.ComponentRequested -= handler; Assert.Single(entity.Components); Assert.Contains(component, entity.Components); }
public void ChangeEntry_ValidIndexValidComponent_Successful() { IStorage <UnitTestComponent> storage = new Storage <UnitTestComponent>(); UnitTestComponent component = new UnitTestComponent(); storage.AddEntry(); var e = Assert.Raises <StorageEntryChangedEventArgs>(handler => storage.EntryChanged += handler, handler => storage.EntryChanged -= handler, () => storage.ChangeEntry(0, component)); Assert.Equal(0, e.Arguments.Index); Assert.Null(e.Arguments.Value); Assert.Equal(component, e.Arguments.NewValue); Assert.Equal(component, storage.GetEntry(0)); }
public void TestRemoveComponent_ValidExistingComponent_ComponentRemoveSuccessfully() { Entity entity = new Entity(); UnitTestComponent component = new UnitTestComponent(); void handler(object sender, ComponentRequestEventArgs args) => args.SetComponent(component); entity.ComponentRequested += handler; entity.AddComponent <UnitTestComponent>(); var e = Assert.Raises <ComponentEventArgs>(handler => entity.ComponentRemoved += handler, handler => entity.ComponentRemoved -= handler, () => entity.RemoveComponent <UnitTestComponent>()); entity.ComponentRequested -= handler; Assert.Empty(entity.Components); }
public void TestAddComponent_ValidNonExistingComponent_ComponentSuccessfullyAdded() { Entity entity = new Entity(); UnitTestComponent component = new UnitTestComponent(); void handler(object sender, ComponentRequestEventArgs args) => args.SetComponent(component); entity.ComponentRequested += handler; var added = Assert.RaisesAny <ComponentEventArgs>(handler => entity.ComponentAdded += handler, handler => entity.ComponentAdded -= handler, () => entity.AddComponent <UnitTestComponent>()); entity.ComponentRequested -= handler; Assert.Single(entity.Components); Assert.Contains(component, entity.Components); Assert.Equal(component, added.Arguments.Component); }
public void TestDestroy_AllEventsThrown() { Entity entity = new Entity(); UnitTestComponent component = new UnitTestComponent(); void handler(object sender, ComponentRequestEventArgs args) => args.SetComponent(component); entity.ComponentRequested += handler; entity.AddComponent <UnitTestComponent>(); var e = Assert.Raises <ComponentEventArgs>(handler => entity.ComponentRemoved += handler, handler => entity.ComponentRemoved -= handler, () => entity.Destroy()); entity.ComponentRequested -= handler; Assert.Empty(entity.Components); Assert.Equal(component, e.Arguments.Component); }
public void TestDestroyEntityWithComponents_ValidEntity_EntitySuccessfullyDestroyed() { Mock <ICacheManager> cacheManagerMock = new Mock <ICacheManager>(); Mock <IStorageManager> storageManagerMock = new Mock <IStorageManager>(); IContext context = new Context(cacheManagerMock.Object, storageManagerMock.Object); UnitTestComponent component = new UnitTestComponent(); cacheManagerMock.Setup((cm) => cm.GetItemFromCache <Entity>()).Returns(new Entity()); cacheManagerMock.Setup((cm) => cm.GetItemFromCache <UnitTestComponent>()).Returns(component); IEntity entity = context.CreateEntity(); entity.AddComponent <UnitTestComponent>(); cacheManagerMock.Setup(cm => cm.AddItemToCache(It.Is <Entity>(e => e.Equals(entity)))).Verifiable(); cacheManagerMock.Setup(cm => cm.AddItemToCache(It.Is <object>(c => c.Equals(component)))).Verifiable(); context.DestroyEntity(entity); cacheManagerMock.VerifyAll(); }
public void UpdateFamily_AddMotherAndChangeIt_ThePatientHasANewMother() { var cmp = new UnitTestComponent(this.Session); var users = cmp.GetPatientsByNameLight("*", SearchOn.FirstAndLastName); var mother1 = this.CreateNewPatient(Guid.NewGuid().ToString(), Gender.Female); var mother2 = this.CreateNewPatient(Guid.NewGuid().ToString(), Gender.Female); cmp.Create(mother1); cmp.Create(mother2); this.ComponentUnderTest.AddNewParent(users[0], mother1); var persistedFamily = this.ComponentUnderTest.GetFamily(users[0]); Assert.AreEqual(mother1.Id, persistedFamily.Mother.Id, "The father has an unexpected ID"); this.ComponentUnderTest.AddNewParent(users[0], mother2); var persistedFamily2 = this.ComponentUnderTest.GetFamily(users[0]); Assert.AreEqual(mother2.Id, persistedFamily2.Mother.Id, "The father has an unexpected ID"); }