コード例 #1
0
        public void AddEntityThenDeleteFromDisk()
        {
            // Create test entity
            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entity = testRepository.Create();
                entity.Contents = new EntityTest {
                    Name = "foo", Number = 1
                };
                testRepository.Add(entity);
                testRepository.Save();
            }

            // Read the new entity from disk, then delete it and save
            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entityFromRepo = testRepository.Entities.FirstOrDefault(x => x.Contents.Name == "foo");
                Assert.IsNotNull(entityFromRepo);
                testRepository.Delete(entityFromRepo);
                testRepository.Save();
            }

            // After re-initializing the repo, the deleted item should be gone, but everything else should still be present
            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entityFromRepo = testRepository.Entities.FirstOrDefault(x => x.Contents.Name == "foo");
                Assert.IsNull(entityFromRepo);
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }
        }
コード例 #2
0
        public void AddEntityAndRetrieveFromDisk()
        {
            // Create test entity and write it to the mock filesystem
            IJsonEntity <EntityTest> entity;
            IJsonEntity <EntityTest> entityFromRepo;

            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                entity          = testRepository.Create();
                entity.Contents = new EntityTest {
                    Name = "foo", Number = 1
                };
                testRepository.Add(entity);
                testRepository.Save();
            }

            // Now re-create the repo, which should read the persisted value for the new entity from "disk"
            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                entityFromRepo = testRepository.Entities.FirstOrDefault(x => x.Contents.Name == "foo");
            }

            Assert.IsNotNull(entityFromRepo);
            Assert.AreEqual(entity.Id, entityFromRepo.Id);
            Assert.AreEqual(entity.Contents.Name, entityFromRepo.Contents.Name);
            Assert.AreEqual(entity.Contents.Number, entityFromRepo.Contents.Number);
        }
コード例 #3
0
        public void CallSaveWithNoPendingChanges()
        {
            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                testRepository.Save();
            }

            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }
        }
コード例 #4
0
        public void DeleteItemThatDoesNotExist()
        {
            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entity = testRepository.Create();
                testRepository.Delete(entity);
                testRepository.Save();
            }

            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }
        }
コード例 #5
0
        public void AddSameItemMoreThanOnce()
        {
            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entity = testRepository.Create();
                testRepository.Add(entity);
                testRepository.Add(entity);
                testRepository.Save();
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4, 5 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }

            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4, 5 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }
        }
コード例 #6
0
        public void UpdateTheSameItemMultipleTimes()
        {
            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entity = testRepository.Entities.First(x => x.Id == 1);
                entity.Contents.Name   = "newname1";
                entity.Contents.Number = -1;
                testRepository.Update(entity);
                entity.Contents.Name   = "newname2";
                entity.Contents.Number = -2;
                testRepository.Update(entity);
                testRepository.Save();
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }

            using (var testRepository = new DurableMemoryRepository <EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
                var entity = testRepository.Entities.First(x => x.Id == 1);
                Assert.AreEqual("newname2", entity.Contents.Name);
                Assert.AreEqual(-2, entity.Contents.Number);
            }
        }
コード例 #7
0
        public void UpdateTheSameItemMultipleTimes()
        {
            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entity = testRepository.Entities.First(x => x.Id == 1);
                entity.Contents.Name = "newname1";
                entity.Contents.Number = -1;
                testRepository.Update(entity);
                entity.Contents.Name = "newname2";
                entity.Contents.Number = -2;
                testRepository.Update(entity);
                testRepository.Save();
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }

            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
                var entity = testRepository.Entities.First(x => x.Id == 1);
                Assert.AreEqual("newname2", entity.Contents.Name);
                Assert.AreEqual(-2, entity.Contents.Number);
            }
        }
コード例 #8
0
        public void DeleteItemThatDoesNotExist()
        {
            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entity = testRepository.Create();
                testRepository.Delete(entity);
                testRepository.Save();
            }

            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }
        }
コード例 #9
0
        public void AddAndDeleteTheSameItemMultipleTimesInASession()
        {
            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entity = testRepository.Create();
                testRepository.Add(entity);
                testRepository.Delete(entity);
                testRepository.Add(entity);
                testRepository.Delete(entity);
                testRepository.Add(entity);
                testRepository.Delete(entity);
                testRepository.Add(entity);
                testRepository.Add(entity);
                testRepository.Delete(entity);
                testRepository.Delete(entity);
                testRepository.Save();
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }

            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }
        }
コード例 #10
0
        public void CallSaveWithNoPendingChanges()
        {
            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                testRepository.Save();
            }

            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }
        }
コード例 #11
0
        public void AddEntityThenDeleteFromDisk()
        {
            // Create test entity
            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entity = testRepository.Create();
                entity.Contents = new EntityTest { Name = "foo", Number = 1 };
                testRepository.Add(entity);
                testRepository.Save();
            }
            
            // Read the new entity from disk, then delete it and save
            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entityFromRepo = testRepository.Entities.FirstOrDefault(x => x.Contents.Name == "foo");
                Assert.IsNotNull(entityFromRepo);
                testRepository.Delete(entityFromRepo);
                testRepository.Save();
            }

            // After re-initializing the repo, the deleted item should be gone, but everything else should still be present
            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                var entityFromRepo = testRepository.Entities.FirstOrDefault(x => x.Contents.Name == "foo");
                Assert.IsNull(entityFromRepo);
                CollectionAssert.AreEquivalent(new[] { 1, 2, 4 }, testRepository.Entities.Select(x => x.Id).ToArray());
            }
        }
コード例 #12
0
        public void AddEntityAndRetrieveFromDisk()
        {
            // Create test entity and write it to the mock filesystem
            IJsonEntity<EntityTest> entity;
            IJsonEntity<EntityTest> entityFromRepo;
            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                entity = testRepository.Create();
                entity.Contents = new EntityTest {Name = "foo", Number = 1};
                testRepository.Add(entity);
                testRepository.Save();
            }

            // Now re-create the repo, which should read the persisted value for the new entity from "disk"
            using (var testRepository = new DurableMemoryRepository<EntityTest>(MockDataPath, _mockProvider.MockFileSystem.Object))
            {
                entityFromRepo = testRepository.Entities.FirstOrDefault(x => x.Contents.Name == "foo");
            }

            Assert.IsNotNull(entityFromRepo);
            Assert.AreEqual(entity.Id, entityFromRepo.Id);
            Assert.AreEqual(entity.Contents.Name, entityFromRepo.Contents.Name);
            Assert.AreEqual(entity.Contents.Number, entityFromRepo.Contents.Number);
        }