Exemplo n.º 1
0
        public void ShouldInsertAndReturnDocument()
        {
            var expectedId = "1";

            SetupForGetDocument(expectedId);
            var expected = new DocumentStub()
            {
                Id = expectedId
            };
            var indexResponse = new Mock <IIndexResponse>();

            indexResponse.SetupGet(x => x.Id).Returns(() => expected.Id);
            ElasticClient.Setup(x => x.Index(expected, It.IsAny <Func <IndexDescriptor <DocumentStub>, IndexDescriptor <DocumentStub> > >()))
            .Returns(indexResponse.Object);

            var actual = Subject.Insert(expected);

            Assert.That(actual.Id, Is.EqualTo(expected.Id));
            ElasticClient.Verify(x => x.Index(expected, It.IsAny <Func <IndexDescriptor <DocumentStub>, IndexDescriptor <DocumentStub> > >()), Times.Once);
        }
Exemplo n.º 2
0
        public void ShouldReturnListOfDocumentsWithIdsFromElasticsearch()
        {
            var searchResponse = new Mock <ISearchResponse <DocumentStub> >();
            var hits           = new List <IHit <DocumentStub> >();
            var cronTrigger    = new DocumentStub();
            var hit            = new Mock <IHit <DocumentStub> >();
            var expectedId     = "1";

            hit.SetupGet(x => x.Source).Returns(() => cronTrigger);
            hit.SetupGet(x => x.Id).Returns(() => expectedId);
            hits.Add(hit.Object);
            searchResponse.SetupGet(x => x.Hits).Returns(() => hits);
            ElasticClient.Setup(x => x.Search <DocumentStub>(It.IsAny <Func <SearchDescriptor <DocumentStub>, SearchDescriptor <DocumentStub> > >()))
            .Returns(searchResponse.Object);

            var actual = Subject.SelectAll <DocumentStub>();

            Assert.That(actual, Is.Not.Empty);
            Assert.That(actual.First().Id, Is.EqualTo(expectedId));
            ElasticClient.Verify(x => x.Search(It.IsAny <Func <SearchDescriptor <DocumentStub>, SearchDescriptor <DocumentStub> > >()), Times.Once);
        }
Exemplo n.º 3
0
        public void ShouldUpdateAndReturnDocument()
        {
            var expectedId = "1";

            SetupForGetDocument(expectedId);
            var expected = new DocumentStub()
            {
                Id = expectedId
            };
            var updateResponse = new Mock <IUpdateResponse>();

            updateResponse.SetupGet(x => x.Id).Returns(() => expected.Id);
            ElasticClient.Setup(x => x.Update <DocumentStub>(It.IsAny <Func <UpdateDescriptor <DocumentStub, DocumentStub>, UpdateDescriptor <DocumentStub, DocumentStub> > >()))
            .Returns(updateResponse.Object);

            var actual = Subject.Update(expected);

            Assert.That(actual.Id, Is.EqualTo(expected.Id));
            ElasticClient.Verify(
                x => x.Update <DocumentStub>(It.IsAny <Func <UpdateDescriptor <DocumentStub, DocumentStub>, UpdateDescriptor <DocumentStub, DocumentStub> > >()),
                Times.Once);
        }