コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }