Ejemplo n.º 1
0
        public void FirstOrDefault_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 repo = new JsonRepository <TestEntityOne>(uowMock.Object);

            var testFirstOrDefault_NotNull = repo.FirstOrDefault(x => x.FieldB == 303 || x.FieldC == "Field_C_4");

            Assert.IsNotNull(testFirstOrDefault_NotNull);
            Assert.IsTrue(testFirstOrDefault_NotNull.Id == "3e627ea2-27e6-48a3-9846-3f27008edd6b" || testFirstOrDefault_NotNull.Id == "77a906b7-46ca-4e9a-b94b-5cf816f4d984");

            var testFirstOrDefault_IsNull = repo.FirstOrDefault(x => x.FieldB == 555);

            Assert.IsNull(testFirstOrDefault_IsNull);
        }