public void DeleteByEmailTest()
        {
            Mock<IElasticClient> client = new Mock<IElasticClient>();
            client.Setup(
                x =>
                    x.Delete<EmployeeRecord>(It.IsAny<Func<DeleteDescriptor<EmployeeRecord>, DeleteDescriptor<EmployeeRecord>>>())
                        .Found).Returns(true);
            client.Setup(
                x =>
                    x.Search<EmployeeRecord>(It.IsAny<Func<SearchDescriptor<EmployeeRecord>, SearchDescriptor<EmployeeRecord>>>())
                        .Documents).Returns(
                            new List<EmployeeRecord>()
                            {
                                new EmployeeRecord() {Id = 9999}
                            });

            EmployeeRecordRepository repository = new EmployeeRecordRepository(client.Object);
            Assert.IsNotNull(repository);
            var results = repository.Delete(new EmployeeRecord()
            {
                Email = "*****@*****.**",
            });
            Assert.IsNotNull(results);
            Assert.AreEqual(true, results);
            client.Verify(x => x.Delete<EmployeeRecord>(It.IsAny<Func<DeleteDescriptor<EmployeeRecord>, DeleteDescriptor<EmployeeRecord>>>()).Found, Times.Exactly(1));
            client.Verify(x =>
                x.Search<EmployeeRecord>(It.IsAny<Func<SearchDescriptor<EmployeeRecord>, SearchDescriptor<EmployeeRecord>>>())
                    .Documents, Times.Exactly(1));
        }
        public void AddTest()
        {
            Mock<IElasticClient> client = new Mock<IElasticClient>();
            client.Setup(x => x.Index<EmployeeRecord>(It.IsAny<EmployeeRecord>(),null).Id).Returns("asdasdf");

            EmployeeRecordRepository repository = new EmployeeRecordRepository(client.Object);
            Assert.IsNotNull(repository);
            var results = repository.Add(new EmployeeRecord()
            {
                Address = "Neverland",
                FirstName = "Peter",
                LastName = "Pan",
                Email = "*****@*****.**",
                JobTitle = "Lord of the Flies",
                Phone = "555-555-5555"
            });
            Assert.IsNotNull(results);
            Assert.AreEqual("asdasdf", results);
        }
 public void ConstuctorTest()
 {
     EmployeeRecordRepository repository = new EmployeeRecordRepository(null);
     Assert.IsNotNull(repository);
 }
        public void UpdateTest()
        {
            var response = new Mock<IUpdateResponse>();
            response.SetupGet(x => x.IsValid).Returns(true);
            Mock<IElasticClient> client = new Mock<IElasticClient>();
            client.Setup(
                x =>
                    x.Update<EmployeeRecord>(It.IsAny<Func<UpdateDescriptor<EmployeeRecord, EmployeeRecord>, UpdateDescriptor<EmployeeRecord, EmployeeRecord>>>())
                        ).Returns(response.Object );

            EmployeeRecordRepository repository = new EmployeeRecordRepository(client.Object);
            Assert.IsNotNull(repository);
            repository.Update(new EmployeeRecord()
            {
                Id = 9999
            });

            client.Verify(x =>
                    x.Update<EmployeeRecord>(It.IsAny<Func<UpdateDescriptor<EmployeeRecord, EmployeeRecord>, UpdateDescriptor<EmployeeRecord, EmployeeRecord>>>())
                        , Times.Exactly(1));
        }
        public void GetAllTest()
        {
            Mock<IElasticClient> client = new Mock<IElasticClient>();
            client.Setup(x => x.Search<EmployeeRecord>(It.IsAny<Func<SearchDescriptor<EmployeeRecord>,SearchDescriptor<EmployeeRecord>>>()).Documents).Returns(
                () =>
                {
                    return new List<EmployeeRecord>()
                    {
                        new EmployeeRecord() { },
                        new EmployeeRecord() { },
                        new EmployeeRecord() { }
                    };
                });

            EmployeeRecordRepository repository = new EmployeeRecordRepository(client.Object);
            Assert.IsNotNull(repository);
            var results = repository.GetAll();
            Assert.IsNotNull(results);
            Assert.AreEqual(3,results.Count());
        }
        public void DeleteWithTest()
        {
            Mock<IElasticClient> client = new Mock<IElasticClient>();
            client.Setup(x => x.Delete<EmployeeRecord>(It.IsAny<Func<DeleteDescriptor<EmployeeRecord>, DeleteDescriptor<EmployeeRecord>>>()).Found).Returns(true);

            EmployeeRecordRepository repository = new EmployeeRecordRepository(client.Object);
            Assert.IsNotNull(repository);
            var results = repository.Delete(9999);
            Assert.IsNotNull(results);
            Assert.AreEqual(true, results);
            client.Verify(x => x.Delete<EmployeeRecord>(It.IsAny<Func<DeleteDescriptor<EmployeeRecord>, DeleteDescriptor<EmployeeRecord>>>()).Found, Times.Exactly(1));
        }