Esempio n. 1
0
        public void TestGetDocumentTypeId()
        {
            var config = new SimpleEntityConfiguration();

            indexService.Setup(x => x.GetDocumentConfiguration <SimpleEntity>()).Returns(config);
            Assert.AreEqual(config.DocumentTypeId, service.GetDocumentTypeId());
        }
Esempio n. 2
0
        public async Task TestDeleteDocuments()
        {
            var list = new List <object> {
                1, 2
            };
            Action <List <DocumentKey> > tester = (givenKeys) =>
            {
                Assert.AreEqual(2, givenKeys.Count);
                Assert.IsTrue(givenKeys.Select(x => x.Value).ToList().Contains(list.First()));
                Assert.IsTrue(givenKeys.Select(x => x.Value).ToList().Contains(list.Last()));
            };

            var config = new SimpleEntityConfiguration();

            indexService.Setup(x => x.GetDocumentConfiguration <SimpleEntity>()).Returns(config);
            indexService.Setup(x => x.DeleteDocuments(It.IsAny <List <DocumentKey> >())).Callback(tester);
            indexService.Setup(x => x.DeleteDocumentsAsync(It.IsAny <List <DocumentKey> >())).ReturnsAsync(new DocumentIndexResponse()).Callback(tester);


            service.DeleteDocuments(list);
            await service.DeleteDocumentsAsync(list);

            indexService.Verify(x => x.DeleteDocuments(It.IsAny <List <DocumentKey> >()), Times.Once());
            indexService.Verify(x => x.DeleteDocumentsAsync(It.IsAny <List <DocumentKey> >()), Times.Once());
            notificationService.Verify(x => x.DeleteDocumentsStarted(It.IsAny <string>(), It.IsAny <List <object> >()), Times.Exactly(2));
            notificationService.Verify(x => x.DeleteDocumentsFinished(It.IsAny <string>(), It.IsAny <List <object> >()), Times.Exactly(2));
        }
Esempio n. 3
0
        public void TestGetDocumentTypeId_ConfigDoesNotExist()
        {
            SimpleEntityConfiguration config = null;

            indexService.Setup(x => x.GetDocumentConfiguration <SimpleEntity>()).Returns(config);
            Action a = () => service.GetDocumentTypeId();

            a.ShouldThrow <NotSupportedException>().WithMessage(String.Format("The document configuration for the type [{0}] was not found.", typeof(SimpleEntity)));
        }
Esempio n. 4
0
        public async Task TestAddOrUpdateDocument_DocumentConfigurationDoesNotExist()
        {
            var configuration    = new SimpleEntityConfiguration();
            var id               = 1;
            var documentTypeName = configuration.GetDocumentTypeName();
            var message          = String.Format("The document configuration for the type [{0}] was not found.", typeof(SimpleEntity));

            indexService.Setup(x => x.GetDocumentConfiguration <SimpleEntity>()).Returns(default(SimpleEntityConfiguration));
            Action      a = () => service.AddOrUpdateDocument(id);
            Func <Task> f = () =>
            {
                return(service.AddOrUpdateDocumentAsync(id));
            };

            a.ShouldThrow <NotSupportedException>().WithMessage(message);
            f.ShouldThrow <NotSupportedException>().WithMessage(message);
        }
Esempio n. 5
0
        public async Task TestAddOrUpdateDocument_DocumentDoesNotExist()
        {
            var configuration    = new SimpleEntityConfiguration();
            var id               = 1;
            var documentTypeName = configuration.GetDocumentTypeName();
            var message          = String.Format("The {0} document with Id {1} was not found.", documentTypeName, id);

            indexService.Setup(x => x.GetDocumentConfiguration <SimpleEntity>()).Returns(configuration);
            Action      a = () => service.AddOrUpdateDocument(id);
            Func <Task> f = () =>
            {
                return(service.AddOrUpdateDocumentAsync(id));
            };

            a.ShouldThrow <ModelNotFoundException>().WithMessage(message);
            f.ShouldThrow <ModelNotFoundException>().WithMessage(message);
        }
Esempio n. 6
0
        public async Task TestAddOrUpdateAll_DocumentConfigurationDoesNotExist()
        {
            SimpleEntityConfiguration configuration = null;

            indexService.Setup(x => x.GetDocumentConfiguration <SimpleEntity>()).Returns(configuration);
            var message = String.Format("The document configuration for the type [{0}] was not found.", typeof(SimpleEntity));

            Action a = () =>
            {
                service.AddOrUpdateAll();
            };
            Func <Task> f = () =>
            {
                return(service.AddOrUpdateAllAsync());
            };

            a.ShouldThrow <NotSupportedException>().WithMessage(message);
            f.ShouldThrow <NotSupportedException>().WithMessage(message);
        }
Esempio n. 7
0
        public async Task TestDeleteDocuments_ConfigDoesNotExist()
        {
            SimpleEntityConfiguration config = null;

            indexService.Setup(x => x.GetDocumentConfiguration <SimpleEntity>()).Returns(config);

            var list = new List <object> {
                1, 2
            };
            Action      a = () => service.DeleteDocuments(list);
            Func <Task> f = () =>
            {
                return(service.DeleteDocumentsAsync(list));
            };
            var message = String.Format("The document configuration for the type [{0}] was not found.", typeof(SimpleEntity));

            a.ShouldThrow <NotSupportedException>().WithMessage(message);
            f.ShouldThrow <NotSupportedException>().WithMessage(message);
            notificationService.Verify(x => x.DeleteDocumentsStarted(It.IsAny <string>(), It.IsAny <List <object> >()), Times.Never());
            notificationService.Verify(x => x.DeleteDocumentsFinished(It.IsAny <string>(), It.IsAny <List <object> >()), Times.Never());
        }