public void Update_Test() { var entities = new Dictionary <string, TestEntityOne> { { "3c0b80ed-6542-42c0-a3df-eef2d784011f", new TestEntityOne { Id = "3c0b80ed-6542-42c0-a3df-eef2d784011f", FieldA = "Field_A_1", FieldB = 101, FieldC = "Field_C_1", FieldD = false } }, { "caab946b-a155-4297-a8a6-aaaa5aedf76d", new TestEntityOne { Id = "caab946b-a155-4297-a8a6-aaaa5aedf76d", FieldA = "Field_A_2", FieldB = 202, FieldC = "Field_C_2", FieldD = true } }, { "3e627ea2-27e6-48a3-9846-3f27008edd6b", new TestEntityOne { Id = "3e627ea2-27e6-48a3-9846-3f27008edd6b", FieldA = "Field_A_3", FieldB = 303, FieldC = "Field_C_3", FieldD = false } }, { "77a906b7-46ca-4e9a-b94b-5cf816f4d984", new TestEntityOne { Id = "77a906b7-46ca-4e9a-b94b-5cf816f4d984", FieldA = "Field_A_4", FieldB = 404, FieldC = "Field_C_4", FieldD = true } }, { "71bb8f25-cdc5-43f5-a66c-4e3dab81d2af", new TestEntityOne { Id = "71bb8f25-cdc5-43f5-a66c-4e3dab81d2af", FieldA = "Field_A_6", FieldB = 606, FieldC = "Field_C_6", FieldD = false } } }; var uowMock = new Mock <IUnitOfWork>(); uowMock.Setup(uow => uow.Set <TestEntityOne>()).Returns(entities); var repo = new JsonRepository <TestEntityOne>(uowMock.Object); var testEntityOne = entities["3e627ea2-27e6-48a3-9846-3f27008edd6b"]; testEntityOne.FieldA = "Changed_1"; var idOne = repo.Update(testEntityOne); Assert.IsTrue(idOne == "3e627ea2-27e6-48a3-9846-3f27008edd6b"); var result = repo.Get("3e627ea2-27e6-48a3-9846-3f27008edd6b"); Assert.IsNotNull(result); Assert.IsTrue(result.Id == "3e627ea2-27e6-48a3-9846-3f27008edd6b"); Assert.IsTrue(result.FieldA == "Changed_1"); Assert.IsTrue(repo.All().Count() == 5); var testEntityTwo = new TestEntityOne { FieldA = "Insert_2", FieldB = 222, FieldC = "Insert_2", FieldD = false }; var idTwo = repo.Update(testEntityTwo); Assert.IsNotNull(idTwo); result = repo.Get(idTwo); Assert.IsNotNull(result); Assert.IsTrue(result.Id == idTwo); Assert.IsTrue(result.FieldA == "Insert_2"); Assert.IsTrue(repo.All().Count() == 6); }
public void All_Test() { var entities = new Dictionary <string, TestEntityOne> { { "3c0b80ed-6542-42c0-a3df-eef2d784011f", new TestEntityOne { Id = "3c0b80ed-6542-42c0-a3df-eef2d784011f", FieldA = "Field_A_1", FieldB = 101, FieldC = "Field_C_1", FieldD = false } }, { "caab946b-a155-4297-a8a6-aaaa5aedf76d", new TestEntityOne { Id = "caab946b-a155-4297-a8a6-aaaa5aedf76d", FieldA = "Field_A_2", FieldB = 202, FieldC = "Field_C_2", FieldD = true } }, { "3e627ea2-27e6-48a3-9846-3f27008edd6b", new TestEntityOne { Id = "3e627ea2-27e6-48a3-9846-3f27008edd6b", FieldA = "Field_A_3", FieldB = 303, FieldC = "Field_C_3", FieldD = false } }, { "77a906b7-46ca-4e9a-b94b-5cf816f4d984", new TestEntityOne { Id = "77a906b7-46ca-4e9a-b94b-5cf816f4d984", FieldA = "Field_A_4", FieldB = 404, FieldC = "Field_C_4", FieldD = true } } }; var uowMock = new Mock <IUnitOfWork>(); uowMock.Setup(uow => uow.Set <TestEntityOne>()).Returns(entities); var unitOfWork = uowMock.Object; var repo = new JsonRepository <TestEntityOne>(unitOfWork); var testAll = repo.All().ToList(); Assert.IsNotNull(testAll); Assert.IsTrue(testAll.Count == 4); Assert.IsTrue(testAll[0].Id == "3c0b80ed-6542-42c0-a3df-eef2d784011f"); Assert.IsTrue(testAll[1].Id == "caab946b-a155-4297-a8a6-aaaa5aedf76d"); Assert.IsTrue(testAll[2].Id == "3e627ea2-27e6-48a3-9846-3f27008edd6b"); Assert.IsTrue(testAll[3].Id == "77a906b7-46ca-4e9a-b94b-5cf816f4d984"); }
public void List_Should_Return_All_Entities() { // arrange var jsonRepository = new JsonRepository(TestContext.TestDir); jsonRepository.DeleteAll<Entry>(); jsonRepository.Save(new Entry { Title = "Entry 1" }); jsonRepository.Save(new Entry { Title = "Entry 2" }); jsonRepository.Save(new Entry { Title = "Entry 3" }); // act var all = jsonRepository.All<Entry>(); // assert Assert.IsTrue(all.Count() == 3); }