コード例 #1
0
        public void DeleteAnEntityByIdDeletesTheEntityAndAllItsContentWhenTrashIsNotActive()
        {
            var mock = new EntityManagerMock();

            mock.EntityManager.Delete <News>(EntityServicesTestData.SecondNewsEntityId);
            mock.DataSourceMock.Mock.Verify(d => d.Delete(It.IsAny <PlatformEntity>()), Times.Once());
        }
コード例 #2
0
        public void GetNewObjectShouldReturnNewObject()
        {
            var mock   = new EntityManagerMock();
            var result = mock.EntityManager.Get(typeof(File), null);

            Assert.IsNotNull(result);
        }
コード例 #3
0
        public void DeleteContentByCultureAndVersionNumberDeletesTheContentForThatCultureAndVersionNumberWhenTrashIsNotActive()
        {
            var mock = new EntityManagerMock();

            mock.EntityManager.Delete <News>(EntityServicesTestData.FirstNewsEntityId, "en", 1);
            mock.DataSourceMock.Mock.Verify(d => d.Delete(It.IsAny <IContent>()), Times.Once());
        }
コード例 #4
0
        public void DeleteContentByCultureDeletesAllTheContentForThatCultureWhenTrashIsNotActive()
        {
            var mock = new EntityManagerMock();

            mock.EntityManager.Delete <News>(EntityServicesTestData.FirstNewsEntityId, "en");
            mock.DataSourceMock.Mock.Verify(d => d.Delete(It.IsAny <object>()), Times.Exactly(3));
        }
コード例 #5
0
        public void UpdatingAModifiedContentItemWithVersioningActiveShouldCreateANewVersion()
        {
            var      mock       = new EntityManagerMock();
            IContent version    = null;
            var      helperMock = _mocks.First(m => m.GetType().Equals(typeof(Mock <IEntityHelper>))) as Mock <IEntityHelper>;

            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.AutomaticVersions)).Returns(true);
            mock.DataSourceMock.Mock.Setup(m => m.GetModifiedPropertyValues(It.IsAny <News>())).Returns(new List <ModifiedPropertyValue> {
                new ModifiedPropertyValue()
            });
            mock.DataSourceMock.Mock.Setup(m => m.Save <IContent>(It.IsAny <IContent>())).Returns <IContent>(n => { version = n; return(n); });
            var entity = EntityServicesTestData.FirstNewsContentEn;

            entity.Body        = "This is a new version of this news.";
            entity.PublishedOn = DateTime.Now;
            var result = mock.EntityManager.Save(entity);

            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.Translations)).Returns(false);
            mock.DataSourceMock.Mock.Verify(d => d.Save <IContent>(It.IsAny <IContent>()), Times.Once());
            Assert.IsNotNull(result);
            Assert.IsNotNull(version);
            Assert.AreEqual(EntityServicesTestData.FirstNewsEntityId, version.EntityId);
            Assert.AreEqual("This is a new version of this news.", ((News)version).Body);
            Assert.AreEqual(2, version.VersionNumber);
            Assert.IsTrue(version.IsCurrentVersion);
        }
コード例 #6
0
        public void ProcessPathShouldAddIndexForAlreadyExistingPath()
        {
            var      mock = new EntityManagerMock();
            IContent news = null;

            mock.DataSourceMock.Mock.Setup(m => m.Save <IContent>(It.IsAny <IContent>())).Returns <IContent>(n => { news = n; return(n); });
            var newsA = GetNew <News>();

            newsA.Body       = "News";
            newsA.Entity.Url = "test";
            var newsB = GetNew <News>();

            newsB.Body       = "News";
            newsB.Entity.Url = "test-2";
            mock.DataSourceMock.RegisterData <News>(new List <News> {
                newsA, newsB
            });
            var entity = GetNew <News>();

            entity.Name = "Test";
            entity.Body = "News";
            mock.EntityManager.Save(entity);
            string expected = "test-3";
            string actual   = news.Entity.Url;

            Assert.AreEqual(expected, actual);
        }
コード例 #7
0
        public void QueryShouldReturnAllNonDeletedContent()
        {
            var mock    = new EntityManagerMock();
            var manager = mock.EntityManager;
            var result  = manager.Query <News>();

            Assert.AreEqual(7, result.Count());
        }
コード例 #8
0
        public void AnExceptionShouldBeThrownWhenCreatingANewContentTranslationWithoutTranslationsEnabled()
        {
            var mock   = new EntityManagerMock();
            var entity = EntityServicesTestData.FirstNewsContentEn;

            entity.Culture = "fr";
            var result = mock.EntityManager.Save(entity);
        }
コード例 #9
0
        public void QueryByTagShouldReturnAllNonDeletedCurrentContentWithTheCurrentCultureFilteredByTag()
        {
            var mock    = new EntityManagerMock();
            var manager = mock.EntityManager;
            var result  = manager.QueryByTag <News>("Test");

            Assert.AreEqual(1, result.Count());
        }
コード例 #10
0
        public void CheckNameShouldReturnFalseForExistingNameAndDifferentId()
        {
            var mock         = new EntityManagerMock();
            var manager      = mock.EntityManager;
            var existingName = EntityServicesTestData.FirstNewsContentEn.Name;
            var result       = manager.IsNameAvailable(typeof(News), existingName, Guid.NewGuid());

            Assert.AreEqual(false, result);
        }
コード例 #11
0
        public void CheckNameShouldReturnTrueForNewNameAndSameId()
        {
            var mock    = new EntityManagerMock();
            var manager = mock.EntityManager;
            var newName = "New Name";
            var result  = manager.IsNameAvailable(typeof(News), newName, EntityServicesTestData.FirstNewsEntityId);

            Assert.AreEqual(true, result);
        }
コード例 #12
0
        public void GetNewEntityShouldReturnProperlyFilledEntity()
        {
            var mock = new EntityManagerMock();
            var news = mock.EntityManager.Get <News>(null);

            Assert.IsNotNull(news);
            Assert.IsNotNull(news.Culture);
            Assert.AreNotEqual(0, news.VersionNumber);
        }
コード例 #13
0
        public void DeleteContentByCultureAndVersionNumberDeletesTheContentForThatCultureAndVersionNumberWhenAlreadyMarkedAsDeletedWhenTrashIsActive()
        {
            var mock       = new EntityManagerMock();
            var helperMock = _mocks.First(m => m.GetType().Equals(typeof(Mock <IEntityHelper>))) as Mock <IEntityHelper>;

            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.Trashbin)).Returns(true);
            mock.EntityManager.Delete <News>(EntityServicesTestData.FirstNewsEntityId, "en", 3);
            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.Trashbin)).Returns(false);
            mock.DataSourceMock.Mock.Verify(d => d.Delete(It.IsAny <IContent>()), Times.Once());
        }
コード例 #14
0
        public void GetEntityByIdShouldReturnCorrectEntity()
        {
            var mock    = new EntityManagerMock();
            var manager = mock.EntityManager;
            var entity  = manager.Get <News>(EntityServicesTestData.FirstNewsEntityId);

            Assert.IsNotNull(entity);
            Assert.AreEqual("first-news", entity.Entity.Url);
            Assert.AreEqual("First news", entity.Name);
            Assert.AreEqual("en", entity.Culture);
        }
コード例 #15
0
        public void DeleteContentByCultureMarksAsDeletedAllTheContentForThatCultureWhenTrashIsActive()
        {
            var mock       = new EntityManagerMock();
            var helperMock = _mocks.First(m => m.GetType().Equals(typeof(Mock <IEntityHelper>))) as Mock <IEntityHelper>;

            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.Trashbin)).Returns(true);
            mock.EntityManager.Delete <News>(EntityServicesTestData.FirstNewsEntityId, "en");
            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.Trashbin)).Returns(false);
            var undeleted = mock.DataSourceMock.DataList <News>().Any(n => n.EntityId == EntityServicesTestData.FirstNewsEntityId && !n.DeletedOn.HasValue && n.Culture == "en");

            Assert.IsFalse(undeleted);
        }
コード例 #16
0
        public void GetEntityByIdAndCultureShouldReturnCorrectEntity()
        {
            var mock    = new EntityManagerMock();
            var manager = mock.EntityManager;
            var entity  = manager.Get <News>(EntityServicesTestData.FirstNewsEntityId, "nl");

            Assert.IsNotNull(entity);
            Assert.AreEqual("first-news", entity.Entity.Url);
            Assert.AreEqual("Eerste nieuwsbericht", entity.Name);
            Assert.AreEqual("nl", entity.Culture);
            Assert.AreEqual(1, entity.VersionNumber);
        }
コード例 #17
0
        public void DeleteAnEntityByIdMarksTheEntityContentAsDeletedWhenTrashIsActive()
        {
            var mock       = new EntityManagerMock();
            var helperMock = _mocks.First(m => m.GetType().Equals(typeof(Mock <IEntityHelper>))) as Mock <IEntityHelper>;

            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.Trashbin)).Returns(true);
            mock.EntityManager.Delete <News>(EntityServicesTestData.SecondNewsEntityId);
            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.Trashbin)).Returns(false);
            var undeleted = mock.DataSourceMock.DataList <News>().Any(n => n.EntityId == EntityServicesTestData.SecondNewsEntityId && !n.DeletedOn.HasValue);

            Assert.IsFalse(undeleted);
        }
コード例 #18
0
        public void ProcessPathShouldCreateCorrectUrl()
        {
            var      mock = new EntityManagerMock();
            IContent news = null;

            mock.DataSourceMock.Mock.Setup(m => m.Save <IContent>(It.IsAny <IContent>())).Returns <IContent>(n => { news = n; return(n); });
            var entity = GetNew <News>();

            entity.Name = "Testing";
            entity.Body = "News";
            mock.EntityManager.Save(entity);
            string expected = "testing";
            string actual   = news.Entity.Url;

            Assert.AreEqual(expected, actual);
        }
コード例 #19
0
        public void ForNewContentANewEntityShouldBeCreated()
        {
            var      mock = new EntityManagerMock();
            IContent news = null;

            mock.DataSourceMock.Mock.Setup(m => m.Save <IContent>(It.IsAny <IContent>())).Returns <IContent>(n => { news = n; return(n); });
            var entity = mock.EntityManager.Get <News>(null);

            entity.Name = "Testing";
            entity.Body = "News";
            var result = mock.EntityManager.Save(entity);

            mock.DataSourceMock.Mock.Verify(d => d.Save <IContent>(It.IsAny <IContent>()), Times.Once());
            Assert.IsNotNull(result);
            Assert.IsNotNull(news.Entity);
            Assert.AreNotEqual(Guid.Empty, news.EntityId);
        }
コード例 #20
0
        public void ForANewContentTranslationANewContentBasedOnTheFirstAvailableCultureWhenNoTranslationIsPresentForTheDefaultCultureShouldBeCreated()
        {
            var      mock        = new EntityManagerMock();
            IContent translation = null;
            var      helperMock  = _mocks.First(m => m.GetType().Equals(typeof(Mock <IEntityHelper>))) as Mock <IEntityHelper>;

            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.Translations)).Returns(true);
            mock.DataSourceMock.Mock.Setup(m => m.Save <IContent>(It.IsAny <IContent>())).Returns <IContent>(n => { translation = n; return(n); });
            var entity = EntityServicesTestData.ThirdNewsContentDe;

            entity.Culture = "fr";
            entity.Name    = "Francais";
            entity.Body    = "La Marseillaise";
            var result = mock.EntityManager.Save(entity);

            helperMock.Setup(m => m.IsServiceActive(typeof(News), EntityServiceActions.Translations)).Returns(false);
            mock.DataSourceMock.Mock.Verify(d => d.Save <IContent>(It.IsAny <IContent>()), Times.Once());
            Assert.IsNotNull(result);
            Assert.IsNotNull(translation);
            Assert.AreEqual(EntityServicesTestData.ThirdNewsEntityId, translation.EntityId);
            Assert.AreEqual("fr", translation.Culture);
            Assert.AreEqual("Francais", translation.Name);
            Assert.AreEqual("La Marseillaise", ((News)translation).Body);
        }
コード例 #21
0
 public void GetNewEntityWithNonGuidKeyShouldThrowNoSupportedException()
 {
     var mock = new EntityManagerMock();
     var news = mock.EntityManager.Get(typeof(News), 1);
 }