From 6dc52b94610c6a06b69fd28021f87185e424a5b0 Mon Sep 17 00:00:00 2001 From: Mole Date: Thu, 1 Oct 2020 15:10:42 +0200 Subject: [PATCH 01/36] Migrate DataTypeServiceTests --- .../Services/DataTypeServiceTests.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/DataTypeServiceTests.cs (67%) diff --git a/src/Umbraco.Tests/Services/DataTypeServiceTests.cs b/src/Umbraco.Tests.Integration/Services/DataTypeServiceTests.cs similarity index 67% rename from src/Umbraco.Tests/Services/DataTypeServiceTests.cs rename to src/Umbraco.Tests.Integration/Services/DataTypeServiceTests.cs index c047b04430..0072095771 100644 --- a/src/Umbraco.Tests/Services/DataTypeServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/DataTypeServiceTests.cs @@ -3,8 +3,10 @@ using System.Linq; using System.Threading; using NUnit.Framework; using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; +using Umbraco.Tests.Integration.Testing; +using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Services @@ -15,16 +17,22 @@ namespace Umbraco.Tests.Services [TestFixture] [Apartment(ApartmentState.STA)] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] - public class DataTypeServiceTests : TestWithSomeContentBase + public class DataTypeServiceTests : UmbracoIntegrationTest { + + private IDataTypeService DataTypeService => GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + private ILocalizedTextService LocalizedTextService => GetRequiredService(); + private ILocalizationService LocalizationService => GetRequiredService(); + [Test] public void DataTypeService_Can_Persist_New_DataTypeDefinition() { // Arrange - var dataTypeService = ServiceContext.DataTypeService; + var dataTypeService = DataTypeService; // Act - IDataType dataType = new DataType(new LabelPropertyEditor(Logger, IOHelper, DataTypeService, LocalizedTextService,LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; + IDataType dataType = new DataType(new LabelPropertyEditor(Logger, IOHelper, DataTypeService, LocalizedTextService, LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; dataTypeService.Save(dataType); // Assert @@ -39,9 +47,12 @@ namespace Umbraco.Tests.Services public void DataTypeService_Can_Delete_Textfield_DataType_And_Clear_Usages() { // Arrange - var dataTypeService = ServiceContext.DataTypeService; + var dataTypeService = DataTypeService; var textfieldId = "Umbraco.Textbox"; var dataTypeDefinitions = dataTypeService.GetByEditorAlias(textfieldId); + var doctype = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); + ContentTypeService.Save(doctype); + // Act var definition = dataTypeDefinitions.First(); @@ -54,7 +65,7 @@ namespace Umbraco.Tests.Services Assert.That(deletedDefinition, Is.Null); //Further assertions against the ContentType that contains PropertyTypes based on the TextField - var contentType = ServiceContext.ContentTypeService.Get(NodeDto.NodeIdSeed+1); + var contentType = ContentTypeService.Get(doctype.Id); Assert.That(contentType.Alias, Is.EqualTo("umbTextpage")); Assert.That(contentType.PropertyTypes.Count(), Is.EqualTo(1)); } @@ -63,7 +74,7 @@ namespace Umbraco.Tests.Services public void Cannot_Save_DataType_With_Empty_Name() { // Arrange - var dataTypeService = ServiceContext.DataTypeService; + var dataTypeService = DataTypeService; // Act var dataTypeDefinition = new DataType(new LabelPropertyEditor(Logger, IOHelper, DataTypeService, LocalizedTextService,LocalizationService, ShortStringHelper)) { Name = string.Empty, DatabaseType = ValueStorageType.Ntext }; From 602e7d01e1535a1e0e4aa75c05ce5e65816bc4d7 Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 2 Oct 2020 10:53:28 +0200 Subject: [PATCH 02/36] Migrate PackageExtractionTests --- .../Packaging/PackageExtractionTests.cs | 11 ++++++++--- .../Packages/Document_Type_Picker_1.1.umb | Bin 0 -> 6147 bytes src/Umbraco.Tests/Umbraco.Tests.csproj | 2 -- 3 files changed, 8 insertions(+), 5 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.UnitTests/Umbraco.Core}/Packaging/PackageExtractionTests.cs (70%) create mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/Packages/Document_Type_Picker_1.1.umb diff --git a/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs similarity index 70% rename from src/Umbraco.Tests/Packaging/PackageExtractionTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs index 20efc422f4..d9dcf1bfe9 100644 --- a/src/Umbraco.Tests/Packaging/PackageExtractionTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs @@ -1,11 +1,14 @@ using System; using System.IO; using System.Linq; +using Moq; using NUnit.Framework; using Umbraco.Core.Composing; +using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Packaging; using Umbraco.Tests.TestHelpers; +using Umbraco.Tests.UnitTests.AutoFixture; namespace Umbraco.Tests.Packaging { @@ -16,9 +19,11 @@ namespace Umbraco.Tests.Packaging private static FileInfo GetTestPackagePath(string packageName) { - const string testPackagesDirName = "Packaging\\Packages"; - var hosting = TestHelper.GetHostingEnvironment(); - string path = Path.Combine(hosting.ApplicationPhysicalPath, testPackagesDirName, packageName); + const string testPackagesDirName = "Umbraco.Core\\Packaging\\Packages"; + var testDir = TestContext.CurrentContext.TestDirectory.Split("bin")[0]; + var hostingEnvironment = Mock.Of( + x => x.ToAbsolute(It.IsAny()) == "/" && x.ApplicationPhysicalPath == testDir); + var path = Path.Combine(hostingEnvironment.ApplicationPhysicalPath, testPackagesDirName, packageName); return new FileInfo(path); } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/Packages/Document_Type_Picker_1.1.umb b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/Packages/Document_Type_Picker_1.1.umb new file mode 100644 index 0000000000000000000000000000000000000000..18449bd3735870c98e711525a7ea9883941e321f GIT binary patch literal 6147 zcma)=RZJWVl!bAp6qn)@DHL~ich`a9GDv|U9o*dqXP~$j8>HwIcc+6CcZxg3_Ww7V z%_f^o_TGmt_vYr@m-BSARFP4L5D*YB5dOwu%SOrHjmG{vav>nF{0m`zTP^`UD|RbO zJ{xvEJ{}u(VJ6 z>RqIdc64-an*}K5AZ-UAemx4uIqk2~WIP~j*f$8$!If+UInR2e$q(g!=FuH-F4L-4 z9dYM91Y;{#CsPV><>WPb+O>B}bWg&$d6f8SWagJ$DRHjNnOwXeRSe4r{pSursKP2+ z5*!Csj==m?xdmqNt(gZb?I}|u@T-17dXyRCfw)Zm+V*Ay#4LOW7g^5bn$2t^_RxbI zb~nFqnEJIPe82VAW1vgLGN5?NciA2C@u8*RO#64`l1El`KGb^eq{hBl4d;)_RN9|h z;2vSvnrG6N7_BRX3JZ;r19(S{2)`5E;kr~#Mr_~Kl~nJtaO8z|tn0FriIPLEk-0X6 zvkrodN)M#{Ib62%^qF1q_<~==kbKIOK6YgSp`>(Lk|N2qo8u_hSPg*eGz2WtsELJg z&i!U|fb7dz**KzB*2#Yx-xvl~W{KI5olssKlTbSoK4HwQbkz%LRT0Zs&^mDvdZM^f zaJ6-Hs!Z$PJ3v>ei2UT60fWv}du)Y_hI){-2L5Ct%oxT=k6UZvoJj>&I^!)jbKH&Z zn`AY%?Dat5!Xs-{1DBUi;|eN+y0ooBU9<+W zXtE^aR5vrFAIN4;N9Ijz8F;tVH*fW17b6FKG25!*j&7OkS`7Kf{_6PgnqvHT(@?hk zLv`$3uPtrWhuOD|xBV3K-Z=x^L*J84#xI&3h8UoEF81qz>!y#mJLY5D1@>wIkH3r( zKD4hMlFtyiV)%T#VfSo7!H3Sox<$um(_bE!wiwmw%hWWmIl0OA#aZY==|=ILqn824 zdZOgHV!5W3XWn)GHS;s9Br+0=)89}`$X;b0zt|G{kaO!YVoO;^U|9U?4*?C z!%|*r>zZj^}+;2PT53CIGVe$h&mj**Cis2A- z`8%{XPB83WbizI%%r;n-d1*hl?rK}yc6^H~msEv1`WhYfE;4vHO~yK60KQbPy+H~& z`rp(kJ4~kAZ*nz~nKy2r#MMU^21S{qW`tix;>?ZXUT`dLZ6bRY-q$g#o^Br|Ldz)_ zDg*O{d2CY7!@cjB=Op+FYx~N>fq<(Ap`nroe+W26+&nUTGK}0iDtO^=(%MYj)iRO# z?oT?0ZWTHZ_P``(^9-`JtTQyLdIA#NI|)c0!3Dc?);nWKZ{Cszq-_5F9y*io>5Hs_ zAnWq_~2s-hqXHNdHM>xV6h`*qRK!=$MrB=hXz+vHdBI$$LU=ggLL z^jO=a$aVtKjpt#M5lUhlQ9Qx@QXkS}vB$}6U~xu4-=rlJC}joEaE7=&(6 z-FR1gL)Z7leecjH^`_wsAd@Ib5u$uuuP82a*C4daRl_d$88oY z?qOz0+t3y^;Qp(6uXXmoj0;jop*I%skt<_q-YP(blUACHztsDilz|0Jd@ULU$sc+RLK@h*@r?;B}v z5IR{Rml=D#;)V+nRmdHtzuv~~FmDRVv)(rn+fk1Yzhcp14yw3Di#tW^85Hq1ZQVh1EGVb^Pax`C0-tS*wo!YH)*C?b4l>Vd)h$bQvM zNSz2P#E`kRXV;MRxn)F7ARMWiXcSQ(iu@Eq6X`bGc#i~zADH>Am4e1_OzOkKBI!m< z5joA{8()ep_|OZrSOWD$LqRZUQF*|}qFR(&V0a?+IQvVvdeiP8IhwTVglv`-h2`=uZ zwI0SrzXM<)cRy#(T3;a9U#glApBlWuG3yBb(Dk~5p$5_3H;wnI@2XOw=YrfS{!*7u z!a)pbk#MBP%1@F8K3KPxe-~fzp(YrDTIB`9&np ztMlJ}{Q*|$yDUgbRY&CGkDxUh_5?3`NWEGwS7;n+Y6(spup!c*h{@AP*SUfef@0ej zlCCAABKL2mkX~}vCOp`U((16TP~2 zxKU*Dd2$2VNmPQMwt~1_3Aj|k8m7@uWe7mq1%nXTy!oGrE^CkEty^Pbnro5D>Aspl ziUt=k7gWZqNu}1Qa&_*oo?Z2$e^eRLTjSg3$omYe6;Z8!i9pU+Of8oM{Iqvl_}wkRr_ix0&v0i6~@8!2pJC z0?yO1Lt}PzprseZS^620EvXAmX#;6|$gCV5aw66pHHh;7pohN53HJUgym11h0jGT- znJ#Tb$S;1B9Xh0Q7{kcJ_icsw*?<*Go{dAqDRdLD{m}#B1gZm$H28~O^a20@7UFd; z^36^G%h6?Y1+qrj_`+%8r5B+Oov?kBJsBZ})OR8HZny>6jN6V{zL7h7RpcaO z5gO`zz>0is7z+KjO(6iDFK#}CfU5I7l!)6=*Ub>G`aIq+tQvmPydGtaCD@oHL7j90pUrRf%j^&T{Jpd~)}G*FsWLG6xG|$2-QLDh zs_|#`jtveNrTh3?w*S(#Uy?=#qbF-XKV_X`86NIM@j3^XQuIuxS==-_^47lWv$vJq zAS-P47_7Qm>CT+iJm*k8G{$l8J-3y)##sctTD3kLG_*=!qr&g1_QQB(#59Eb%crLV zyB0Zy2en_nt@k~(T!~f6Jdu38;wfg|vSD{Jz{iU_vPH+URQobavCM`S`ojBP9;v#WL= z>Z>yLbwtLvJL$L%%hHAtZ)_WxxdjDH?IaWh#|7-DgT4f|^*0Mk?5N0h@9(^Ql#GIQ zIPZo_?1=li8lhhfl>D5VUi_o>5u6|BkcdlML!dv$Kug0CZ>N#VXU~Vj14NKiemoKL z8^EUPT9E^p7+)OUXJn4d@ETz@+s$N&yHVJsIlvm?kZ-d?&o2WH?C?`O%u(#MA9=o$ zFRG_EyMLUP8e&~#83rVlo?X{NHswSt)xi)PQDuT0WK_FkPNI*INOd%XY!yZvU(ZCP zliy@uGXh7|XauM@$j8aYgvj>o&U@JHj=HIZDP;bHTs~l z#J%r#h;A3H8V{i4hs=?{$rrsAJ!&sZf`nK1fw!_E1@2Ahg8SUhmgqI(azDLQ4M@iN zC^^OE24Bns*a5 zYX13M#}>VKWJ{)NbfNLRWwol7POHxS-zz(`+@#DH?~BEaN{`5>vKM7uzs4yEHtZ6? z%b<$VnhJ`OpC?)Tqq&=9t&ST?%NVFxmMrV7#gut+RWr>z947bo(U#Wsuepn;P z2CFR7mLNf@aY{4MQuz%Ey_;>92&Gazd0)1pkuV>KwP$FYH0)fzzAyzRb18KS!#fP| zDm)@sn%t?!zS76PA{H;7zsbm`LvQ< zujr5-h3qLt)ms{ZJ(|eq>yHUna6T$~q`<+!`i{I(0_}hdrjfw{)sLA>FU8Y#MTJzp z*e50C?c_m#FH~OBZ=h(72(>P=r?NoiPd(G^7sqAn!C@OdA#19pGdl0kztLc)mT@T{ z7Be~GoNdd0Ql|LXVMXGm$s{cIE-K^)y>^vSo|GH9rXpxxY-9~l>K#GNBhG=cQF4E7 zPQ)#W|4u#$G>eS?!x}d`c5DPSs!rJR`EPK;qm=L;;3B%{6}`SczsYyVAJc^r&E~K3qG|;RjqSU&+G3p*#4?VcqDZL6ezyGN!?Y&PAwMCGXttI%{xhL8yTaq?Eq< z!Dq0=I+ttmY;wh-`*-ieub$qXlxxTIW~q$@is3z}pp}|?M^7ZTK{O0Ozv+k!XItJ+ ztD2PAu@d&U|2j?_Wf89v($Jg`iub|tXMYh$t*YDIY6l0NCw1QrW4HSAJsemBZ5|$j zc=CN$8#*Yuse0CY|4tT1nYIGD4da+(W(J81-!t|qml8NsXvJnZY`DH*u52LwX6eOO zS=lmpgRjK@9j`nq4@p?zC}%LCs(}HYF7g11dgq<8GP&Ae+?Lx6RC8wWoWnR|#or^n z#*ni+O-L?dB$%ySp}o{={FHmXPRfKTAdMzNu`Kd!M#z({447Y!hR=?#UPT;3TsRPy zp4Ci{VaAufHd_@(ddu4eCH3r1WMq6r})JmSFPFdJrM`@a{?6axWC`G}A^DqGoIlg>9x%ssmFHAc zA;yh4FL&ObY{WN%1-N@ZkQEL$$G;3WwzQ5C?2izkG6-CG9J)TO|IP@-u!NrV(IF!O z^B$y&*w-qd>0l#76lq7<_+~i>wK9}j-kQ0>a__4_Y*flT4t|0TMxo|Gdl@&YMrW|_ zyf>Rk#+sy%!PnQtW14igo!1F%z6^)&_4m-!DYYxrb*s~~n$M{#zt~jJ>Kv8V(9+i4 z*g{(07N zU#$Pmp^gUD6>_j~06U-(Tzh@KF1lDf`}$<|G`?Nw)~I&+x44+O+%wT@SuA!g(T~rN zmHKA#w_@Giy|&*|g5qw%ZWaBZm22Khof#gU!Ab#UAiM>3)4w63*ZCrZ{O}|}InXr) zDEm-=^Z;@c|HA%q!+sU`IP!MD@9;zfov$>&X%zS7{fYQ{R}k>5k%iHQbAPk6 zv>`9*-r5WeOnzihj!z!MY(Xwx=F_No(zlR6)h*&N*Y?j*K;h+iW6?!6m(t{sdS4>4 zTY#&rxiRB(jqCp|IZW2TpJOt1#LY=mIgpIsnu_FWt6e;Mw;{xXkgAk8nI`qZsD(Bv zyvkm`XZB0;m2<6&qi_R=jZU%pn;+RV=FBo@`K9B9KhnO?%gL_4Nh)<;z>P1{#oja~ zP5Tq~;tO(M&{(VFdC$4z)(}~%)j} zHaDuLH34?Tfy}eJl|Mlb3)|1$JHVBocd@TYa85+6|IRZ*9m?fCGU0)xkq{6-Cf*ZaN#F@~PP8t@EI#8X^FN|lf;z-*2tigPkH zbrg##Zrs60*X2O={)MXU%7Jr7nG#W4#aq<9*%R6EOj#p%)rC#(AeEk5y&=)qjcZUYRKJY3dvzFX0C%hZGvfmP~T#f zQE#0|`ZS;WNqe8?#T>YB${6@t4y*v{!=MN#$xTUjBy>z@K=aez!CKP*$1RsptqQGc zk|dGUV%496zS~E$+R}9%)*?sIBLm?z(d9%m`4Vn|Q4@2fa3w3t2p9ictT=2AdNUk? zLMN+KIpxkKthpLGVjEiap8)2v_dljd3GU)?Wp^bc@nX?%6L_7;3XYi#EDg^QzNTP` zBCVgG%9kK`2UACUoY-(lhqhT1bsm4*L4MLduukZszN-JxqW4DwVYV}pKLAJ%KHlO7 zpyewOysjBD1=o3I%T2PT-pko?rE%RcxC@rsV8_gkw$Oz4V4M&15?no@=0_tjhZ+fC z8$IL`v60`W-u5o)k=v(nZlh|cA|eqX{NLI6KX&^c_5V%M|5cUzFV+9;;P?NfNc#_` z|9SmC{EUV0?-Bt45rGV0H$DE%j^h-f<+aM~_CI_MRr*hAsiLC&dxP{(H~m8q(toG_ E0K6^9ApigX literal 0 HcmV?d00001 diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index fe5e334a93..8bb8937992 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -170,7 +170,6 @@ - @@ -338,7 +337,6 @@ - From 89d2668b8f8891eff466a868900f3a07f404d4d5 Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 2 Oct 2020 12:00:13 +0200 Subject: [PATCH 03/36] Move ConsentServiceTests & CreatedPackagesRepositoryTests I need to figure out why hostBuilder.StartAsync(); hangs --- .../CreatedPackagesRepositoryTests.cs | 33 +++++++++++++----- .../Packages/Document_Type_Picker_1.1.umb | Bin 0 -> 6147 bytes .../Services/ConsentServiceTests.cs | 10 +++--- src/Umbraco.Tests/Umbraco.Tests.csproj | 2 -- 4 files changed, 30 insertions(+), 15 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Packaging/CreatedPackagesRepositoryTests.cs (80%) create mode 100644 src/Umbraco.Tests.Integration/Packaging/Packages/Document_Type_Picker_1.1.umb rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/ConsentServiceTests.cs (94%) diff --git a/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs similarity index 80% rename from src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs rename to src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs index d5988439b4..3243c267eb 100644 --- a/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs @@ -3,43 +3,58 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using System.Xml.Linq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; +using Umbraco.Core.Hosting; using Umbraco.Core.Models.Packaging; using Umbraco.Core.Packaging; using Umbraco.Core.Services; -using Umbraco.Tests.TestHelpers; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Packaging { [TestFixture] + [Explicit] // TODO: find out why tests only run one at at time, the tests get blocked after the first test [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] - public class CreatedPackagesRepositoryTests : TestWithDatabaseBase + public class CreatedPackagesRepositoryTests : UmbracoIntegrationTest { private Guid _testBaseFolder; - public override void SetUp() + public override Task Setup() { - base.SetUp(); _testBaseFolder = Guid.NewGuid(); + return base.Setup(); } public override void TearDown() { base.TearDown(); - //clear out files/folders - Directory.Delete(IOHelper.MapPath("~/" + _testBaseFolder), true); + Directory.Delete(HostingEnvironment.MapPathContentRoot("~/" + _testBaseFolder), true); + } + private IContentService ContentService => GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + private IDataTypeService DataTypeService => GetRequiredService(); + private IFileService FileService => GetRequiredService(); + private IMacroService MacroService => GetRequiredService(); + private ILocalizationService LocalizationService => GetRequiredService(); + private IEntityXmlSerializer EntityXmlSerializer => GetRequiredService(); + private IHostingEnvironment HostingEnvironment => GetRequiredService(); + private IUmbracoVersion UmbracoVersion => GetRequiredService(); + public ICreatedPackagesRepository PackageBuilder => new PackagesRepository( - ServiceContext.ContentService, ServiceContext.ContentTypeService, ServiceContext.DataTypeService, - ServiceContext.FileService, ServiceContext.MacroService, ServiceContext.LocalizationService, + ContentService, ContentTypeService, DataTypeService, + FileService, MacroService, LocalizationService, HostingEnvironment, - Factory.GetInstance(), Logger, + EntityXmlSerializer, Logger, UmbracoVersion, Microsoft.Extensions.Options.Options.Create(new GlobalSettings()), "createdPackages.config", diff --git a/src/Umbraco.Tests.Integration/Packaging/Packages/Document_Type_Picker_1.1.umb b/src/Umbraco.Tests.Integration/Packaging/Packages/Document_Type_Picker_1.1.umb new file mode 100644 index 0000000000000000000000000000000000000000..18449bd3735870c98e711525a7ea9883941e321f GIT binary patch literal 6147 zcma)=RZJWVl!bAp6qn)@DHL~ich`a9GDv|U9o*dqXP~$j8>HwIcc+6CcZxg3_Ww7V z%_f^o_TGmt_vYr@m-BSARFP4L5D*YB5dOwu%SOrHjmG{vav>nF{0m`zTP^`UD|RbO zJ{xvEJ{}u(VJ6 z>RqIdc64-an*}K5AZ-UAemx4uIqk2~WIP~j*f$8$!If+UInR2e$q(g!=FuH-F4L-4 z9dYM91Y;{#CsPV><>WPb+O>B}bWg&$d6f8SWagJ$DRHjNnOwXeRSe4r{pSursKP2+ z5*!Csj==m?xdmqNt(gZb?I}|u@T-17dXyRCfw)Zm+V*Ay#4LOW7g^5bn$2t^_RxbI zb~nFqnEJIPe82VAW1vgLGN5?NciA2C@u8*RO#64`l1El`KGb^eq{hBl4d;)_RN9|h z;2vSvnrG6N7_BRX3JZ;r19(S{2)`5E;kr~#Mr_~Kl~nJtaO8z|tn0FriIPLEk-0X6 zvkrodN)M#{Ib62%^qF1q_<~==kbKIOK6YgSp`>(Lk|N2qo8u_hSPg*eGz2WtsELJg z&i!U|fb7dz**KzB*2#Yx-xvl~W{KI5olssKlTbSoK4HwQbkz%LRT0Zs&^mDvdZM^f zaJ6-Hs!Z$PJ3v>ei2UT60fWv}du)Y_hI){-2L5Ct%oxT=k6UZvoJj>&I^!)jbKH&Z zn`AY%?Dat5!Xs-{1DBUi;|eN+y0ooBU9<+W zXtE^aR5vrFAIN4;N9Ijz8F;tVH*fW17b6FKG25!*j&7OkS`7Kf{_6PgnqvHT(@?hk zLv`$3uPtrWhuOD|xBV3K-Z=x^L*J84#xI&3h8UoEF81qz>!y#mJLY5D1@>wIkH3r( zKD4hMlFtyiV)%T#VfSo7!H3Sox<$um(_bE!wiwmw%hWWmIl0OA#aZY==|=ILqn824 zdZOgHV!5W3XWn)GHS;s9Br+0=)89}`$X;b0zt|G{kaO!YVoO;^U|9U?4*?C z!%|*r>zZj^}+;2PT53CIGVe$h&mj**Cis2A- z`8%{XPB83WbizI%%r;n-d1*hl?rK}yc6^H~msEv1`WhYfE;4vHO~yK60KQbPy+H~& z`rp(kJ4~kAZ*nz~nKy2r#MMU^21S{qW`tix;>?ZXUT`dLZ6bRY-q$g#o^Br|Ldz)_ zDg*O{d2CY7!@cjB=Op+FYx~N>fq<(Ap`nroe+W26+&nUTGK}0iDtO^=(%MYj)iRO# z?oT?0ZWTHZ_P``(^9-`JtTQyLdIA#NI|)c0!3Dc?);nWKZ{Cszq-_5F9y*io>5Hs_ zAnWq_~2s-hqXHNdHM>xV6h`*qRK!=$MrB=hXz+vHdBI$$LU=ggLL z^jO=a$aVtKjpt#M5lUhlQ9Qx@QXkS}vB$}6U~xu4-=rlJC}joEaE7=&(6 z-FR1gL)Z7leecjH^`_wsAd@Ib5u$uuuP82a*C4daRl_d$88oY z?qOz0+t3y^;Qp(6uXXmoj0;jop*I%skt<_q-YP(blUACHztsDilz|0Jd@ULU$sc+RLK@h*@r?;B}v z5IR{Rml=D#;)V+nRmdHtzuv~~FmDRVv)(rn+fk1Yzhcp14yw3Di#tW^85Hq1ZQVh1EGVb^Pax`C0-tS*wo!YH)*C?b4l>Vd)h$bQvM zNSz2P#E`kRXV;MRxn)F7ARMWiXcSQ(iu@Eq6X`bGc#i~zADH>Am4e1_OzOkKBI!m< z5joA{8()ep_|OZrSOWD$LqRZUQF*|}qFR(&V0a?+IQvVvdeiP8IhwTVglv`-h2`=uZ zwI0SrzXM<)cRy#(T3;a9U#glApBlWuG3yBb(Dk~5p$5_3H;wnI@2XOw=YrfS{!*7u z!a)pbk#MBP%1@F8K3KPxe-~fzp(YrDTIB`9&np ztMlJ}{Q*|$yDUgbRY&CGkDxUh_5?3`NWEGwS7;n+Y6(spup!c*h{@AP*SUfef@0ej zlCCAABKL2mkX~}vCOp`U((16TP~2 zxKU*Dd2$2VNmPQMwt~1_3Aj|k8m7@uWe7mq1%nXTy!oGrE^CkEty^Pbnro5D>Aspl ziUt=k7gWZqNu}1Qa&_*oo?Z2$e^eRLTjSg3$omYe6;Z8!i9pU+Of8oM{Iqvl_}wkRr_ix0&v0i6~@8!2pJC z0?yO1Lt}PzprseZS^620EvXAmX#;6|$gCV5aw66pHHh;7pohN53HJUgym11h0jGT- znJ#Tb$S;1B9Xh0Q7{kcJ_icsw*?<*Go{dAqDRdLD{m}#B1gZm$H28~O^a20@7UFd; z^36^G%h6?Y1+qrj_`+%8r5B+Oov?kBJsBZ})OR8HZny>6jN6V{zL7h7RpcaO z5gO`zz>0is7z+KjO(6iDFK#}CfU5I7l!)6=*Ub>G`aIq+tQvmPydGtaCD@oHL7j90pUrRf%j^&T{Jpd~)}G*FsWLG6xG|$2-QLDh zs_|#`jtveNrTh3?w*S(#Uy?=#qbF-XKV_X`86NIM@j3^XQuIuxS==-_^47lWv$vJq zAS-P47_7Qm>CT+iJm*k8G{$l8J-3y)##sctTD3kLG_*=!qr&g1_QQB(#59Eb%crLV zyB0Zy2en_nt@k~(T!~f6Jdu38;wfg|vSD{Jz{iU_vPH+URQobavCM`S`ojBP9;v#WL= z>Z>yLbwtLvJL$L%%hHAtZ)_WxxdjDH?IaWh#|7-DgT4f|^*0Mk?5N0h@9(^Ql#GIQ zIPZo_?1=li8lhhfl>D5VUi_o>5u6|BkcdlML!dv$Kug0CZ>N#VXU~Vj14NKiemoKL z8^EUPT9E^p7+)OUXJn4d@ETz@+s$N&yHVJsIlvm?kZ-d?&o2WH?C?`O%u(#MA9=o$ zFRG_EyMLUP8e&~#83rVlo?X{NHswSt)xi)PQDuT0WK_FkPNI*INOd%XY!yZvU(ZCP zliy@uGXh7|XauM@$j8aYgvj>o&U@JHj=HIZDP;bHTs~l z#J%r#h;A3H8V{i4hs=?{$rrsAJ!&sZf`nK1fw!_E1@2Ahg8SUhmgqI(azDLQ4M@iN zC^^OE24Bns*a5 zYX13M#}>VKWJ{)NbfNLRWwol7POHxS-zz(`+@#DH?~BEaN{`5>vKM7uzs4yEHtZ6? z%b<$VnhJ`OpC?)Tqq&=9t&ST?%NVFxmMrV7#gut+RWr>z947bo(U#Wsuepn;P z2CFR7mLNf@aY{4MQuz%Ey_;>92&Gazd0)1pkuV>KwP$FYH0)fzzAyzRb18KS!#fP| zDm)@sn%t?!zS76PA{H;7zsbm`LvQ< zujr5-h3qLt)ms{ZJ(|eq>yHUna6T$~q`<+!`i{I(0_}hdrjfw{)sLA>FU8Y#MTJzp z*e50C?c_m#FH~OBZ=h(72(>P=r?NoiPd(G^7sqAn!C@OdA#19pGdl0kztLc)mT@T{ z7Be~GoNdd0Ql|LXVMXGm$s{cIE-K^)y>^vSo|GH9rXpxxY-9~l>K#GNBhG=cQF4E7 zPQ)#W|4u#$G>eS?!x}d`c5DPSs!rJR`EPK;qm=L;;3B%{6}`SczsYyVAJc^r&E~K3qG|;RjqSU&+G3p*#4?VcqDZL6ezyGN!?Y&PAwMCGXttI%{xhL8yTaq?Eq< z!Dq0=I+ttmY;wh-`*-ieub$qXlxxTIW~q$@is3z}pp}|?M^7ZTK{O0Ozv+k!XItJ+ ztD2PAu@d&U|2j?_Wf89v($Jg`iub|tXMYh$t*YDIY6l0NCw1QrW4HSAJsemBZ5|$j zc=CN$8#*Yuse0CY|4tT1nYIGD4da+(W(J81-!t|qml8NsXvJnZY`DH*u52LwX6eOO zS=lmpgRjK@9j`nq4@p?zC}%LCs(}HYF7g11dgq<8GP&Ae+?Lx6RC8wWoWnR|#or^n z#*ni+O-L?dB$%ySp}o{={FHmXPRfKTAdMzNu`Kd!M#z({447Y!hR=?#UPT;3TsRPy zp4Ci{VaAufHd_@(ddu4eCH3r1WMq6r})JmSFPFdJrM`@a{?6axWC`G}A^DqGoIlg>9x%ssmFHAc zA;yh4FL&ObY{WN%1-N@ZkQEL$$G;3WwzQ5C?2izkG6-CG9J)TO|IP@-u!NrV(IF!O z^B$y&*w-qd>0l#76lq7<_+~i>wK9}j-kQ0>a__4_Y*flT4t|0TMxo|Gdl@&YMrW|_ zyf>Rk#+sy%!PnQtW14igo!1F%z6^)&_4m-!DYYxrb*s~~n$M{#zt~jJ>Kv8V(9+i4 z*g{(07N zU#$Pmp^gUD6>_j~06U-(Tzh@KF1lDf`}$<|G`?Nw)~I&+x44+O+%wT@SuA!g(T~rN zmHKA#w_@Giy|&*|g5qw%ZWaBZm22Khof#gU!Ab#UAiM>3)4w63*ZCrZ{O}|}InXr) zDEm-=^Z;@c|HA%q!+sU`IP!MD@9;zfov$>&X%zS7{fYQ{R}k>5k%iHQbAPk6 zv>`9*-r5WeOnzihj!z!MY(Xwx=F_No(zlR6)h*&N*Y?j*K;h+iW6?!6m(t{sdS4>4 zTY#&rxiRB(jqCp|IZW2TpJOt1#LY=mIgpIsnu_FWt6e;Mw;{xXkgAk8nI`qZsD(Bv zyvkm`XZB0;m2<6&qi_R=jZU%pn;+RV=FBo@`K9B9KhnO?%gL_4Nh)<;z>P1{#oja~ zP5Tq~;tO(M&{(VFdC$4z)(}~%)j} zHaDuLH34?Tfy}eJl|Mlb3)|1$JHVBocd@TYa85+6|IRZ*9m?fCGU0)xkq{6-Cf*ZaN#F@~PP8t@EI#8X^FN|lf;z-*2tigPkH zbrg##Zrs60*X2O={)MXU%7Jr7nG#W4#aq<9*%R6EOj#p%)rC#(AeEk5y&=)qjcZUYRKJY3dvzFX0C%hZGvfmP~T#f zQE#0|`ZS;WNqe8?#T>YB${6@t4y*v{!=MN#$xTUjBy>z@K=aez!CKP*$1RsptqQGc zk|dGUV%496zS~E$+R}9%)*?sIBLm?z(d9%m`4Vn|Q4@2fa3w3t2p9ictT=2AdNUk? zLMN+KIpxkKthpLGVjEiap8)2v_dljd3GU)?Wp^bc@nX?%6L_7;3XYi#EDg^QzNTP` zBCVgG%9kK`2UACUoY-(lhqhT1bsm4*L4MLduukZszN-JxqW4DwVYV}pKLAJ%KHlO7 zpyewOysjBD1=o3I%T2PT-pko?rE%RcxC@rsV8_gkw$Oz4V4M&15?no@=0_tjhZ+fC z8$IL`v60`W-u5o)k=v(nZlh|cA|eqX{NLI6KX&^c_5V%M|5cUzFV+9;;P?NfNc#_` z|9SmC{EUV0?-Bt45rGV0H$DE%j^h-f<+aM~_CI_MRr*hAsiLC&dxP{(H~m8q(toG_ E0K6^9ApigX literal 0 HcmV?d00001 diff --git a/src/Umbraco.Tests/Services/ConsentServiceTests.cs b/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs similarity index 94% rename from src/Umbraco.Tests/Services/ConsentServiceTests.cs rename to src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs index a27d6a164e..7b01bc126f 100644 --- a/src/Umbraco.Tests/Services/ConsentServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs @@ -2,19 +2,21 @@ using System.Linq; using NUnit.Framework; using Umbraco.Core.Models; -using Umbraco.Tests.TestHelpers; +using Umbraco.Core.Services; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Services { [TestFixture] + [Explicit] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] - public class ConsentServiceTests : TestWithDatabaseBase + public class ConsentServiceTests : UmbracoIntegrationTest { [Test] public void CanCrudConsent() { - var consentService = ServiceContext.ConsentService; + var consentService = GetRequiredService(); // can register @@ -109,7 +111,7 @@ namespace Umbraco.Tests.Services [Test] public void CanRegisterConsentWithoutComment() { - var consentService = ServiceContext.ConsentService; + var consentService = GetRequiredService(); // Attept to add consent without a comment consentService.RegisterConsent("user/1234", "app1", "consentWithoutComment", ConsentState.Granted); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 8bb8937992..9c026de798 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -160,7 +160,6 @@ - @@ -186,7 +185,6 @@ - From 8c5e348437019c8263001d243b8ba730b158ced7 Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 2 Oct 2020 14:15:46 +0200 Subject: [PATCH 04/36] Move CachedDataTypeServiceTests --- .../Services/CachedDataTypeServiceTests.cs | 13 ++++++++++--- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 10 insertions(+), 4 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/CachedDataTypeServiceTests.cs (58%) diff --git a/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs b/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs similarity index 58% rename from src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs rename to src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs index ee08c16bdd..7ff14b4697 100644 --- a/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs @@ -2,6 +2,9 @@ using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; +using Umbraco.Core.Services; +using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Services @@ -12,8 +15,12 @@ namespace Umbraco.Tests.Services [TestFixture] [Apartment(ApartmentState.STA)] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] - public class CachedDataTypeServiceTests : TestWithSomeContentBase + public class CachedDataTypeServiceTests : UmbracoIntegrationTest { + private IDataTypeService DataTypeService => GetRequiredService(); + private ILocalizedTextService LocalizedTextService => GetRequiredService(); + private ILocalizationService LocalizationService => GetRequiredService(); + /// /// This tests validates that with the new scope changes that the underlying cache policies work - in this case it tests that the cache policy /// with Count verification works. @@ -21,9 +28,9 @@ namespace Umbraco.Tests.Services [Test] public void DataTypeService_Can_Get_All() { - var dataTypeService = ServiceContext.DataTypeService; + var dataTypeService = (DataTypeService) GetRequiredService(); - IDataType dataType = new DataType(new LabelPropertyEditor(Logger, IOHelper, DataTypeService,LocalizedTextService, LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; + IDataType dataType = new DataType(new LabelPropertyEditor(Logger, IOHelper, DataTypeService, LocalizedTextService, LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; dataTypeService.Save(dataType); //Get all the first time (no cache) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 9c026de798..4fdc1b8d58 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -184,7 +184,6 @@ - From e4dd5abd3e12f35a650e77158866c3adfe80b060 Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 2 Oct 2020 14:16:36 +0200 Subject: [PATCH 05/36] Fix NewSchemaPerFixture I don't know if this is a hacky fix, someone might have to take a look at it --- .../Packaging/CreatedPackagesRepositoryTests.cs | 1 - .../Services/ConsentServiceTests.cs | 1 - .../Testing/LocalDbTestDatabase.cs | 9 +++++++++ .../Testing/UmbracoIntegrationTest.cs | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs index 3243c267eb..53b81fba8a 100644 --- a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs @@ -20,7 +20,6 @@ using Umbraco.Tests.Testing; namespace Umbraco.Tests.Packaging { [TestFixture] - [Explicit] // TODO: find out why tests only run one at at time, the tests get blocked after the first test [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] public class CreatedPackagesRepositoryTests : UmbracoIntegrationTest { diff --git a/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs b/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs index 7b01bc126f..cfb8303a0d 100644 --- a/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs @@ -9,7 +9,6 @@ using Umbraco.Tests.Testing; namespace Umbraco.Tests.Services { [TestFixture] - [Explicit] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] public class ConsentServiceTests : UmbracoIntegrationTest { diff --git a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs index 01abe90b32..09c0a994c9 100644 --- a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs +++ b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs @@ -25,6 +25,14 @@ namespace Umbraco.Tests.Integration.Testing public const string InstanceName = "UmbracoTests"; public const string DatabaseName = "UmbracoTests"; + public bool HasSchema + { + get + { + return !(_schemaPool is null) && !_schemaPool.CanAttach; + } + } + private readonly ILogger _logger; private readonly LocalDb _localDb; private readonly IUmbracoVersion _umbracoVersion; @@ -254,6 +262,7 @@ namespace Umbraco.Tests.Integration.Testing private class DatabasePool { + public bool CanAttach => _readyQueue.Count > 0; private readonly LocalDb _localDb; private readonly LocalDb.Instance _instance; private readonly string _filesPath; diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 552bbf59ae..0279b7c58f 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -365,6 +365,23 @@ namespace Umbraco.Tests.Integration.Testing break; case UmbracoTestOptions.Database.NewSchemaPerFixture: + // If we try to AttachSchema before the old schema has been detached + // the process will be blocked since readyQueue remain empty + // Probably because the DB is blocked because it hasn't been detached + // Also if we attach a new schema for every test isn't it just essentially + // the same as NewSchemaPerTest? + if (db.HasSchema) + { + // We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings + if (!databaseFactory.Configured) + { + databaseFactory.Configure(db.ConnectionString, Constants.DatabaseProviders.SqlServer); + } + + // re-run the runtime level check + runtimeState.DetermineRuntimeLevel(); + return; + } // New DB + Schema var newSchemaFixtureDbId = db.AttachSchema(); From ca2ec63dd660db6117f8e70d6966e6b23cb90583 Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 2 Oct 2020 14:35:24 +0200 Subject: [PATCH 06/36] Re-configure current factory in NewSchemaPerFixture like in NewSchemaPerTest --- .../Testing/UmbracoIntegrationTest.cs | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 0279b7c58f..d4dd610f75 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -370,24 +370,23 @@ namespace Umbraco.Tests.Integration.Testing // Probably because the DB is blocked because it hasn't been detached // Also if we attach a new schema for every test isn't it just essentially // the same as NewSchemaPerTest? - if (db.HasSchema) + if (!db.HasSchema) { - // We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings - if (!databaseFactory.Configured) - { - databaseFactory.Configure(db.ConnectionString, Constants.DatabaseProviders.SqlServer); - } + // New DB + Schema + var newSchemaFixtureDbId = db.AttachSchema(); - // re-run the runtime level check - runtimeState.DetermineRuntimeLevel(); - return; + // Add teardown callback + OnFixtureTearDown(() => db.Detach(newSchemaFixtureDbId)); } - // New DB + Schema - var newSchemaFixtureDbId = db.AttachSchema(); + // We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings + if (!databaseFactory.Configured) + { + databaseFactory.Configure(db.ConnectionString, Constants.DatabaseProviders.SqlServer); + } - // Add teardown callback - OnFixtureTearDown(() => db.Detach(newSchemaFixtureDbId)); + // re-run the runtime level check + runtimeState.DetermineRuntimeLevel(); break; case UmbracoTestOptions.Database.NewEmptyPerFixture: From 07d943e37ac970e8120ad9006ba5123e787a0881 Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 2 Oct 2020 14:46:14 +0200 Subject: [PATCH 07/36] Migrate FileServiceTests --- .../Services/FileServiceTests.cs | 75 +++++++++++++++++++ .../Services/FileServiceTests.cs | 75 ------------------- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 3 files changed, 75 insertions(+), 76 deletions(-) create mode 100644 src/Umbraco.Tests.Integration/Services/FileServiceTests.cs delete mode 100644 src/Umbraco.Tests/Services/FileServiceTests.cs diff --git a/src/Umbraco.Tests.Integration/Services/FileServiceTests.cs b/src/Umbraco.Tests.Integration/Services/FileServiceTests.cs new file mode 100644 index 0000000000..52a0b0e654 --- /dev/null +++ b/src/Umbraco.Tests.Integration/Services/FileServiceTests.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using NUnit.Framework; +using Umbraco.Core.Services; +using Umbraco.Tests.Integration.Testing; +using Umbraco.Tests.Testing; + +namespace Umbraco.Tests.Services +{ + [TestFixture] + [Apartment(ApartmentState.STA)] + [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] + public class FileServiceTests : UmbracoIntegrationTest + { + private IFileService FileService => GetRequiredService(); + + [Test] + public void Create_Template_Then_Assign_Child() + { + var child = FileService.CreateTemplateWithIdentity("Child", "child", "test"); + var parent = FileService.CreateTemplateWithIdentity("Parent", "parent", "test"); + + child.SetMasterTemplate(parent); + FileService.SaveTemplate(child); + + child = FileService.GetTemplate(child.Id); + + Assert.AreEqual(parent.Alias, child.MasterTemplateAlias); + + } + + [Test] + public void Create_Template_With_Child_Then_Unassign() + { + var parent = FileService.CreateTemplateWithIdentity("Parent", "parent", "test"); + var child = FileService.CreateTemplateWithIdentity("Child", "child", "test", parent); + + child.SetMasterTemplate(null); + FileService.SaveTemplate(child); + + child = FileService.GetTemplate(child.Id); + + Assert.AreEqual(null, child.MasterTemplateAlias); + } + + [Test] + public void Can_Query_Template_Children() + { + var parent = FileService.CreateTemplateWithIdentity("Parent", "parent", "test"); + var child1 = FileService.CreateTemplateWithIdentity("Child1", "child1", "test", parent); + var child2 = FileService.CreateTemplateWithIdentity("Child2", "child2", "test", parent); + + var children = FileService.GetTemplates(parent.Id).Select(x => x.Id).ToArray(); + + Assert.IsTrue(children.Contains(child1.Id)); + Assert.IsTrue(children.Contains(child2.Id)); + } + + [Test] + public void Create_Template_With_Custom_Alias() + { + var template = FileService.CreateTemplateWithIdentity("Test template", "customTemplateAlias", "test"); + + FileService.SaveTemplate(template); + + template = FileService.GetTemplate(template.Id); + + Assert.AreEqual("Test template", template.Name); + Assert.AreEqual("customTemplateAlias", template.Alias); + } + + } +} diff --git a/src/Umbraco.Tests/Services/FileServiceTests.cs b/src/Umbraco.Tests/Services/FileServiceTests.cs deleted file mode 100644 index fa27a3ee81..0000000000 --- a/src/Umbraco.Tests/Services/FileServiceTests.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using NUnit.Framework; -using Umbraco.Tests.TestHelpers; -using Umbraco.Tests.Testing; - -namespace Umbraco.Tests.Services -{ - [TestFixture] - [Apartment(ApartmentState.STA)] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] - public class FileServiceTests : TestWithSomeContentBase - { - [Test] - public void Create_Template_Then_Assign_Child() - { - var child = ServiceContext.FileService.CreateTemplateWithIdentity("Child", "child", "test"); - var parent = ServiceContext.FileService.CreateTemplateWithIdentity("Parent", "parent", "test"); - - child.SetMasterTemplate(parent); - ServiceContext.FileService.SaveTemplate(child); - - child = ServiceContext.FileService.GetTemplate(child.Id); - - Assert.AreEqual(parent.Alias, child.MasterTemplateAlias); - - } - - [Test] - public void Create_Template_With_Child_Then_Unassign() - { - var parent = ServiceContext.FileService.CreateTemplateWithIdentity("Parent", "parent", "test"); - var child = ServiceContext.FileService.CreateTemplateWithIdentity("Child", "child", "test", parent); - - child.SetMasterTemplate(null); - ServiceContext.FileService.SaveTemplate(child); - - child = ServiceContext.FileService.GetTemplate(child.Id); - - Assert.AreEqual(null, child.MasterTemplateAlias); - } - - [Test] - public void Can_Query_Template_Children() - { - var parent = ServiceContext.FileService.CreateTemplateWithIdentity("Parent", "parent", "test"); - var child1 = ServiceContext.FileService.CreateTemplateWithIdentity("Child1", "child1", "test", parent); - var child2 = ServiceContext.FileService.CreateTemplateWithIdentity("Child2", "child2", "test", parent); - - var children = ServiceContext.FileService.GetTemplates(parent.Id).Select(x => x.Id).ToArray(); - - Assert.IsTrue(children.Contains(child1.Id)); - Assert.IsTrue(children.Contains(child2.Id)); - } - - [Test] - public void Create_Template_With_Custom_Alias() - { - var template = ServiceContext.FileService.CreateTemplateWithIdentity("Test template", "customTemplateAlias", "test"); - - ServiceContext.FileService.SaveTemplate(template); - - template = ServiceContext.FileService.GetTemplate(template.Id); - - Assert.AreEqual("Test template", template.Name); - Assert.AreEqual("customTemplateAlias", template.Alias); - } - - } -} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 4fdc1b8d58..2b19706e81 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -262,7 +262,6 @@ - From 7ad3cfc40311f7a9da853c87ebba36ce8bac8dae Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 2 Oct 2020 14:52:48 +0200 Subject: [PATCH 08/36] Migrate KeyValueServiceTests --- .../Services/KeyValueServiceTests.cs | 16 +++++++++------- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 9 insertions(+), 8 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/KeyValueServiceTests.cs (83%) diff --git a/src/Umbraco.Tests/Services/KeyValueServiceTests.cs b/src/Umbraco.Tests.Integration/Services/KeyValueServiceTests.cs similarity index 83% rename from src/Umbraco.Tests/Services/KeyValueServiceTests.cs rename to src/Umbraco.Tests.Integration/Services/KeyValueServiceTests.cs index 5ab29258f5..03e9d84787 100644 --- a/src/Umbraco.Tests/Services/KeyValueServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/KeyValueServiceTests.cs @@ -1,7 +1,7 @@ using System.Threading; using NUnit.Framework; -using NUnit.Framework.Internal; using Umbraco.Core.Services; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Services @@ -14,13 +14,15 @@ namespace Umbraco.Tests.Services [TestFixture] [Apartment(ApartmentState.STA)] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] - public class KeyValueServiceTests : TestWithSomeContentBase + public class KeyValueServiceTests : UmbracoIntegrationTest { + private IKeyValueService KeyValueService => GetRequiredService(); + [Test] public void GetValue_ForMissingKey_ReturnsNull() { // Arrange - var keyValueService = ServiceContext.KeyValueService; + var keyValueService = KeyValueService; // Act var value = keyValueService.GetValue("foo"); @@ -33,7 +35,7 @@ namespace Umbraco.Tests.Services public void GetValue_ForExistingKey_ReturnsValue() { // Arrange - var keyValueService = ServiceContext.KeyValueService; + var keyValueService = KeyValueService; keyValueService.SetValue("foo", "bar"); // Act @@ -47,7 +49,7 @@ namespace Umbraco.Tests.Services public void SetValue_ForExistingKey_SavesValue() { // Arrange - var keyValueService = ServiceContext.KeyValueService; + var keyValueService = KeyValueService; keyValueService.SetValue("foo", "bar"); // Act @@ -62,7 +64,7 @@ namespace Umbraco.Tests.Services public void TrySetValue_ForExistingKeyWithProvidedValue_ReturnsTrueAndSetsValue() { // Arrange - var keyValueService = ServiceContext.KeyValueService; + var keyValueService = KeyValueService; keyValueService.SetValue("foo", "bar"); // Act @@ -78,7 +80,7 @@ namespace Umbraco.Tests.Services public void TrySetValue_ForExistingKeyWithoutProvidedValue_ReturnsFalseAndDoesNotSetValue() { // Arrange - var keyValueService = ServiceContext.KeyValueService; + var keyValueService = KeyValueService; keyValueService.SetValue("foo", "bar"); // Act diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 2b19706e81..114e7f5369 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -140,7 +140,6 @@ - From 8404ae63c08accbf5e014bbb9199f22432e7ddfe Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 5 Oct 2020 08:13:52 +0200 Subject: [PATCH 09/36] Change HasSchema to CanAttachSchema in LocalDbTestDatabase It's more indicative of what it's actually checking for. --- .../Packaging/CreatedPackagesRepositoryTests.cs | 1 - .../Testing/LocalDbTestDatabase.cs | 8 +------- .../Testing/UmbracoIntegrationTest.cs | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs index 53b81fba8a..6f91bc3c26 100644 --- a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; -using System.Threading; using System.Threading.Tasks; using System.Xml.Linq; using NUnit.Framework; diff --git a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs index 09c0a994c9..9194747034 100644 --- a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs +++ b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs @@ -25,13 +25,7 @@ namespace Umbraco.Tests.Integration.Testing public const string InstanceName = "UmbracoTests"; public const string DatabaseName = "UmbracoTests"; - public bool HasSchema - { - get - { - return !(_schemaPool is null) && !_schemaPool.CanAttach; - } - } + public bool CanAttachSchema => _schemaPool is null || _schemaPool.CanAttach; private readonly ILogger _logger; private readonly LocalDb _localDb; diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index d4dd610f75..94b2f30694 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -370,7 +370,7 @@ namespace Umbraco.Tests.Integration.Testing // Probably because the DB is blocked because it hasn't been detached // Also if we attach a new schema for every test isn't it just essentially // the same as NewSchemaPerTest? - if (!db.HasSchema) + if (db.CanAttachSchema) { // New DB + Schema var newSchemaFixtureDbId = db.AttachSchema(); From b181fa0e0106d61813fae5f047c14a9a735357dd Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 5 Oct 2020 09:38:30 +0200 Subject: [PATCH 10/36] Migrate EntityServiceTests --- .../Services/EntityServiceTests.cs | 264 ++++++++++-------- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 150 insertions(+), 115 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/EntityServiceTests.cs (76%) diff --git a/src/Umbraco.Tests/Services/EntityServiceTests.cs b/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs similarity index 76% rename from src/Umbraco.Tests/Services/EntityServiceTests.cs rename to src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs index ca2f123deb..6001b85270 100644 --- a/src/Umbraco.Tests/Services/EntityServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs @@ -2,15 +2,15 @@ using System.Collections.Generic; using System.Linq; using System.Threading; +using System.Threading.Tasks; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; -using Umbraco.Core.Persistence.DatabaseModelDefinitions; +using Umbraco.Core.Persistence; using Umbraco.Core.Services; -using Umbraco.Tests.Common.Builders; -using Umbraco.Tests.TestHelpers; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -22,44 +22,55 @@ namespace Umbraco.Tests.Services [TestFixture] [Apartment(ApartmentState.STA)] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] - public class EntityServiceTests : TestWithSomeContentBase + public class EntityServiceTests : UmbracoIntegrationTest { private Language _langFr; private Language _langEs; - public override void SetUp() + private ILocalizationService LocalizationService => GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + private IContentService ContentService => GetRequiredService(); + private IEntityService EntityService => GetRequiredService(); + private ISqlContext SqlContext => GetRequiredService(); + private IMediaTypeService MediaTypeService => GetRequiredService(); + private IMediaService MediaService => GetRequiredService(); + private IFileService FileService => GetRequiredService(); + + public override async Task Setup() { - base.SetUp(); + await base.Setup(); if (_langFr == null && _langEs == null) { var globalSettings = new GlobalSettings(); _langFr = new Language(globalSettings, "fr-FR"); _langEs = new Language(globalSettings, "es-ES"); - ServiceContext.LocalizationService.Save(_langFr); - ServiceContext.LocalizationService.Save(_langEs); + LocalizationService.Save(_langFr); + LocalizationService.Save(_langEs); } + + CreateTestData(); } [Test] public void EntityService_Can_Get_Paged_Descendants_Ordering_Path() { - var contentType = ServiceContext.ContentTypeService.Get("umbTextpage"); + var contentType = ContentTypeService.Get("umbTextpage"); var root = MockedContent.CreateSimpleContent(contentType); - ServiceContext.ContentService.Save(root); + ContentService.Save(root); var rootId = root.Id; var ids = new List(); for (int i = 0; i < 10; i++) { var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root); - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); ids.Add(c1.Id); root = c1; // make a hierarchy } - var service = ServiceContext.EntityService; + var service = EntityService; long total; @@ -92,19 +103,19 @@ namespace Umbraco.Tests.Services public void EntityService_Can_Get_Paged_Content_Children() { - var contentType = ServiceContext.ContentTypeService.Get("umbTextpage"); + var contentType = ContentTypeService.Get("umbTextpage"); var root = MockedContent.CreateSimpleContent(contentType); - ServiceContext.ContentService.Save(root); + ContentService.Save(root); var ids = new List(); for (int i = 0; i < 10; i++) { var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root); - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); ids.Add(c1.Id); } - var service = ServiceContext.EntityService; + var service = EntityService; long total; @@ -136,26 +147,26 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Paged_Content_Descendants() { - var contentType = ServiceContext.ContentTypeService.Get("umbTextpage"); + var contentType = ContentTypeService.Get("umbTextpage"); var root = MockedContent.CreateSimpleContent(contentType); - ServiceContext.ContentService.Save(root); + ContentService.Save(root); var count = 0; for (int i = 0; i < 10; i++) { var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root); - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); count++; for (int j = 0; j < 5; j++) { var c2 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), c1); - ServiceContext.ContentService.Save(c2); + ContentService.Save(c2); count++; } } - var service = ServiceContext.EntityService; + var service = EntityService; long total; var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 31, out total).ToArray(); @@ -169,15 +180,15 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Paged_Content_Descendants_Including_Recycled() { - var contentType = ServiceContext.ContentTypeService.Get("umbTextpage"); + var contentType = ContentTypeService.Get("umbTextpage"); var root = MockedContent.CreateSimpleContent(contentType); - ServiceContext.ContentService.Save(root); + ContentService.Save(root); var toDelete = new List(); for (int i = 0; i < 10; i++) { var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root); - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); if (i % 2 == 0) { @@ -187,16 +198,16 @@ namespace Umbraco.Tests.Services for (int j = 0; j < 5; j++) { var c2 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), c1); - ServiceContext.ContentService.Save(c2); + ContentService.Save(c2); } } foreach (var content in toDelete) { - ServiceContext.ContentService.MoveToRecycleBin(content); + ContentService.MoveToRecycleBin(content); } - var service = ServiceContext.EntityService; + var service = EntityService; long total; //search at root to see if it returns recycled @@ -213,15 +224,15 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Paged_Content_Descendants_Without_Recycled() { - var contentType = ServiceContext.ContentTypeService.Get("umbTextpage"); + var contentType = ContentTypeService.Get("umbTextpage"); var root = MockedContent.CreateSimpleContent(contentType); - ServiceContext.ContentService.Save(root); + ContentService.Save(root); var toDelete = new List(); for (int i = 0; i < 10; i++) { var c1 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), root); - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); if (i % 2 == 0) { @@ -231,16 +242,16 @@ namespace Umbraco.Tests.Services for (int j = 0; j < 5; j++) { var c2 = MockedContent.CreateSimpleContent(contentType, Guid.NewGuid().ToString(), c1); - ServiceContext.ContentService.Save(c2); + ContentService.Save(c2); } } foreach (var content in toDelete) { - ServiceContext.ContentService.MoveToRecycleBin(content); + ContentService.MoveToRecycleBin(content); } - var service = ServiceContext.EntityService; + var service = EntityService; long total; //search at root to see if it returns recycled @@ -257,24 +268,24 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Paged_Content_Descendants_With_Search() { - var contentType = ServiceContext.ContentTypeService.Get("umbTextpage"); + var contentType = ContentTypeService.Get("umbTextpage"); var root = MockedContent.CreateSimpleContent(contentType); - ServiceContext.ContentService.Save(root); + ContentService.Save(root); for (int i = 0; i < 10; i++) { var c1 = MockedContent.CreateSimpleContent(contentType, "ssss" + Guid.NewGuid(), root); - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); for (int j = 0; j < 5; j++) { var c2 = MockedContent.CreateSimpleContent(contentType, "tttt" + Guid.NewGuid(), c1); - ServiceContext.ContentService.Save(c2); + ContentService.Save(c2); } } - var service = ServiceContext.EntityService; + var service = EntityService; long total; var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 10, out total, @@ -290,18 +301,18 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Paged_Media_Children() { - var folderType = ServiceContext.MediaTypeService.Get(1031); - var imageMediaType = ServiceContext.MediaTypeService.Get(1032); + var folderType = MediaTypeService.Get(1031); + var imageMediaType = MediaTypeService.Get(1032); var root = MockedMedia.CreateMediaFolder(folderType, -1); - ServiceContext.MediaService.Save(root); + MediaService.Save(root); for (int i = 0; i < 10; i++) { var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id); - ServiceContext.MediaService.Save(c1); + MediaService.Save(c1); } - var service = ServiceContext.EntityService; + var service = EntityService; long total; var entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 0, 6, out total).ToArray(); @@ -315,27 +326,27 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Paged_Media_Descendants() { - var folderType = ServiceContext.MediaTypeService.Get(1031); - var imageMediaType = ServiceContext.MediaTypeService.Get(1032); + var folderType = MediaTypeService.Get(1031); + var imageMediaType = MediaTypeService.Get(1032); var root = MockedMedia.CreateMediaFolder(folderType, -1); - ServiceContext.MediaService.Save(root); + MediaService.Save(root); var count = 0; for (int i = 0; i < 10; i++) { var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id); - ServiceContext.MediaService.Save(c1); + MediaService.Save(c1); count++; for (int j = 0; j < 5; j++) { var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id); - ServiceContext.MediaService.Save(c2); + MediaService.Save(c2); count++; } } - var service = ServiceContext.EntityService; + var service = EntityService; long total; var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 31, out total).ToArray(); @@ -349,16 +360,16 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Paged_Media_Descendants_Including_Recycled() { - var folderType = ServiceContext.MediaTypeService.Get(1031); - var imageMediaType = ServiceContext.MediaTypeService.Get(1032); + var folderType = MediaTypeService.Get(1031); + var imageMediaType = MediaTypeService.Get(1032); var root = MockedMedia.CreateMediaFolder(folderType, -1); - ServiceContext.MediaService.Save(root); + MediaService.Save(root); var toDelete = new List(); for (int i = 0; i < 10; i++) { var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id); - ServiceContext.MediaService.Save(c1); + MediaService.Save(c1); if (i % 2 == 0) { @@ -368,16 +379,16 @@ namespace Umbraco.Tests.Services for (int j = 0; j < 5; j++) { var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id); - ServiceContext.MediaService.Save(c2); + MediaService.Save(c2); } } foreach (var content in toDelete) { - ServiceContext.MediaService.MoveToRecycleBin(content); + MediaService.MoveToRecycleBin(content); } - var service = ServiceContext.EntityService; + var service = EntityService; long total; //search at root to see if it returns recycled @@ -394,16 +405,16 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Paged_Media_Descendants_Without_Recycled() { - var folderType = ServiceContext.MediaTypeService.Get(1031); - var imageMediaType = ServiceContext.MediaTypeService.Get(1032); + var folderType = MediaTypeService.Get(1031); + var imageMediaType = MediaTypeService.Get(1032); var root = MockedMedia.CreateMediaFolder(folderType, -1); - ServiceContext.MediaService.Save(root); + MediaService.Save(root); var toDelete = new List(); for (int i = 0; i < 10; i++) { var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id); - ServiceContext.MediaService.Save(c1); + MediaService.Save(c1); if (i % 2 == 0) { @@ -413,16 +424,16 @@ namespace Umbraco.Tests.Services for (int j = 0; j < 5; j++) { var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id); - ServiceContext.MediaService.Save(c2); + MediaService.Save(c2); } } foreach (var content in toDelete) { - ServiceContext.MediaService.MoveToRecycleBin(content); + MediaService.MoveToRecycleBin(content); } - var service = ServiceContext.EntityService; + var service = EntityService; long total; //search at root to see if it returns recycled @@ -439,27 +450,27 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Paged_Media_Descendants_With_Search() { - var folderType = ServiceContext.MediaTypeService.Get(1031); - var imageMediaType = ServiceContext.MediaTypeService.Get(1032); + var folderType = MediaTypeService.Get(1031); + var imageMediaType = MediaTypeService.Get(1032); var root = MockedMedia.CreateMediaFolder(folderType, -1); - ServiceContext.MediaService.Save(root); + MediaService.Save(root); for (int i = 0; i < 10; i++) { var c1 = MockedMedia.CreateMediaImage(imageMediaType, root.Id); c1.Name = "ssss" + Guid.NewGuid(); - ServiceContext.MediaService.Save(c1); + MediaService.Save(c1); for (int j = 0; j < 5; j++) { var c2 = MockedMedia.CreateMediaImage(imageMediaType, c1.Id); c2.Name = "tttt" + Guid.NewGuid(); - ServiceContext.MediaService.Save(c2); + MediaService.Save(c2); } } - var service = ServiceContext.EntityService; + var service = EntityService; long total; var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 10, out total, @@ -475,7 +486,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_Content_By_UmbracoObjectTypes() { - var service = ServiceContext.EntityService; + var service = EntityService; var entities = service.GetAll(UmbracoObjectTypes.Document).ToArray(); @@ -487,7 +498,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_Content_By_UmbracoObjectType_Id() { - var service = ServiceContext.EntityService; + var service = EntityService; var objectTypeId = Constants.ObjectTypes.Document; var entities = service.GetAll(objectTypeId).ToArray(); @@ -500,7 +511,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_Content_By_Type() { - var service = ServiceContext.EntityService; + var service = EntityService; var entities = service.GetAll().ToArray(); @@ -512,7 +523,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Child_Content_By_ParentId_And_UmbracoObjectType() { - var service = ServiceContext.EntityService; + var service = EntityService; var entities = service.GetChildren(-1, UmbracoObjectTypes.Document).ToArray(); @@ -524,17 +535,17 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Content_By_UmbracoObjectType_With_Variant_Names() { - var service = ServiceContext.EntityService; + var service = EntityService; var alias = "test" + Guid.NewGuid(); var contentType = MockedContentTypes.CreateSimpleContentType(alias, alias, false); contentType.Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var c1 = MockedContent.CreateSimpleContent(contentType, "Test", -1); c1.SetCultureName("Test - FR", _langFr.IsoCode); c1.SetCultureName("Test - ES", _langEs.IsoCode); - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); var result = service.Get(c1.Id, UmbracoObjectTypes.Document); Assert.AreEqual("Test - FR", result.Name); // got name from default culture @@ -548,15 +559,15 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Child_Content_By_ParentId_And_UmbracoObjectType_With_Variant_Names() { - var service = ServiceContext.EntityService; + var service = EntityService; var contentType = MockedContentTypes.CreateSimpleContentType("test1", "Test1", false); contentType.Variations = ContentVariation.Culture; - ServiceContext.ContentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var root = MockedContent.CreateSimpleContent(contentType); root.SetCultureName("Root", _langFr.IsoCode); // else cannot save - ServiceContext.ContentService.Save(root); + ContentService.Save(root); for (int i = 0; i < 10; i++) { @@ -570,7 +581,7 @@ namespace Umbraco.Tests.Services { c1.SetCultureName("Test", _langFr.IsoCode); // else cannot save } - ServiceContext.ContentService.Save(c1); + ContentService.Save(c1); } var entities = service.GetChildren(root.Id, UmbracoObjectTypes.Document).ToArray(); @@ -601,7 +612,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Children_By_ParentId() { - var service = ServiceContext.EntityService; + var service = EntityService; var entities = service.GetChildren(folderId); @@ -613,7 +624,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Descendants_By_ParentId() { - var service = ServiceContext.EntityService; + var service = EntityService; var entities = service.GetDescendants(folderId); @@ -625,7 +636,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Throws_When_Getting_All_With_Invalid_Type() { - var service = ServiceContext.EntityService; + var service = EntityService; var objectTypeId = Constants.ObjectTypes.ContentItem; Assert.Throws(() => service.GetAll()); @@ -635,7 +646,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_ContentTypes_By_UmbracoObjectTypes() { - var service = ServiceContext.EntityService; + var service = EntityService; var entities = service.GetAll(UmbracoObjectTypes.DocumentType).ToArray(); @@ -646,7 +657,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_ContentTypes_By_UmbracoObjectType_Id() { - var service = ServiceContext.EntityService; + var service = EntityService; var objectTypeId = Constants.ObjectTypes.DocumentType; var entities = service.GetAll(objectTypeId).ToArray(); @@ -658,7 +669,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_ContentTypes_By_Type() { - var service = ServiceContext.EntityService; + var service = EntityService; var entities = service.GetAll().ToArray(); @@ -669,7 +680,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_Media_By_UmbracoObjectTypes() { - var service = ServiceContext.EntityService; + var service = EntityService; var entities = service.GetAll(UmbracoObjectTypes.Media).ToArray(); @@ -687,7 +698,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_ObjectType() { - var service = ServiceContext.EntityService; + var service = EntityService; var mediaObjectType = service.GetObjectType(1031); Assert.NotNull(mediaObjectType); @@ -697,8 +708,8 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Key_For_Id_With_Unknown_Type() { - var service = ServiceContext.EntityService; - var result = service.GetKey(1061, UmbracoObjectTypes.Unknown); + var service = EntityService; + var result = service.GetKey(1052, UmbracoObjectTypes.Unknown); Assert.IsTrue(result.Success); Assert.AreEqual(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), result.Result); @@ -707,8 +718,8 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Key_For_Id() { - var service = ServiceContext.EntityService; - var result = service.GetKey(1061, UmbracoObjectTypes.DocumentType); + var service = EntityService; + var result = service.GetKey(1052, UmbracoObjectTypes.DocumentType); Assert.IsTrue(result.Success); Assert.AreEqual(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), result.Result); @@ -717,9 +728,9 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Cannot_Get_Key_For_Id_With_Incorrect_Object_Type() { - var service = ServiceContext.EntityService; - var result1 = service.GetKey(1061, UmbracoObjectTypes.DocumentType); - var result2 = service.GetKey(1061, UmbracoObjectTypes.MediaType); + var service = EntityService; + var result1 = service.GetKey(1052, UmbracoObjectTypes.DocumentType); + var result2 = service.GetKey(1052, UmbracoObjectTypes.MediaType); Assert.IsTrue(result1.Success); Assert.IsFalse(result2.Success); @@ -728,27 +739,27 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Id_For_Key_With_Unknown_Type() { - var service = ServiceContext.EntityService; + var service = EntityService; var result = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.Unknown); Assert.IsTrue(result.Success); - Assert.AreEqual(1061, result.Result); + Assert.AreEqual(1052, result.Result); } [Test] public void EntityService_Can_Get_Id_For_Key() { - var service = ServiceContext.EntityService; + var service = EntityService; var result = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType); Assert.IsTrue(result.Success); - Assert.AreEqual(1061, result.Result); + Assert.AreEqual(1052, result.Result); } [Test] public void EntityService_Cannot_Get_Id_For_Key_With_Incorrect_Object_Type() { - var service = ServiceContext.EntityService; + var service = EntityService; var result1 = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType); var result2 = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.MediaType); @@ -759,7 +770,7 @@ namespace Umbraco.Tests.Services [Test] public void ReserveId() { - var service = ServiceContext.EntityService; + var service = EntityService; var guid = Guid.NewGuid(); // can reserve @@ -784,34 +795,59 @@ namespace Umbraco.Tests.Services private int folderId; - public override void CreateTestData() + public void CreateTestData() { if (_isSetup == false) { _isSetup = true; - base.CreateTestData(); + //Create and Save ContentType "umbTextpage" -> 1052 + ContentType contentType = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); + contentType.Key = new Guid("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"); + FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType! + ContentTypeService.Save(contentType); - //Create and Save folder-Media -> 1050 - var folderMediaType = ServiceContext.MediaTypeService.Get(1031); + //Create and Save Content "Homepage" based on "umbTextpage" -> 1053 + Content textpage = MockedContent.CreateSimpleContent(contentType); + textpage.Key = new Guid("B58B3AD4-62C2-4E27-B1BE-837BD7C533E0"); + ContentService.Save(textpage, 0); + + //Create and Save Content "Text Page 1" based on "umbTextpage" -> 1054 + Content subpage = MockedContent.CreateSimpleContent(contentType, "Text Page 1", textpage.Id); + subpage.ContentSchedule.Add(DateTime.Now.AddMinutes(-5), null); + ContentService.Save(subpage, 0); + + //Create and Save Content "Text Page 2" based on "umbTextpage" -> 1055 + Content subpage2 = MockedContent.CreateSimpleContent(contentType, "Text Page 2", textpage.Id); + ContentService.Save(subpage2, 0); + + //Create and Save Content "Text Page Deleted" based on "umbTextpage" -> 1056 + Content trashed = MockedContent.CreateSimpleContent(contentType, "Text Page Deleted", -20); + trashed.Trashed = true; + ContentService.Save(trashed, 0); + + //Create and Save folder-Media -> 1057 + var folderMediaType = MediaTypeService.Get(1031); var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1); - ServiceContext.MediaService.Save(folder, 0); + MediaService.Save(folder, 0); folderId = folder.Id; - //Create and Save image-Media -> 1051 - var imageMediaType = ServiceContext.MediaTypeService.Get(1032); + //Create and Save image-Media -> 1058 + var imageMediaType = MediaTypeService.Get(1032); var image = MockedMedia.CreateMediaImage(imageMediaType, folder.Id); - ServiceContext.MediaService.Save(image, 0); + MediaService.Save(image, 0); - //Create and Save file-Media -> 1052 - var fileMediaType = ServiceContext.MediaTypeService.Get(1033); + //Create and Save file-Media -> 1059 + var fileMediaType = MediaTypeService.Get(1033); var file = MockedMedia.CreateMediaFile(fileMediaType, folder.Id); - ServiceContext.MediaService.Save(file, 0); + MediaService.Save(file, 0); + // Create and save sub folder -> 1060 var subfolder = MockedMedia.CreateMediaFolder(folderMediaType, folder.Id); - ServiceContext.MediaService.Save(subfolder, 0); + MediaService.Save(subfolder, 0); + // Create and save sub folder -> 1061 var subfolder2 = MockedMedia.CreateMediaFolder(folderMediaType, subfolder.Id); - ServiceContext.MediaService.Save(subfolder2, 0); + MediaService.Save(subfolder2, 0); } } } diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 114e7f5369..5d833d67cb 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -332,7 +332,6 @@ - True From 4293337b81e86cfe561a651cc7840dc9c79c921c Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 5 Oct 2020 11:15:45 +0200 Subject: [PATCH 11/36] Migrate LocalizedTextServiceTests --- .../Umbraco.Core}/Services/LocalizedTextServiceTests.cs | 0 src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 1 deletion(-) rename src/{Umbraco.Tests => Umbraco.Tests.UnitTests/Umbraco.Core}/Services/LocalizedTextServiceTests.cs (100%) diff --git a/src/Umbraco.Tests/Services/LocalizedTextServiceTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/LocalizedTextServiceTests.cs similarity index 100% rename from src/Umbraco.Tests/Services/LocalizedTextServiceTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/LocalizedTextServiceTests.cs diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 5d833d67cb..8c3e26b30a 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -261,7 +261,6 @@ - From 6a9228af11b7e7d3a1f9a3dde356340a9a107dbe Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 5 Oct 2020 11:32:03 +0200 Subject: [PATCH 12/36] Migrate PropertyValidationServiceTest --- .../Umbraco.Core}/Services/PropertyValidationServiceTests.cs | 5 +++-- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.UnitTests/Umbraco.Core}/Services/PropertyValidationServiceTests.cs (98%) diff --git a/src/Umbraco.Tests/Services/PropertyValidationServiceTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/PropertyValidationServiceTests.cs similarity index 98% rename from src/Umbraco.Tests/Services/PropertyValidationServiceTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/PropertyValidationServiceTests.cs index 7b1dbc216d..8a7bad3d8c 100644 --- a/src/Umbraco.Tests/Services/PropertyValidationServiceTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/PropertyValidationServiceTests.cs @@ -7,14 +7,15 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; using Umbraco.Core.Services; using Umbraco.Core.Strings; -using Umbraco.Tests.Testing; using Umbraco.Web.PropertyEditors; namespace Umbraco.Tests.Services { [TestFixture] - public class PropertyValidationServiceTests : UmbracoTestBase + public class PropertyValidationServiceTests { + private IShortStringHelper ShortStringHelper => new DefaultShortStringHelper(new DefaultShortStringHelperConfig()); + private void MockObjects(out PropertyValidationService validationService, out IDataType dt) { var textService = new Mock(); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 8c3e26b30a..429de1c159 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -161,7 +161,6 @@ - From d7f0af7d4d20e0d8b5469bc90874b01e7f091740 Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 5 Oct 2020 11:38:05 +0200 Subject: [PATCH 13/36] Remove empty PackagingServiceTests --- .../Services/PackagingServiceTests.cs | 21 ------------------- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 22 deletions(-) delete mode 100644 src/Umbraco.Tests/Services/PackagingServiceTests.cs diff --git a/src/Umbraco.Tests/Services/PackagingServiceTests.cs b/src/Umbraco.Tests/Services/PackagingServiceTests.cs deleted file mode 100644 index f6878e9407..0000000000 --- a/src/Umbraco.Tests/Services/PackagingServiceTests.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.IO; -using NUnit.Framework; -using Umbraco.Core.IO; -using Umbraco.Core.Models.Packaging; -using Umbraco.Core.Services.Implement; -using Umbraco.Tests.TestHelpers; -using Umbraco.Tests.Testing; - -namespace Umbraco.Tests.Services -{ - [TestFixture] - [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] - public class PackagingServiceTests : TestWithSomeContentBase - { - - - - - - } -} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 429de1c159..a76ad495c5 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -266,7 +266,6 @@ - From ff2528bb0667edb152f6648e3970c690d2bf851b Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 5 Oct 2020 11:51:07 +0200 Subject: [PATCH 14/36] Migrate MacroServiceTests --- .../Services/MacroServiceTests.cs | 44 ++++++++++++------- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 27 insertions(+), 18 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/MacroServiceTests.cs (90%) diff --git a/src/Umbraco.Tests/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs similarity index 90% rename from src/Umbraco.Tests/Services/MacroServiceTests.cs rename to src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index ceecb72156..08a9b849c9 100644 --- a/src/Umbraco.Tests/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -1,15 +1,16 @@ using System; using System.Linq; using System.Threading; +using System.Threading.Tasks; using Moq; using NUnit.Framework; using Umbraco.Core.Cache; using Umbraco.Core.Logging; using Umbraco.Core.Models; - -using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; +using Umbraco.Core.Services; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; namespace Umbraco.Tests.Services @@ -17,13 +18,22 @@ namespace Umbraco.Tests.Services [TestFixture] [Apartment(ApartmentState.STA)] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] - public class MacroServiceTests : TestWithSomeContentBase + public class MacroServiceTests : UmbracoIntegrationTest { - public override void CreateTestData() - { - base.CreateTestData(); + private IMacroService MacroService => GetRequiredService(); - var provider = TestObjects.GetScopeProvider(Logger); + public override Task Setup() + { + var setup = base.Setup(); + CreateTestData(); + return setup; + } + + public void CreateTestData() + { + // base.CreateTestData(); + + var provider = ScopeProvider; using (var scope = provider.CreateScope()) { var repository = new MacroRepository((IScopeAccessor) provider, AppCaches.Disabled, Mock.Of(), ShortStringHelper); @@ -45,7 +55,7 @@ namespace Umbraco.Tests.Services public void Can_Get_By_Alias() { // Arrange - var macroService = ServiceContext.MacroService; + var macroService = MacroService; // Act var macro = macroService.GetByAlias("test1"); @@ -59,7 +69,7 @@ namespace Umbraco.Tests.Services public void Can_Get_All() { // Arrange - var macroService = ServiceContext.MacroService; + var macroService = MacroService; // Act var result = macroService.GetAll(); @@ -72,7 +82,7 @@ namespace Umbraco.Tests.Services public void Can_Create() { // Arrange - var macroService = ServiceContext.MacroService; + var macroService = MacroService; // Act var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); @@ -99,7 +109,7 @@ namespace Umbraco.Tests.Services public void Can_Delete() { // Arrange - var macroService = ServiceContext.MacroService; + var macroService = MacroService; var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); macroService.Save(macro); @@ -118,7 +128,7 @@ namespace Umbraco.Tests.Services public void Can_Update() { // Arrange - var macroService = ServiceContext.MacroService; + var macroService = MacroService; IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); macroService.Save(macro); @@ -142,7 +152,7 @@ namespace Umbraco.Tests.Services public void Can_Update_Property() { // Arrange - var macroService = ServiceContext.MacroService; + var macroService = MacroService; IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); macro.Properties.Add(new MacroProperty("blah", "Blah", 0, "blah")); macroService.Save(macro); @@ -173,7 +183,7 @@ namespace Umbraco.Tests.Services public void Can_Update_Remove_Property() { // Arrange - var macroService = ServiceContext.MacroService; + var macroService = MacroService; IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); macro.Properties.Add(new MacroProperty("blah1", "Blah1", 0, "blah1")); macro.Properties.Add(new MacroProperty("blah2", "Blah2", 1, "blah2")); @@ -217,7 +227,7 @@ namespace Umbraco.Tests.Services [Test] public void Can_Add_And_Remove_Properties() { - var macroService = ServiceContext.MacroService; + var macroService = MacroService; var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); //adds some properties @@ -252,7 +262,7 @@ namespace Umbraco.Tests.Services public void Cannot_Save_Macro_With_Empty_Name() { // Arrange - var macroService = ServiceContext.MacroService; + var macroService = MacroService; var macro = new Macro(ShortStringHelper, "test", string.Empty, "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); // Act & Assert @@ -263,7 +273,7 @@ namespace Umbraco.Tests.Services //public void Can_Get_Many_By_Alias() //{ // // Arrange - // var macroService = ServiceContext.MacroService; + // var macroService = MacroService; // // Act // var result = macroService.GetAll("test1", "test2"); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index a76ad495c5..7f0ba64d39 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -268,7 +268,6 @@ - From 8c9a55b0bc051dba21e6cef4b7b2e490a640928a Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 5 Oct 2020 12:44:42 +0200 Subject: [PATCH 15/36] Migrate ContentTypeServiceExtensionsTests --- .../Services/ContentTypeServiceExtensionsTests.cs | 7 ++++--- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.UnitTests/Umbraco.Core}/Services/ContentTypeServiceExtensionsTests.cs (98%) diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentTypeServiceExtensionsTests.cs similarity index 98% rename from src/Umbraco.Tests/Services/ContentTypeServiceExtensionsTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentTypeServiceExtensionsTests.cs index d0f817542b..c37d5c9427 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/ContentTypeServiceExtensionsTests.cs @@ -5,15 +5,16 @@ using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using Umbraco.Tests.TestHelpers.Entities; -using Umbraco.Tests.Testing; namespace Umbraco.Tests.Services { [TestFixture] - [UmbracoTest(WithApplication = true)] - public class ContentTypeServiceExtensionsTests : UmbracoTestBase + public class ContentTypeServiceExtensionsTests { + private IShortStringHelper ShortStringHelper => new DefaultShortStringHelper(new DefaultShortStringHelperConfig()); + [Test] public void GetAvailableCompositeContentTypes_No_Overlap_By_Content_Type_And_Property_Type_Alias() { diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 7f0ba64d39..cb9d7f9e70 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -223,7 +223,6 @@ - From c97375d478be7e89c238d434bbb1ca980526c6ed Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 5 Oct 2020 13:33:39 +0200 Subject: [PATCH 16/36] Migrate ContentServicePublishBranchTests --- .../ContentServicePublishBranchTests.cs | 99 ++++++++++--------- .../Testing/UmbracoIntegrationTest.cs | 15 ++- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 3 files changed, 66 insertions(+), 49 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/ContentServicePublishBranchTests.cs (84%) diff --git a/src/Umbraco.Tests/Services/ContentServicePublishBranchTests.cs b/src/Umbraco.Tests.Integration/Services/ContentServicePublishBranchTests.cs similarity index 84% rename from src/Umbraco.Tests/Services/ContentServicePublishBranchTests.cs rename to src/Umbraco.Tests.Integration/Services/ContentServicePublishBranchTests.cs index 51adfbeae9..ba0f033b5f 100644 --- a/src/Umbraco.Tests/Services/ContentServicePublishBranchTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ContentServicePublishBranchTests.cs @@ -7,6 +7,7 @@ using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; @@ -16,8 +17,12 @@ namespace Umbraco.Tests.Services { [TestFixture] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true, WithApplication = true)] - public class ContentServicePublishBranchTests : TestWithDatabaseBase + public class ContentServicePublishBranchTests : UmbracoIntegrationTest { + private IContentService ContentService => GetRequiredService(); + private ILocalizationService LocalizationService => GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + [TestCase(1)] // use overload w/ culture: "*" [TestCase(2)] // use overload w/ cultures: new [] { "*" } public void Can_Publish_Invariant_Branch(int method) @@ -26,13 +31,13 @@ namespace Umbraco.Tests.Services IContent iRoot = new Content("iroot", -1, iContentType); iRoot.SetValue("ip", "iroot"); - ServiceContext.ContentService.Save(iRoot); + ContentService.Save(iRoot); IContent ii1 = new Content("ii1", iRoot, iContentType); ii1.SetValue("ip", "vii1"); - ServiceContext.ContentService.Save(ii1); + ContentService.Save(ii1); IContent ii2 = new Content("ii2", iRoot, iContentType); ii2.SetValue("ip", "vii2"); - ServiceContext.ContentService.Save(ii2); + ContentService.Save(ii2); // iroot !published !edited // ii1 !published !edited @@ -51,24 +56,24 @@ namespace Umbraco.Tests.Services // prepare - ServiceContext.ContentService.SaveAndPublish(iRoot); - ServiceContext.ContentService.SaveAndPublish(ii1); + ContentService.SaveAndPublish(iRoot); + ContentService.SaveAndPublish(ii1); IContent ii11 = new Content("ii11", ii1, iContentType); ii11.SetValue("ip", "vii11"); - ServiceContext.ContentService.SaveAndPublish(ii11); + ContentService.SaveAndPublish(ii11); IContent ii12 = new Content("ii12", ii1, iContentType); ii11.SetValue("ip", "vii12"); - ServiceContext.ContentService.Save(ii12); + ContentService.Save(ii12); - ServiceContext.ContentService.SaveAndPublish(ii2); + ContentService.SaveAndPublish(ii2); IContent ii21 = new Content("ii21", ii2, iContentType); ii21.SetValue("ip", "vii21"); - ServiceContext.ContentService.SaveAndPublish(ii21); + ContentService.SaveAndPublish(ii21); IContent ii22 = new Content("ii22", ii2, iContentType); ii22.SetValue("ip", "vii22"); - ServiceContext.ContentService.Save(ii22); - ServiceContext.ContentService.Unpublish(ii2); + ContentService.Save(ii22); + ContentService.Unpublish(ii2); // iroot published !edited // ii1 published !edited @@ -94,9 +99,9 @@ namespace Umbraco.Tests.Services // prepare iRoot.SetValue("ip", "changed"); - ServiceContext.ContentService.Save(iRoot); + ContentService.Save(iRoot); ii11.SetValue("ip", "changed"); - ServiceContext.ContentService.Save(ii11); + ContentService.Save(ii11); // iroot published edited *** // ii1 published !edited @@ -133,7 +138,7 @@ namespace Umbraco.Tests.Services PublishResultType.SuccessPublishAlready, // was masked PublishResultType.SuccessPublish); - ii21 = ServiceContext.ContentService.GetById(ii21.Id); + ii21 = ContentService.GetById(ii21.Id); Assert.IsTrue(ii21.Published); } @@ -151,7 +156,7 @@ namespace Umbraco.Tests.Services vRoot.SetValue("vp", "vroot.de", "de"); vRoot.SetValue("vp", "vroot.ru", "ru"); vRoot.SetValue("vp", "vroot.es", "es"); - ServiceContext.ContentService.SaveAndPublish(vRoot); + ContentService.SaveAndPublish(vRoot); //create/publish child IContent iv1 = new Content("iv1", vRoot, vContentType, "de"); @@ -162,13 +167,13 @@ namespace Umbraco.Tests.Services iv1.SetValue("vp", "iv1.de", "de"); iv1.SetValue("vp", "iv1.ru", "ru"); iv1.SetValue("vp", "iv1.es", "es"); - ServiceContext.ContentService.SaveAndPublish(iv1); + ContentService.SaveAndPublish(iv1); //update the child iv1.SetValue("vp", "UPDATED-iv1.de", "de"); - ServiceContext.ContentService.Save(iv1); + ContentService.Save(iv1); - var r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); //no culture specified so "*" is used, so all cultures + var r = ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); //no culture specified so "*" is used, so all cultures Assert.AreEqual(PublishResultType.SuccessPublishAlready, r[0].Result); Assert.AreEqual(PublishResultType.SuccessPublishCulture, r[1].Result); } @@ -187,7 +192,7 @@ namespace Umbraco.Tests.Services vRoot.SetValue("vp", "vroot.de", "de"); vRoot.SetValue("vp", "vroot.ru", "ru"); vRoot.SetValue("vp", "vroot.es", "es"); - ServiceContext.ContentService.SaveAndPublish(vRoot); + ContentService.SaveAndPublish(vRoot); //create/publish child IContent iv1 = new Content("iv1", vRoot, vContentType, "de"); @@ -198,13 +203,13 @@ namespace Umbraco.Tests.Services iv1.SetValue("vp", "iv1.de", "de"); iv1.SetValue("vp", "iv1.ru", "ru"); iv1.SetValue("vp", "iv1.es", "es"); - ServiceContext.ContentService.SaveAndPublish(iv1); + ContentService.SaveAndPublish(iv1); //update the child iv1.SetValue("vp", "UPDATED-iv1.de", "de"); - var saveResult = ServiceContext.ContentService.Save(iv1); + var saveResult = ContentService.Save(iv1); - var r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray(); + var r = ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray(); Assert.AreEqual(PublishResultType.SuccessPublishAlready, r[0].Result); Assert.AreEqual(PublishResultType.SuccessPublishCulture, r[1].Result); } @@ -222,7 +227,7 @@ namespace Umbraco.Tests.Services vRoot.SetValue("vp", "vroot.de", "de"); vRoot.SetValue("vp", "vroot.ru", "ru"); vRoot.SetValue("vp", "vroot.es", "es"); - ServiceContext.ContentService.Save(vRoot); + ContentService.Save(vRoot); IContent iv1 = new Content("iv1", vRoot, vContentType, "de"); iv1.SetCultureName("iv1.de", "de"); @@ -232,7 +237,7 @@ namespace Umbraco.Tests.Services iv1.SetValue("vp", "iv1.de", "de"); iv1.SetValue("vp", "iv1.ru", "ru"); iv1.SetValue("vp", "iv1.es", "es"); - ServiceContext.ContentService.Save(iv1); + ContentService.Save(iv1); IContent iv2 = new Content("iv2", vRoot, vContentType, "de"); iv2.SetCultureName("iv2.de", "de"); @@ -242,7 +247,7 @@ namespace Umbraco.Tests.Services iv2.SetValue("vp", "iv2.de", "de"); iv2.SetValue("vp", "iv2.ru", "ru"); iv2.SetValue("vp", "iv2.es", "es"); - ServiceContext.ContentService.Save(iv2); + ContentService.Save(iv2); // vroot !published !edited // iv1 !published !edited @@ -251,7 +256,7 @@ namespace Umbraco.Tests.Services // !force = publishes those that are actually published, and have changes // here: nothing - var r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); // no culture specified = all cultures + var r = ContentService.SaveAndPublishBranch(vRoot, false).ToArray(); // no culture specified = all cultures // not forcing, iv1 and iv2 not published yet: only root got published AssertPublishResults(r, x => x.Content.Name, @@ -264,15 +269,15 @@ namespace Umbraco.Tests.Services vRoot.SetValue("vp", "changed.de", "de"); vRoot.SetValue("vp", "changed.ru", "ru"); vRoot.SetValue("vp", "changed.es", "es"); - ServiceContext.ContentService.Save(vRoot); // now root has drafts in all cultures + ContentService.Save(vRoot); // now root has drafts in all cultures - ServiceContext.ContentService.SaveAndPublish(iv1, new []{"de", "ru"}); // now iv1 de and ru are published + ContentService.SaveAndPublish(iv1, new []{"de", "ru"}); // now iv1 de and ru are published iv1.SetValue("ip", "changed"); iv1.SetValue("vp", "changed.de", "de"); iv1.SetValue("vp", "changed.ru", "ru"); iv1.SetValue("vp", "changed.es", "es"); - ServiceContext.ContentService.Save(iv1); // now iv1 has drafts in all cultures + ContentService.Save(iv1); // now iv1 has drafts in all cultures // validate - everything published for root, because no culture was specified = all Assert.IsTrue(vRoot.Published); @@ -286,7 +291,7 @@ namespace Umbraco.Tests.Services Assert.IsTrue(iv1.IsCulturePublished("ru")); Assert.IsFalse(iv1.IsCulturePublished("es")); - r = ServiceContext.ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray(); + r = ContentService.SaveAndPublishBranch(vRoot, false, "de").ToArray(); // not forcing, iv2 not published yet: only root and iv1 got published AssertPublishResults(r, x => x.Content.Name, @@ -332,21 +337,21 @@ namespace Umbraco.Tests.Services // invariant root -> invariant -> variant iRoot = new Content("iroot", -1, iContentType); iRoot.SetValue("ip", "iroot"); - ServiceContext.ContentService.SaveAndPublish(iRoot); + ContentService.SaveAndPublish(iRoot); ii1 = new Content("ii1", iRoot, iContentType); ii1.SetValue("ip", "vii1"); - ServiceContext.ContentService.SaveAndPublish(ii1); + ContentService.SaveAndPublish(ii1); ii1.SetValue("ip", "changed"); - ServiceContext.ContentService.Save(ii1); + ContentService.Save(ii1); iv11 = new Content("iv11.de", ii1, vContentType, "de"); iv11.SetValue("ip", "iv11"); iv11.SetValue("vp", "iv11.de", "de"); iv11.SetValue("vp", "iv11.ru", "ru"); iv11.SetValue("vp", "iv11.es", "es"); - ServiceContext.ContentService.Save(iv11); + ContentService.Save(iv11); iv11.SetCultureName("iv11.ru", "ru"); - var xxx = ServiceContext.ContentService.SaveAndPublish(iv11, new []{"de", "ru"}); + var xxx = ContentService.SaveAndPublish(iv11, new []{"de", "ru"}); Assert.AreEqual("iv11.de", iv11.GetValue("vp", "de", published: true)); Assert.AreEqual("iv11.ru", iv11.GetValue("vp", "ru", published: true)); @@ -354,7 +359,7 @@ namespace Umbraco.Tests.Services iv11.SetValue("ip", "changed"); iv11.SetValue("vp", "changed.de", "de"); iv11.SetValue("vp", "changed.ru", "ru"); - ServiceContext.ContentService.Save(iv11); + ContentService.Save(iv11); } [Test] @@ -362,7 +367,7 @@ namespace Umbraco.Tests.Services { Can_Publish_Mixed_Branch(out var iRoot, out var ii1, out var iv11); - var r = ServiceContext.ContentService.SaveAndPublishBranch(iRoot, false, "de").ToArray(); + var r = ContentService.SaveAndPublishBranch(iRoot, false, "de").ToArray(); AssertPublishResults(r, x => x.Content.Name, "iroot", "ii1", "iv11.de"); AssertPublishResults(r, x => x.Result, @@ -388,7 +393,7 @@ namespace Umbraco.Tests.Services { Can_Publish_Mixed_Branch(out var iRoot, out var ii1, out var iv11); - var r = ServiceContext.ContentService.SaveAndPublishBranch(iRoot, false, new[] { "de", "ru" }).ToArray(); + var r = ContentService.SaveAndPublishBranch(iRoot, false, new[] { "de", "ru" }).ToArray(); AssertPublishResults(r, x => x.Content.Name, "iroot", "ii1", "iv11.de"); AssertPublishResults(r, x => x.Result, @@ -423,18 +428,18 @@ namespace Umbraco.Tests.Services } private void Reload(ref IContent document) - => document = ServiceContext.ContentService.GetById(document.Id); + => document = ContentService.GetById(document.Id); private void CreateTypes(out IContentType iContentType, out IContentType vContentType) { var globalSettings = new GlobalSettings(); var langDe = new Language(globalSettings, "de") { IsDefault = true }; - ServiceContext.LocalizationService.Save(langDe); + LocalizationService.Save(langDe); var langRu = new Language(globalSettings, "ru"); - ServiceContext.LocalizationService.Save(langRu); + LocalizationService.Save(langRu); var langEs = new Language(globalSettings, "es"); - ServiceContext.LocalizationService.Save(langEs); + LocalizationService.Save(langEs); iContentType = new ContentType(ShortStringHelper, -1) { @@ -443,7 +448,7 @@ namespace Umbraco.Tests.Services Variations = ContentVariation.Nothing }; iContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "ip") { Variations = ContentVariation.Nothing }); - ServiceContext.ContentTypeService.Save(iContentType); + ContentTypeService.Save(iContentType); vContentType = new ContentType(ShortStringHelper, -1) { @@ -453,7 +458,7 @@ namespace Umbraco.Tests.Services }; vContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "ip") { Variations = ContentVariation.Nothing }); vContentType.AddPropertyType(new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Nvarchar, "vp") { Variations = ContentVariation.Culture }); - ServiceContext.ContentTypeService.Save(vContentType); + ContentTypeService.Save(vContentType); } private IEnumerable SaveAndPublishInvariantBranch(IContent content, bool force, int method) @@ -463,9 +468,9 @@ namespace Umbraco.Tests.Services switch (method) { case 1: - return ServiceContext.ContentService.SaveAndPublishBranch(content, force, culture: "*"); + return ContentService.SaveAndPublishBranch(content, force, culture: "*"); case 2: - return ServiceContext.ContentService.SaveAndPublishBranch(content, force, cultures: new [] { "*" }); + return ContentService.SaveAndPublishBranch(content, force, cultures: new [] { "*" }); default: throw new ArgumentOutOfRangeException(nameof(method)); } diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 94b2f30694..136a3f0b75 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -77,6 +77,8 @@ namespace Umbraco.Tests.Integration.Testing { foreach (var a in _testTeardown) a(); _testTeardown = null; + FirstTestInFixture = false; + FirstTestInSession = false; } [SetUp] @@ -246,6 +248,13 @@ namespace Umbraco.Tests.Integration.Testing { Services.GetRequiredService().EnsureBackofficeSecurity(); Services.GetRequiredService().EnsureUmbracoContext(); + OnTestTearDown(() => + { + var caches = GetRequiredService(); + caches.IsolatedCaches.ClearAllCaches(); + caches.RuntimeCache.Clear(); + caches.RequestCache.Clear(); + }); // get the currently set ptions var testOptions = TestOptionAttributeBase.GetTestOptions(); @@ -370,7 +379,7 @@ namespace Umbraco.Tests.Integration.Testing // Probably because the DB is blocked because it hasn't been detached // Also if we attach a new schema for every test isn't it just essentially // the same as NewSchemaPerTest? - if (db.CanAttachSchema) + if (FirstTestInFixture) { // New DB + Schema var newSchemaFixtureDbId = db.AttachSchema(); @@ -456,5 +465,9 @@ namespace Umbraco.Tests.Integration.Testing protected UserGroupBuilder UserGroupBuilder = new UserGroupBuilder(); #endregion + + protected static bool FirstTestInSession = true; + + protected bool FirstTestInFixture = true; } } diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index cb9d7f9e70..79a4f24bfd 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -155,7 +155,6 @@ - From 696c65222f296b9d4fc36cc074f340dcc071e049 Mon Sep 17 00:00:00 2001 From: Mole Date: Mon, 5 Oct 2020 15:04:41 +0200 Subject: [PATCH 17/36] Fix migration and clear caches --- .../CreatedPackagesRepositoryTests.cs | 4 +-- .../Services/EntityServiceTests.cs | 5 ++-- .../Services/MacroServiceTests.cs | 5 ++-- .../Testing/LocalDbTestDatabase.cs | 3 --- .../Testing/UmbracoIntegrationTest.cs | 27 ++++++++++++------- src/Umbraco.Tests/Umbraco.Tests.csproj | 8 ------ 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs index 6f91bc3c26..f95a7be093 100644 --- a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs @@ -24,10 +24,10 @@ namespace Umbraco.Tests.Packaging { private Guid _testBaseFolder; - public override Task Setup() + [SetUp] + public void SetupTestData() { _testBaseFolder = Guid.NewGuid(); - return base.Setup(); } public override void TearDown() diff --git a/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs b/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs index 6001b85270..fee2f07469 100644 --- a/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs @@ -36,10 +36,9 @@ namespace Umbraco.Tests.Services private IMediaService MediaService => GetRequiredService(); private IFileService FileService => GetRequiredService(); - public override async Task Setup() + [SetUp] + public void SetupTestData() { - await base.Setup(); - if (_langFr == null && _langEs == null) { var globalSettings = new GlobalSettings(); diff --git a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index 08a9b849c9..e8d3518367 100644 --- a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -22,11 +22,10 @@ namespace Umbraco.Tests.Services { private IMacroService MacroService => GetRequiredService(); - public override Task Setup() + [SetUp] + public void SetupTestData() { - var setup = base.Setup(); CreateTestData(); - return setup; } public void CreateTestData() diff --git a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs index 9194747034..01abe90b32 100644 --- a/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs +++ b/src/Umbraco.Tests.Integration/Testing/LocalDbTestDatabase.cs @@ -25,8 +25,6 @@ namespace Umbraco.Tests.Integration.Testing public const string InstanceName = "UmbracoTests"; public const string DatabaseName = "UmbracoTests"; - public bool CanAttachSchema => _schemaPool is null || _schemaPool.CanAttach; - private readonly ILogger _logger; private readonly LocalDb _localDb; private readonly IUmbracoVersion _umbracoVersion; @@ -256,7 +254,6 @@ namespace Umbraco.Tests.Integration.Testing private class DatabasePool { - public bool CanAttach => _readyQueue.Count > 0; private readonly LocalDb _localDb; private readonly LocalDb.Instance _instance; private readonly string _filesPath; diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index d7ca358220..18a9dfed89 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Integration.Testing [NonParallelizable] public abstract class UmbracoIntegrationTest { - + public static LightInjectContainer CreateUmbracoContainer(out UmbracoServiceProviderFactory serviceProviderFactory) { var container = UmbracoServiceProviderFactory.CreateServiceContainer(); @@ -251,13 +251,6 @@ namespace Umbraco.Tests.Integration.Testing { Services.GetRequiredService().EnsureBackofficeSecurity(); Services.GetRequiredService().EnsureUmbracoContext(); - OnTestTearDown(() => - { - var caches = GetRequiredService(); - caches.IsolatedCaches.ClearAllCaches(); - caches.RuntimeCache.Clear(); - caches.RequestCache.Clear(); - }); // get the currently set ptions var testOptions = TestOptionAttributeBase.GetTestOptions(); @@ -353,7 +346,14 @@ namespace Umbraco.Tests.Integration.Testing var newSchemaDbId = db.AttachSchema(); // Add teardown callback - OnTestTearDown(() => db.Detach(newSchemaDbId)); + OnTestTearDown(() => + { + db.Detach(newSchemaDbId); + var caches = GetRequiredService(); + caches.IsolatedCaches.ClearAllCaches(); + caches.RuntimeCache.Clear(); + caches.RequestCache.Clear(); + }); // We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings if (!databaseFactory.Configured) @@ -388,7 +388,14 @@ namespace Umbraco.Tests.Integration.Testing var newSchemaFixtureDbId = db.AttachSchema(); // Add teardown callback - OnFixtureTearDown(() => db.Detach(newSchemaFixtureDbId)); + OnFixtureTearDown(() => + { + db.Detach(newSchemaFixtureDbId); + var caches = GetRequiredService(); + caches.IsolatedCaches.ClearAllCaches(); + caches.RuntimeCache.Clear(); + caches.RequestCache.Clear(); + }); } // We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index e9a7b35640..1b3361cf76 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -222,8 +222,6 @@ - - @@ -259,17 +257,11 @@ - - - - - - From 471903b793ff54d3db8d00ad43dfba6768bae6e6 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 5 Oct 2020 16:59:26 +0200 Subject: [PATCH 18/36] Introduced NoopServerMessenger for integration tests Signed-off-by: Bjarke Berg --- .../Testing/IntegrationTestComposer.cs | 52 +++++++++++++++++++ .../Testing/UmbracoIntegrationTest.cs | 13 ++--- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs index ebbfb0be25..ce0261febf 100644 --- a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs +++ b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs @@ -1,6 +1,7 @@ using Moq; using NUnit.Framework; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Extensions.Options; @@ -14,6 +15,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; +using Umbraco.Core.Sync; using Umbraco.Core.WebAssets; using Umbraco.Examine; using Umbraco.Web.Compose; @@ -50,6 +52,10 @@ namespace Umbraco.Tests.Integration.Testing // replace this service so that it can lookup the correct file locations composition.RegisterUnique(GetLocalizedTextService); + + composition.RegisterUnique(); + + } /// @@ -100,5 +106,51 @@ namespace Umbraco.Tests.Integration.Testing } } + private class NoopServerMessenger : IServerMessenger + { + public NoopServerMessenger() + { } + + public void PerformRefresh(ICacheRefresher refresher, TPayload[] payload) + { + + } + + public void PerformRefresh(ICacheRefresher refresher, Func getNumericId, params T[] instances) + { + + } + + public void PerformRefresh(ICacheRefresher refresher, Func getGuidId, params T[] instances) + { + + } + + public void PerformRemove(ICacheRefresher refresher, Func getNumericId, params T[] instances) + { + + } + + public void PerformRemove(ICacheRefresher refresher, params int[] numericIds) + { + + } + + public void PerformRefresh(ICacheRefresher refresher, params int[] numericIds) + { + + } + + public void PerformRefresh(ICacheRefresher refresher, params Guid[] guidIds) + { + + } + + public void PerformRefreshAll(ICacheRefresher refresher) + { + + } + } + } } diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 18a9dfed89..fb57a543ac 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -247,11 +247,12 @@ namespace Umbraco.Tests.Integration.Testing CustomTestSetup(services); } + public virtual void Configure(IApplicationBuilder app) { Services.GetRequiredService().EnsureBackofficeSecurity(); Services.GetRequiredService().EnsureUmbracoContext(); - + // get the currently set ptions var testOptions = TestOptionAttributeBase.GetTestOptions(); if (testOptions.Boot) @@ -261,7 +262,7 @@ namespace Umbraco.Tests.Integration.Testing } #endregion - + #region LocalDb @@ -349,10 +350,6 @@ namespace Umbraco.Tests.Integration.Testing OnTestTearDown(() => { db.Detach(newSchemaDbId); - var caches = GetRequiredService(); - caches.IsolatedCaches.ClearAllCaches(); - caches.RuntimeCache.Clear(); - caches.RequestCache.Clear(); }); // We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings @@ -391,10 +388,6 @@ namespace Umbraco.Tests.Integration.Testing OnFixtureTearDown(() => { db.Detach(newSchemaFixtureDbId); - var caches = GetRequiredService(); - caches.IsolatedCaches.ClearAllCaches(); - caches.RuntimeCache.Clear(); - caches.RequestCache.Clear(); }); } From 30b0f142eb6e564d6a450c0cb4586d9ff072d287 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 5 Oct 2020 21:45:33 +0200 Subject: [PATCH 19/36] Migrated various service tests into the new integration or unit tests projects as appropriate. --- .../Services/ContentServiceEventTests.cs | 111 +++++++----------- .../Services/SectionServiceTests.cs | 21 ++-- .../Services/AmbiguousEventTests.cs | 78 ------------ src/Umbraco.Tests/Umbraco.Tests.csproj | 2 - .../UmbracoContext/UmbracoContextFactory.cs | 1 - 5 files changed, 53 insertions(+), 160 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/ContentServiceEventTests.cs (75%) delete mode 100644 src/Umbraco.Tests/Services/AmbiguousEventTests.cs diff --git a/src/Umbraco.Tests/Services/ContentServiceEventTests.cs b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs similarity index 75% rename from src/Umbraco.Tests/Services/ContentServiceEventTests.cs rename to src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs index c22679a820..8fcb41305b 100644 --- a/src/Umbraco.Tests/Services/ContentServiceEventTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs @@ -1,4 +1,5 @@ using System.Linq; +using System.Threading.Tasks; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration.Models; @@ -7,7 +8,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; -using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; @@ -18,13 +19,18 @@ namespace Umbraco.Tests.Services PublishedRepositoryEvents = true, WithApplication = true, Logger = UmbracoTestOptions.Logger.Console)] - public class ContentServiceEventTests : TestWithSomeContentBase + public class ContentServiceEventTests : UmbracoIntegrationTest { + private IContentTypeService _contentTypeService => GetRequiredService(); + private IContentService _contentService => GetRequiredService(); + private ILocalizationService _localizationService => GetRequiredService(); + private IFileService _fileService => GetRequiredService(); + private GlobalSettings _globalSettings; - public override void SetUp() + public override async Task Setup() { - base.SetUp(); + await base.Setup(); ContentRepositoryBase.ThrowOnWarning = true; _globalSettings = new GlobalSettings(); } @@ -38,28 +44,22 @@ namespace Umbraco.Tests.Services [Test] public void Saving_Culture() { - var languageService = ServiceContext.LocalizationService; - - languageService.Save(new Language(_globalSettings, "fr-FR")); - - var contentTypeService = ServiceContext.ContentTypeService; + _localizationService.Save(new Language(_globalSettings, "fr-FR")); var contentType = MockedContentTypes.CreateTextPageContentType(); - ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); + _fileService.SaveTemplate(contentType.DefaultTemplate); contentType.Variations = ContentVariation.Culture; foreach (var propertyType in contentType.PropertyTypes) propertyType.Variations = ContentVariation.Culture; - contentTypeService.Save(contentType); - - var contentService = ServiceContext.ContentService; + _contentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); document.SetCultureName("hello", "en-US"); document.SetCultureName("bonjour", "fr-FR"); - contentService.Save(document); + _contentService.Save(document); //re-get - dirty properties need resetting - document = contentService.GetById(document.Id); + document = _contentService.GetById(document.Id); // properties: title, bodyText, keywords, description document.SetValue("title", "title-en", "en-US"); @@ -88,7 +88,7 @@ namespace Umbraco.Tests.Services ContentService.Saved += OnSaved; try { - contentService.Save(document); + _contentService.Save(document); } finally { @@ -100,13 +100,9 @@ namespace Umbraco.Tests.Services [Test] public void Saving_Set_Value() { - var contentTypeService = ServiceContext.ContentTypeService; - var contentType = MockedContentTypes.CreateTextPageContentType(); - ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); - contentTypeService.Save(contentType); - - var contentService = ServiceContext.ContentService; + _fileService.SaveTemplate(contentType.DefaultTemplate); + _contentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); @@ -136,44 +132,37 @@ namespace Umbraco.Tests.Services ContentService.Saved += OnSaved; try { - contentService.Save(document); + _contentService.Save(document); } finally { ContentService.Saving -= OnSaving; ContentService.Saved -= OnSaved; } - } [Test] public void Publishing_Culture() { - var languageService = ServiceContext.LocalizationService; - - languageService.Save(new Language(_globalSettings, "fr-FR")); - - var contentTypeService = ServiceContext.ContentTypeService; + _localizationService.Save(new Language(_globalSettings, "fr-FR")); var contentType = MockedContentTypes.CreateTextPageContentType(); - ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); + _fileService.SaveTemplate(contentType.DefaultTemplate); contentType.Variations = ContentVariation.Culture; foreach (var propertyType in contentType.PropertyTypes) propertyType.Variations = ContentVariation.Culture; - contentTypeService.Save(contentType); - - var contentService = ServiceContext.ContentService; + _contentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); document.SetCultureName("hello", "en-US"); document.SetCultureName("bonjour", "fr-FR"); - contentService.Save(document); + _contentService.Save(document); Assert.IsFalse(document.IsCulturePublished("fr-FR")); Assert.IsFalse(document.IsCulturePublished("en-US")); //re-get - dirty properties need resetting - document = contentService.GetById(document.Id); + document = _contentService.GetById(document.Id); void OnPublishing(IContentService sender, ContentPublishingEventArgs e) { @@ -199,7 +188,7 @@ namespace Umbraco.Tests.Services ContentService.Published += OnPublished; try { - contentService.SaveAndPublish(document, "fr-FR"); + _contentService.SaveAndPublish(document, "fr-FR"); } finally { @@ -207,7 +196,7 @@ namespace Umbraco.Tests.Services ContentService.Published -= OnPublished; } - document = contentService.GetById(document.Id); + document = _contentService.GetById(document.Id); // ensure it works and does not throw Assert.IsTrue(document.IsCulturePublished("fr-FR")); @@ -217,13 +206,9 @@ namespace Umbraco.Tests.Services [Test] public void Publishing_Set_Value() { - var contentTypeService = ServiceContext.ContentTypeService; - var contentType = MockedContentTypes.CreateTextPageContentType(); - ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); - contentTypeService.Save(contentType); - - var contentService = ServiceContext.ContentService; + _fileService.SaveTemplate(contentType.DefaultTemplate); + _contentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); @@ -242,21 +227,21 @@ namespace Umbraco.Tests.Services Assert.AreSame("title", document.GetValue("title")); - //we're only dealing with invariant here + // We're only dealing with invariant here. var propValue = saved.Properties["title"].Values.First(x => x.Culture == null && x.Segment == null); Assert.AreEqual("title", propValue.EditedValue); Assert.AreEqual("title", propValue.PublishedValue); } - //We are binding to Saving (not Publishing), because the Publishing event is really just used for cancelling, it should not be - //used for setting values and it won't actually work! This is because the Publishing event is raised AFTER the values on the model - //are published, but Saving is raised BEFORE. + // We are binding to Saving (not Publishing), because the Publishing event is really just used for cancelling, it should not be + // used for setting values and it won't actually work! This is because the Publishing event is raised AFTER the values on the model + // are published, but Saving is raised BEFORE. ContentService.Saving += OnSaving; ContentService.Saved += OnSaved; try { - contentService.SaveAndPublish(document); + _contentService.SaveAndPublish(document); } finally { @@ -268,19 +253,15 @@ namespace Umbraco.Tests.Services [Test] public void Publishing_Set_Mandatory_Value() { - var contentTypeService = ServiceContext.ContentTypeService; - var contentType = MockedContentTypes.CreateTextPageContentType(); var titleProperty = contentType.PropertyTypes.First(x => x.Alias == "title"); titleProperty.Mandatory = true; // make this required! - ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); - contentTypeService.Save(contentType); - - var contentService = ServiceContext.ContentService; + _fileService.SaveTemplate(contentType.DefaultTemplate); + _contentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); - var result = contentService.SaveAndPublish(document); + var result = _contentService.SaveAndPublish(document); Assert.IsFalse(result.Success); Assert.AreEqual("title", result.InvalidProperties.First().Alias); @@ -297,13 +278,13 @@ namespace Umbraco.Tests.Services saved.SetValue("title", "title"); } - //We are binding to Saving (not Publishing), because the Publishing event is really just used for cancelling, it should not be - //used for setting values and it won't actually work! This is because the Publishing event is raised AFTER the values on the model - //are published, but Saving is raised BEFORE. + // We are binding to Saving (not Publishing), because the Publishing event is really just used for cancelling, it should not be + // used for setting values and it won't actually work! This is because the Publishing event is raised AFTER the values on the model + // are published, but Saving is raised BEFORE. ContentService.Saving += OnSaving; try { - result = contentService.SaveAndPublish(document); + result = _contentService.SaveAndPublish(document); Assert.IsTrue(result.Success); //will succeed now because we were able to specify the required value in the Saving event } finally @@ -315,20 +296,16 @@ namespace Umbraco.Tests.Services [Test] public void Unpublishing_Culture() { - var languageService = ServiceContext.LocalizationService; - - languageService.Save(new Language(_globalSettings, "fr-FR")); - - var contentTypeService = ServiceContext.ContentTypeService; + _localizationService.Save(new Language(_globalSettings, "fr-FR")); var contentType = MockedContentTypes.CreateTextPageContentType(); - ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); + _fileService.SaveTemplate(contentType.DefaultTemplate); contentType.Variations = ContentVariation.Culture; foreach (var propertyType in contentType.PropertyTypes) propertyType.Variations = ContentVariation.Culture; - contentTypeService.Save(contentType); + _contentTypeService.Save(contentType); - var contentService = (ContentService)ServiceContext.ContentService; + var contentService = (ContentService)_contentService; IContent document = new Content("content", -1, contentType); document.SetCultureName("hello", "en-US"); diff --git a/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs b/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs index 533a66ad96..a54a1c1c59 100644 --- a/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs @@ -1,12 +1,9 @@ -using NUnit.Framework; -using System.Linq; +using System.Linq; using System.Threading; -using Umbraco.Core; -using Umbraco.Core.Composing; +using NUnit.Framework; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; -using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; using Umbraco.Web.Services; @@ -21,8 +18,8 @@ namespace Umbraco.Tests.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class SectionServiceTests : UmbracoIntegrationTest { - private ISectionService SectionService => GetRequiredService(); - private IUserService UserService => GetRequiredService(); + private ISectionService _sectionService => GetRequiredService(); + private IUserService _userService => GetRequiredService(); [Test] public void SectionService_Can_Get_Allowed_Sections_For_User() @@ -31,7 +28,7 @@ namespace Umbraco.Tests.Services var user = CreateTestUser(); // Act - var result = SectionService.GetAllowedSections(user.Id).ToList(); + var result = _sectionService.GetAllowedSections(user.Id).ToList(); // Assert Assert.AreEqual(3, result.Count); @@ -46,7 +43,7 @@ namespace Umbraco.Tests.Services Username = "testUser", Email = "testuser@test.com", }; - UserService.Save(user, false); + _userService.Save(user, false); var userGroupA = new UserGroup(ShortStringHelper) { @@ -56,7 +53,7 @@ namespace Umbraco.Tests.Services userGroupA.AddAllowedSection("media"); userGroupA.AddAllowedSection("settings"); // TODO: This is failing the test - UserService.Save(userGroupA, new[] { user.Id }, false); + _userService.Save(userGroupA, new[] { user.Id }, false); var userGroupB = new UserGroup(ShortStringHelper) { @@ -65,9 +62,9 @@ namespace Umbraco.Tests.Services }; userGroupB.AddAllowedSection("settings"); userGroupB.AddAllowedSection("member"); - UserService.Save(userGroupB, new[] { user.Id }, false); + _userService.Save(userGroupB, new[] { user.Id }, false); - return UserService.GetUserById(user.Id); + return _userService.GetUserById(user.Id); } } } diff --git a/src/Umbraco.Tests/Services/AmbiguousEventTests.cs b/src/Umbraco.Tests/Services/AmbiguousEventTests.cs deleted file mode 100644 index e137da1188..0000000000 --- a/src/Umbraco.Tests/Services/AmbiguousEventTests.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Reflection; -using System.Text; -using NUnit.Framework; -using Umbraco.Core.Events; -using Umbraco.Core.Services.Implement; - -namespace Umbraco.Tests.Services -{ - [TestFixture] - public class AmbiguousEventTests - { - [Explicit] - [TestCase(typeof(ContentService))] - [TestCase(typeof(MediaService))] - public void ListAmbiguousEvents(Type serviceType) - { - var typedEventHandler = typeof(TypedEventHandler<,>); - - // get all events - var events = serviceType.GetEvents(BindingFlags.Static | BindingFlags.Public); - - string TypeName(Type type) - { - if (!type.IsGenericType) - return type.Name; - var sb = new StringBuilder(); - TypeNameSb(type, sb); - return sb.ToString(); - } - - void TypeNameSb(Type type, StringBuilder sb) - { - var name = type.Name; - var pos = name.IndexOf('`'); - name = pos > 0 ? name.Substring(0, pos) : name; - sb.Append(name); - if (!type.IsGenericType) - return; - sb.Append("<"); - var first = true; - foreach (var arg in type.GetGenericArguments()) - { - if (first) first = false; - else sb.Append(", "); - TypeNameSb(arg, sb); - } - sb.Append(">"); - } - - foreach (var e in events) - { - // only continue if this is a TypedEventHandler - if (!e.EventHandlerType.IsGenericType) continue; - var typeDef = e.EventHandlerType.GetGenericTypeDefinition(); - if (typedEventHandler != typeDef) continue; - - // get the event args type - var eventArgsType = e.EventHandlerType.GenericTypeArguments[1]; - - // try to find the event back, based upon sender type + args type - // exclude -ing (eg Saving) events, we don't deal with them in EventDefinitionBase (they always trigger) - var found = EventNameExtractor.FindEvents(serviceType, eventArgsType, EventNameExtractor.MatchIngNames); - - if (found.Length == 1) continue; - - if (found.Length == 0) - { - Console.WriteLine($"{typeof(ContentService).Name} {e.Name} {TypeName(eventArgsType)} NotFound"); - continue; - } - - Console.WriteLine($"{typeof(ContentService).Name} {e.Name} {TypeName(eventArgsType)} Ambiguous"); - Console.WriteLine("\t" + string.Join(", ", found)); - } - } - } -} \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 197e928e1f..b65cc2ff74 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -154,8 +154,6 @@ - - diff --git a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs index a31ef614cf..f50a2e2ba8 100644 --- a/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs +++ b/src/Umbraco.Web.Common/UmbracoContext/UmbracoContextFactory.cs @@ -96,7 +96,6 @@ namespace Umbraco.Web if (currentUmbracoContext != null) return new UmbracoContextReference(currentUmbracoContext, false, _umbracoContextAccessor); - var umbracoContext = CreateUmbracoContext(); _umbracoContextAccessor.UmbracoContext = umbracoContext; From 6736860f4bdfcc1a1a8b3e02d3332e5b3185c7de Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Mon, 5 Oct 2020 21:45:51 +0200 Subject: [PATCH 20/36] Removed duplicate depenency registration. --- .../Runtime/CoreInitialComposer.cs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs index fdd358e64a..7981d8c964 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs @@ -1,11 +1,12 @@ using System; using Examine; +using Microsoft.Extensions.Options; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Composing.CompositionExtensions; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Grid; -using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Configuration.Models; using Umbraco.Core.Dashboards; using Umbraco.Core.Dictionary; using Umbraco.Core.Events; @@ -18,7 +19,6 @@ using Umbraco.Core.Migrations; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Migrations.PostMigrations; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Core.Templates; using Umbraco.Core.Persistence; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; @@ -29,6 +29,7 @@ using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; using Umbraco.Core.Strings; using Umbraco.Core.Sync; +using Umbraco.Core.Templates; using Umbraco.Examine; using Umbraco.Infrastructure.Examine; using Umbraco.Infrastructure.Media; @@ -41,6 +42,7 @@ using Umbraco.Web.Features; using Umbraco.Web.HealthCheck; using Umbraco.Web.HealthCheck.NotificationMethods; using Umbraco.Web.Install; +using Umbraco.Web.Media; using Umbraco.Web.Media.EmbedProviders; using Umbraco.Web.Migrations.PostMigrations; using Umbraco.Web.Models.PublishedContent; @@ -55,9 +57,6 @@ using Umbraco.Web.Templates; using Umbraco.Web.Trees; using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator; using TextStringValueConverter = Umbraco.Core.PropertyEditors.ValueConverters.TextStringValueConverter; -using Umbraco.Core.Configuration.Models; -using Microsoft.Extensions.Options; -using Umbraco.Web.Media; namespace Umbraco.Core.Runtime { @@ -204,13 +203,6 @@ namespace Umbraco.Core.Runtime // Config manipulator composition.RegisterUnique(); - - // register the http context and umbraco context accessors - // we *should* use the HttpContextUmbracoContextAccessor, however there are cases when - // we have no http context, eg when booting Umbraco or in background threads, so instead - // let's use an hybrid accessor that can fall back to a ThreadStatic context. - composition.RegisterUnique(); - // register the umbraco context factory // composition.RegisterUnique(); composition.RegisterUnique(); @@ -353,7 +345,6 @@ namespace Umbraco.Core.Runtime return new PublishedContentQuery(umbCtx.UmbracoContext.PublishedSnapshot, factory.GetInstance(), factory.GetInstance()); }, Lifetime.Request); - composition.RegisterUnique(); // register the http context and umbraco context accessors From 30e49ac548b4cbfaf5604457368089948dfab8c6 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 6 Oct 2020 08:28:02 +0200 Subject: [PATCH 21/36] Fix after rebase. --- .../Services/ContentServiceEventTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs index 8fcb41305b..3222c1b052 100644 --- a/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs @@ -28,9 +28,9 @@ namespace Umbraco.Tests.Services private GlobalSettings _globalSettings; - public override async Task Setup() + public override void Setup() { - await base.Setup(); + base.Setup(); ContentRepositoryBase.ThrowOnWarning = true; _globalSettings = new GlobalSettings(); } From 1f83c610439c83435d2c5e5aa1f730ea7ef82db2 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 6 Oct 2020 09:23:15 +0200 Subject: [PATCH 22/36] Aligned service integration tests with naming convention for private variables and use of test model builders. --- .../TestHelpers/Entities/MockedUser.cs | 62 --- .../Services/AuditServiceTests.cs | 2 +- .../Services/ContentServiceEventTests.cs | 3 +- .../Services/LocalizationServiceTests.cs | 130 +++--- .../Services/MediaServiceTests.cs | 82 ++-- .../Services/PublicAccessServiceTests.cs | 54 +-- .../Services/SectionServiceTests.cs | 2 +- .../Services/TagServiceTests.cs | 50 +-- .../Services/UserServiceTests.cs | 404 ++++++++++-------- .../UserEditorAuthorizationHelperTests.cs | 67 +-- .../Services/AmbiguousEventTests.cs | 78 ++++ src/Umbraco.Tests/Umbraco.Tests.csproj | 2 +- 12 files changed, 497 insertions(+), 439 deletions(-) delete mode 100644 src/Umbraco.Tests.Common/TestHelpers/Entities/MockedUser.cs create mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/AmbiguousEventTests.cs diff --git a/src/Umbraco.Tests.Common/TestHelpers/Entities/MockedUser.cs b/src/Umbraco.Tests.Common/TestHelpers/Entities/MockedUser.cs deleted file mode 100644 index 5b77909fec..0000000000 --- a/src/Umbraco.Tests.Common/TestHelpers/Entities/MockedUser.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Moq; -using System; -using System.Collections.Generic; -using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Models.Membership; - -namespace Umbraco.Tests.Common.TestHelpers.Entities -{ - public static class MockedUser - { - /// - /// Returns a and ensures that the ToUserCache and FromUserCache methods are mapped correctly for - /// dealing with start node caches - /// - /// - public static Mock GetUserMock() - { - var userCache = new Dictionary(); - var userMock = new Mock(); - userMock.Setup(x => x.FromUserCache(It.IsAny())).Returns((string key) => userCache.TryGetValue(key, out var val) ? val is int[] iVal ? iVal : null : null); - userMock.Setup(x => x.ToUserCache(It.IsAny(), It.IsAny())).Callback((string key, int[] val) => userCache[key] = val); - return userMock; - } - - public static User CreateUser(string suffix = "") - { - var globalSettings = new GlobalSettings(); - var user = new User(globalSettings) - { - Language = "en", - IsApproved = true, - Name = "TestUser" + suffix, - RawPasswordValue = "testing", - IsLockedOut = false, - Email = "test" + suffix + "@test.com", - Username = "TestUser" + suffix - }; - - return user; - } - - public static IEnumerable CreateMulipleUsers(int amount, Action onCreating = null) - { - var list = new List(); - - var globalSettings = new GlobalSettings(); - for (var i = 0; i < amount; i++) - { - var name = "Member No-" + i; - var user = new User(globalSettings, name, "test" + i + "@test.com", "test" + i, "test" + i); - - onCreating?.Invoke(i, user); - - user.ResetDirtyProperties(false); - - list.Add(user); - } - - return list; - } - } -} diff --git a/src/Umbraco.Tests.Integration/Services/AuditServiceTests.cs b/src/Umbraco.Tests.Integration/Services/AuditServiceTests.cs index 9a0ba54082..474229372c 100644 --- a/src/Umbraco.Tests.Integration/Services/AuditServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/AuditServiceTests.cs @@ -9,7 +9,7 @@ using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; -namespace Umbraco.Tests.Services +namespace Umbraco.Tests.Integration.Services { [TestFixture] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] diff --git a/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs index 3222c1b052..e2b6d20d82 100644 --- a/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs @@ -1,5 +1,4 @@ using System.Linq; -using System.Threading.Tasks; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration.Models; @@ -12,7 +11,7 @@ using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; -namespace Umbraco.Tests.Services +namespace Umbraco.Tests.Integration.Services { [TestFixture] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, diff --git a/src/Umbraco.Tests.Integration/Services/LocalizationServiceTests.cs b/src/Umbraco.Tests.Integration/Services/LocalizationServiceTests.cs index 83d3476324..5c17666619 100644 --- a/src/Umbraco.Tests.Integration/Services/LocalizationServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/LocalizationServiceTests.cs @@ -31,7 +31,7 @@ namespace Umbraco.Tests.Integration.Services private int _englishLangId; private GlobalSettings _globalSettings; - private ILocalizationService LocalizationService => GetRequiredService(); + private ILocalizationService _localizationService => GetRequiredService(); [SetUp] public void SetUp() @@ -43,7 +43,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Get_Root_Dictionary_Items() { - var rootItems = LocalizationService.GetRootDictionaryItems(); + var rootItems = _localizationService.GetRootDictionaryItems(); Assert.NotNull(rootItems); Assert.IsTrue(rootItems.Any()); @@ -52,14 +52,14 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Determint_If_DictionaryItem_Exists() { - var exists = LocalizationService.DictionaryItemExists("Parent"); + var exists = _localizationService.DictionaryItemExists("Parent"); Assert.IsTrue(exists); } [Test] public void Can_Get_All_Languages() { - var languages = LocalizationService.GetAllLanguages(); + var languages = _localizationService.GetAllLanguages(); Assert.NotNull(languages); Assert.IsTrue(languages.Any()); Assert.That(languages.Count(), Is.EqualTo(3)); @@ -68,37 +68,37 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Get_Dictionary_Item_By_Int_Id() { - var parentItem = LocalizationService.GetDictionaryItemById(_parentItemIntId); + var parentItem = _localizationService.GetDictionaryItemById(_parentItemIntId); Assert.NotNull(parentItem); - var childItem = LocalizationService.GetDictionaryItemById(_childItemIntId); + var childItem = _localizationService.GetDictionaryItemById(_childItemIntId); Assert.NotNull(childItem); } [Test] public void Can_Get_Dictionary_Item_By_Guid_Id() { - var parentItem = LocalizationService.GetDictionaryItemById(_parentItemGuidId); + var parentItem = _localizationService.GetDictionaryItemById(_parentItemGuidId); Assert.NotNull(parentItem); - var childItem = LocalizationService.GetDictionaryItemById(_childItemGuidId); + var childItem = _localizationService.GetDictionaryItemById(_childItemGuidId); Assert.NotNull(childItem); } [Test] public void Can_Get_Dictionary_Item_By_Key() { - var parentItem = LocalizationService.GetDictionaryItemByKey("Parent"); + var parentItem = _localizationService.GetDictionaryItemByKey("Parent"); Assert.NotNull(parentItem); - var childItem = LocalizationService.GetDictionaryItemByKey("Child"); + var childItem = _localizationService.GetDictionaryItemByKey("Child"); Assert.NotNull(childItem); } [Test] public void Can_Get_Dictionary_Item_Children() { - var item = LocalizationService.GetDictionaryItemChildren(_parentItemGuidId); + var item = _localizationService.GetDictionaryItemChildren(_parentItemGuidId); Assert.NotNull(item); Assert.That(item.Count(), Is.EqualTo(1)); @@ -114,8 +114,8 @@ namespace Umbraco.Tests.Integration.Services { using (var scope = ScopeProvider.CreateScope()) { - var en = LocalizationService.GetLanguageById(_englishLangId); - var dk = LocalizationService.GetLanguageById(_danishLangId); + var en = _localizationService.GetLanguageById(_englishLangId); + var dk = _localizationService.GetLanguageById(_danishLangId); var currParentId = _childItemGuidId; for (var i = 0; i < 25; i++) @@ -137,8 +137,8 @@ namespace Umbraco.Tests.Integration.Services new DictionaryTranslation(dk, "BørnVærdi2 " + i) } }; - LocalizationService.Save(desc1); - LocalizationService.Save(desc2); + _localizationService.Save(desc1); + _localizationService.Save(desc2); currParentId = desc1.Key; } @@ -146,7 +146,7 @@ namespace Umbraco.Tests.Integration.Services scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; scope.Database.AsUmbracoDatabase().EnableSqlCount = true; - var items = LocalizationService.GetDictionaryItemDescendants(_parentItemGuidId).ToArray(); + var items = _localizationService.GetDictionaryItemDescendants(_parentItemGuidId).ToArray(); Debug.WriteLine("SQL CALLS: " + scope.Database.AsUmbracoDatabase().SqlCount); @@ -159,8 +159,8 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_GetLanguageById() { - var danish = LocalizationService.GetLanguageById(_danishLangId); - var english = LocalizationService.GetLanguageById(_englishLangId); + var danish = _localizationService.GetLanguageById(_danishLangId); + var english = _localizationService.GetLanguageById(_englishLangId); Assert.NotNull(danish); Assert.NotNull(english); } @@ -168,8 +168,8 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_GetLanguageByIsoCode() { - var danish = LocalizationService.GetLanguageByIsoCode("da-DK"); - var english = LocalizationService.GetLanguageByIsoCode("en-GB"); + var danish = _localizationService.GetLanguageByIsoCode("da-DK"); + var english = _localizationService.GetLanguageByIsoCode("en-GB"); Assert.NotNull(danish); Assert.NotNull(english); } @@ -177,14 +177,14 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Does_Not_Fail_When_Language_Doesnt_Exist() { - var language = LocalizationService.GetLanguageByIsoCode("sv-SE"); + var language = _localizationService.GetLanguageByIsoCode("sv-SE"); Assert.Null(language); } [Test] public void Does_Not_Fail_When_DictionaryItem_Doesnt_Exist() { - var item = LocalizationService.GetDictionaryItemByKey("RandomKey"); + var item = _localizationService.GetDictionaryItemByKey("RandomKey"); Assert.Null(item); } @@ -192,34 +192,34 @@ namespace Umbraco.Tests.Integration.Services public void Can_Delete_Language() { var norwegian = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian" }; - LocalizationService.Save(norwegian, 0); + _localizationService.Save(norwegian, 0); Assert.That(norwegian.HasIdentity, Is.True); var languageId = norwegian.Id; - LocalizationService.Delete(norwegian); + _localizationService.Delete(norwegian); - var language = LocalizationService.GetLanguageById(languageId); + var language = _localizationService.GetLanguageById(languageId); Assert.Null(language); } [Test] public void Can_Delete_Language_Used_As_Fallback() { - var danish = LocalizationService.GetLanguageByIsoCode("da-DK"); + var danish = _localizationService.GetLanguageByIsoCode("da-DK"); var norwegian = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian", FallbackLanguageId = danish.Id }; - LocalizationService.Save(norwegian, 0); + _localizationService.Save(norwegian, 0); var languageId = danish.Id; - LocalizationService.Delete(danish); + _localizationService.Delete(danish); - var language = LocalizationService.GetLanguageById(languageId); + var language = _localizationService.GetLanguageById(languageId); Assert.Null(language); } [Test] public void Can_Create_DictionaryItem_At_Root() { - var english = LocalizationService.GetLanguageByIsoCode("en-US"); + var english = _localizationService.GetLanguageByIsoCode("en-US"); var item = (IDictionaryItem)new DictionaryItem("Testing123") { @@ -228,10 +228,10 @@ namespace Umbraco.Tests.Integration.Services new DictionaryTranslation(english, "Hello world") } }; - LocalizationService.Save(item); + _localizationService.Save(item); //re-get - item = LocalizationService.GetDictionaryItemById(item.Id); + item = _localizationService.GetDictionaryItemById(item.Id); Assert.Greater(item.Id, 0); Assert.IsTrue(item.HasIdentity); @@ -243,18 +243,18 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Create_DictionaryItem_At_Root_With_Identity() { - var item = LocalizationService.CreateDictionaryItemWithIdentity( + var item = _localizationService.CreateDictionaryItemWithIdentity( "Testing12345", null, "Hellooooo"); //re-get - item = LocalizationService.GetDictionaryItemById(item.Id); + item = _localizationService.GetDictionaryItemById(item.Id); Assert.IsNotNull(item); Assert.Greater(item.Id, 0); Assert.IsTrue(item.HasIdentity); Assert.IsFalse(item.ParentId.HasValue); Assert.AreEqual("Testing12345", item.ItemKey); - var allLangs = LocalizationService.GetAllLanguages(); + var allLangs = _localizationService.GetAllLanguages(); Assert.Greater(allLangs.Count(), 0); foreach (var language in allLangs) { @@ -265,20 +265,20 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Add_Translation_To_Existing_Dictionary_Item() { - var english = LocalizationService.GetLanguageByIsoCode("en-US"); + var english = _localizationService.GetLanguageByIsoCode("en-US"); var item = (IDictionaryItem) new DictionaryItem("Testing123"); - LocalizationService.Save(item); + _localizationService.Save(item); //re-get - item = LocalizationService.GetDictionaryItemById(item.Id); + item = _localizationService.GetDictionaryItemById(item.Id); item.Translations = new List { new DictionaryTranslation(english, "Hello world") }; - LocalizationService.Save(item); + _localizationService.Save(item); Assert.AreEqual(1, item.Translations.Count()); foreach (var translation in item.Translations) @@ -289,14 +289,14 @@ namespace Umbraco.Tests.Integration.Services item.Translations = new List(item.Translations) { new DictionaryTranslation( - LocalizationService.GetLanguageByIsoCode("en-GB"), + _localizationService.GetLanguageByIsoCode("en-GB"), "My new value") }; - LocalizationService.Save(item); + _localizationService.Save(item); //re-get - item = LocalizationService.GetDictionaryItemById(item.Id); + item = _localizationService.GetDictionaryItemById(item.Id); Assert.AreEqual(2, item.Translations.Count()); Assert.AreEqual("Hello world", item.Translations.First().Value); @@ -306,27 +306,27 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Delete_DictionaryItem() { - var item = LocalizationService.GetDictionaryItemByKey("Child"); + var item = _localizationService.GetDictionaryItemByKey("Child"); Assert.NotNull(item); - LocalizationService.Delete(item); + _localizationService.Delete(item); - var deletedItem = LocalizationService.GetDictionaryItemByKey("Child"); + var deletedItem = _localizationService.GetDictionaryItemByKey("Child"); Assert.Null(deletedItem); } [Test] public void Can_Update_Existing_DictionaryItem() { - var item = LocalizationService.GetDictionaryItemByKey("Child"); + var item = _localizationService.GetDictionaryItemByKey("Child"); foreach (var translation in item.Translations) { translation.Value = translation.Value + "UPDATED"; } - LocalizationService.Save(item); + _localizationService.Save(item); - var updatedItem = LocalizationService.GetDictionaryItemByKey("Child"); + var updatedItem = _localizationService.GetDictionaryItemByKey("Child"); Assert.NotNull(updatedItem); foreach (var translation in updatedItem.Translations) @@ -339,7 +339,7 @@ namespace Umbraco.Tests.Integration.Services public void Find_BaseData_Language() { // Act - var languages = LocalizationService.GetAllLanguages(); + var languages = _localizationService.GetAllLanguages(); // Assert Assert.That(3, Is.EqualTo(languages.Count())); @@ -353,8 +353,8 @@ namespace Umbraco.Tests.Integration.Services var language = new Core.Models.Language(_globalSettings, isoCode); // Act - LocalizationService.Save(language); - var result = LocalizationService.GetLanguageByIsoCode(isoCode); + _localizationService.Save(language); + var result = _localizationService.GetLanguageByIsoCode(isoCode); // Assert Assert.NotNull(result); @@ -367,8 +367,8 @@ namespace Umbraco.Tests.Integration.Services var language = new Core.Models.Language(_globalSettings, isoCode); // Act - LocalizationService.Save(language); - var result = LocalizationService.GetLanguageById(language.Id); + _localizationService.Save(language); + var result = _localizationService.GetLanguageById(language.Id); // Assert Assert.NotNull(result); @@ -378,16 +378,16 @@ namespace Umbraco.Tests.Integration.Services public void Set_Default_Language() { var language = new Language(_globalSettings, "en-AU") {IsDefault = true}; - LocalizationService.Save(language); - var result = LocalizationService.GetLanguageById(language.Id); + _localizationService.Save(language); + var result = _localizationService.GetLanguageById(language.Id); Assert.IsTrue(result.IsDefault); var language2 = new Language(_globalSettings, "en-NZ") {IsDefault = true}; - LocalizationService.Save(language2); - var result2 = LocalizationService.GetLanguageById(language2.Id); + _localizationService.Save(language2); + var result2 = _localizationService.GetLanguageById(language2.Id); //re-get - result = LocalizationService.GetLanguageById(language.Id); + result = _localizationService.GetLanguageById(language.Id); Assert.IsTrue(result2.IsDefault); Assert.IsFalse(result.IsDefault); @@ -398,11 +398,11 @@ namespace Umbraco.Tests.Integration.Services { var isoCode = "en-AU"; var language = new Core.Models.Language(_globalSettings, isoCode); - LocalizationService.Save(language); + _localizationService.Save(language); // Act - LocalizationService.Delete(language); - var result = LocalizationService.GetLanguageByIsoCode(isoCode); + _localizationService.Delete(language); + var result = _localizationService.GetLanguageByIsoCode(isoCode); // Assert Assert.Null(result); @@ -412,8 +412,8 @@ namespace Umbraco.Tests.Integration.Services { var danish = new Language(_globalSettings, "da-DK") { CultureName = "Danish" }; var english = new Language(_globalSettings, "en-GB") { CultureName = "English" }; - LocalizationService.Save(danish, 0); - LocalizationService.Save(english, 0); + _localizationService.Save(danish, 0); + _localizationService.Save(english, 0); _danishLangId = danish.Id; _englishLangId = english.Id; @@ -425,7 +425,7 @@ namespace Umbraco.Tests.Integration.Services new DictionaryTranslation(danish, "ForældreVærdi") } }; - LocalizationService.Save(parentItem); + _localizationService.Save(parentItem); _parentItemGuidId = parentItem.Key; _parentItemIntId = parentItem.Id; @@ -437,7 +437,7 @@ namespace Umbraco.Tests.Integration.Services new DictionaryTranslation(danish, "BørnVærdi") } }; - LocalizationService.Save(childItem); + _localizationService.Save(childItem); _childItemGuidId = childItem.Key; _childItemIntId = childItem.Id; } diff --git a/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs index a43f21d061..89c01b54d3 100644 --- a/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs @@ -19,8 +19,8 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true)] public class MediaServiceTests : UmbracoIntegrationTest { - private IMediaService MediaService => GetRequiredService(); - private IMediaTypeService MediaTypeService => GetRequiredService(); + private IMediaService _mediaService => GetRequiredService(); + private IMediaTypeService _mediaTypeService => GetRequiredService(); /// /// Used to list out all ambiguous events that will require dispatching with a name @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Integration.Services [Test, Explicit] public void List_Ambiguous_Events() { - var events = MediaService.GetType().GetEvents(BindingFlags.Static | BindingFlags.Public); + var events = _mediaService.GetType().GetEvents(BindingFlags.Static | BindingFlags.Public); var typedEventHandler = typeof(TypedEventHandler<,>); foreach (var e in events) { @@ -52,30 +52,30 @@ namespace Umbraco.Tests.Integration.Services public void Get_Paged_Children_With_Media_Type_Filter() { var mediaType1 = MockedContentTypes.CreateImageMediaType("Image2"); - MediaTypeService.Save(mediaType1); + _mediaTypeService.Save(mediaType1); var mediaType2 = MockedContentTypes.CreateImageMediaType("Image3"); - MediaTypeService.Save(mediaType2); + _mediaTypeService.Save(mediaType2); for (var i = 0; i < 10; i++) { var m1 = MockedMedia.CreateMediaImage(mediaType1, -1); - MediaService.Save(m1); + _mediaService.Save(m1); var m2 = MockedMedia.CreateMediaImage(mediaType2, -1); - MediaService.Save(m2); + _mediaService.Save(m2); } long total; var provider = ScopeProvider; using (provider.CreateScope()) { - var result = MediaService.GetPagedChildren(-1, 0, 11, out total, + var result = _mediaService.GetPagedChildren(-1, 0, 11, out total, provider.SqlContext.Query() .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)), Ordering.By("SortOrder", Direction.Ascending)); Assert.AreEqual(11, result.Count()); Assert.AreEqual(20, total); - result = MediaService.GetPagedChildren(-1, 1, 11, out total, + result = _mediaService.GetPagedChildren(-1, 1, 11, out total, provider.SqlContext.Query() .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)), Ordering.By("SortOrder", Direction.Ascending)); @@ -89,10 +89,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var mediaItems = CreateTrashedTestMedia(); - var media = MediaService.GetById(mediaItems.Item3.Id); + var media = _mediaService.GetById(mediaItems.Item3.Id); // Act - MediaService.Move(media, mediaItems.Item2.Id); + _mediaService.Move(media, mediaItems.Item2.Id); // Assert Assert.That(media.ParentId, Is.EqualTo(mediaItems.Item2.Id)); @@ -104,10 +104,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var mediaItems = CreateTrashedTestMedia(); - var media = MediaService.GetById(mediaItems.Item1.Id); + var media = _mediaService.GetById(mediaItems.Item1.Id); // Act - MediaService.MoveToRecycleBin(media); + _mediaService.MoveToRecycleBin(media); // Assert Assert.That(media.ParentId, Is.EqualTo(-21)); @@ -119,11 +119,11 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var mediaItems = CreateTrashedTestMedia(); - var media = MediaService.GetById(mediaItems.Item4.Id); + var media = _mediaService.GetById(mediaItems.Item4.Id); // Act - moving out of recycle bin - MediaService.Move(media, mediaItems.Item1.Id); - var mediaChild = MediaService.GetById(mediaItems.Item5.Id); + _mediaService.Move(media, mediaItems.Item1.Id); + var mediaChild = _mediaService.GetById(mediaItems.Item5.Id); // Assert Assert.That(media.ParentId, Is.EqualTo(mediaItems.Item1.Id)); @@ -137,11 +137,11 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var mediaType = MockedContentTypes.CreateVideoMediaType(); - MediaTypeService.Save(mediaType); - var media = MediaService.CreateMedia(string.Empty, -1, "video"); + _mediaTypeService.Save(mediaType); + var media = _mediaService.CreateMedia(string.Empty, -1, "video"); // Act & Assert - Assert.Throws(() => MediaService.Save(media)); + Assert.Throws(() => _mediaService.Save(media)); } /* [Test] @@ -163,13 +163,13 @@ namespace Umbraco.Tests.Integration.Services public void Can_Get_Media_By_Path() { var mediaType = MockedContentTypes.CreateImageMediaType("Image2"); - MediaTypeService.Save(mediaType); + _mediaTypeService.Save(mediaType); var media = MockedMedia.CreateMediaImage(mediaType, -1); - MediaService.Save(media); + _mediaService.Save(media); var mediaPath = "/media/test-image.png"; - var resolvedMedia = MediaService.GetMediaByPath(mediaPath); + var resolvedMedia = _mediaService.GetMediaByPath(mediaPath); Assert.IsNotNull(resolvedMedia); Assert.That(resolvedMedia.GetValue(Constants.Conventions.Media.File).ToString() == mediaPath); @@ -179,13 +179,13 @@ namespace Umbraco.Tests.Integration.Services public void Can_Get_Media_With_Crop_By_Path() { var mediaType = MockedContentTypes.CreateImageMediaTypeWithCrop("Image2"); - MediaTypeService.Save(mediaType); + _mediaTypeService.Save(mediaType); var media = MockedMedia.CreateMediaImageWithCrop(mediaType, -1); - MediaService.Save(media); + _mediaService.Save(media); var mediaPath = "/media/test-image.png"; - var resolvedMedia = MediaService.GetMediaByPath(mediaPath); + var resolvedMedia = _mediaService.GetMediaByPath(mediaPath); Assert.IsNotNull(resolvedMedia); Assert.That(resolvedMedia.GetValue(Constants.Conventions.Media.File).ToString().Contains(mediaPath)); @@ -195,14 +195,14 @@ namespace Umbraco.Tests.Integration.Services public void Can_Get_Paged_Children() { var mediaType = MockedContentTypes.CreateImageMediaType("Image2"); - MediaTypeService.Save(mediaType); + _mediaTypeService.Save(mediaType); for (var i = 0; i < 10; i++) { var c1 = MockedMedia.CreateMediaImage(mediaType, -1); - MediaService.Save(c1); + _mediaService.Save(c1); } - var service = MediaService; + var service = _mediaService; long total; var entities = service.GetPagedChildren(-1, 0, 6, out total).ToArray(); @@ -217,25 +217,25 @@ namespace Umbraco.Tests.Integration.Services public void Can_Get_Paged_Children_Dont_Get_Descendants() { var mediaType = MockedContentTypes.CreateImageMediaType("Image2"); - MediaTypeService.Save(mediaType); + _mediaTypeService.Save(mediaType); // only add 9 as we also add a folder with children for (var i = 0; i < 9; i++) { var m1 = MockedMedia.CreateMediaImage(mediaType, -1); - MediaService.Save(m1); + _mediaService.Save(m1); } var mediaTypeForFolder = MockedContentTypes.CreateImageMediaType("Folder2"); - MediaTypeService.Save(mediaTypeForFolder); + _mediaTypeService.Save(mediaTypeForFolder); var mediaFolder = MockedMedia.CreateMediaFolder(mediaTypeForFolder, -1); - MediaService.Save(mediaFolder); + _mediaService.Save(mediaFolder); for (var i = 0; i < 10; i++) { var m1 = MockedMedia.CreateMediaImage(mediaType, mediaFolder.Id); - MediaService.Save(m1); + _mediaService.Save(m1); } - var service = MediaService; + var service = _mediaService; long total; // children in root including the folder - not the descendants in the folder @@ -258,28 +258,28 @@ namespace Umbraco.Tests.Integration.Services private Tuple CreateTrashedTestMedia() { //Create and Save folder-Media -> 1050 - var folderMediaType = MediaTypeService.Get(1031); + var folderMediaType = _mediaTypeService.Get(1031); var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1); - MediaService.Save(folder); + _mediaService.Save(folder); //Create and Save folder-Media -> 1051 var folder2 = MockedMedia.CreateMediaFolder(folderMediaType, -1); - MediaService.Save(folder2); + _mediaService.Save(folder2); //Create and Save image-Media -> 1052 - var imageMediaType = MediaTypeService.Get(1032); + var imageMediaType = _mediaTypeService.Get(1032); var image = (Media)MockedMedia.CreateMediaImage(imageMediaType, 1050); - MediaService.Save(image); + _mediaService.Save(image); //Create and Save folder-Media that is trashed -> 1053 var folderTrashed = (Media)MockedMedia.CreateMediaFolder(folderMediaType, -21); folderTrashed.Trashed = true; - MediaService.Save(folderTrashed); + _mediaService.Save(folderTrashed); //Create and Save image-Media child of folderTrashed -> 1054 var imageTrashed = (Media)MockedMedia.CreateMediaImage(imageMediaType, folderTrashed.Id); imageTrashed.Trashed = true; - MediaService.Save(imageTrashed); + _mediaService.Save(imageTrashed); return new Tuple(folder, folder2, image, folderTrashed, imageTrashed); } diff --git a/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs b/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs index 5294e8015b..42419565a2 100644 --- a/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs @@ -15,20 +15,20 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class PublicAccessServiceTests : UmbracoIntegrationTest { - private IContentService ContentService => GetRequiredService(); - private IContentTypeService ContentTypeService => GetRequiredService(); - private IFileService FileService => GetRequiredService(); - private IPublicAccessService PublicAccessService => GetRequiredService(); + private IContentService _contentService => GetRequiredService(); + private IContentTypeService _contentTypeService => GetRequiredService(); + private IFileService _fileService => GetRequiredService(); + private IPublicAccessService _publicAccessService => GetRequiredService(); [Test] public void Can_Add_New_Entry() { // Arrange var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - FileService.SaveTemplate(ct.DefaultTemplate); - ContentTypeService.Save(ct); + _fileService.SaveTemplate(ct.DefaultTemplate); + _contentTypeService.Save(ct); var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - ContentService.Save(c); + _contentService.Save(c); // Act var entry = new PublicAccessEntry(c, c, c, new[] @@ -39,7 +39,7 @@ namespace Umbraco.Tests.Integration.Services RuleValue = "TestVal" }, }); - var result = PublicAccessService.Save(entry); + var result = _publicAccessService.Save(entry); // Assert Assert.IsTrue(result.Success); @@ -56,10 +56,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - FileService.SaveTemplate(ct.DefaultTemplate); - ContentTypeService.Save(ct); + _fileService.SaveTemplate(ct.DefaultTemplate); + _contentTypeService.Save(ct); var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - ContentService.Save(c); + _contentService.Save(c); var entry = new PublicAccessEntry(c, c, c, new[] { new PublicAccessRule() @@ -68,12 +68,12 @@ namespace Umbraco.Tests.Integration.Services RuleValue = "TestVal" }, }); - PublicAccessService.Save(entry); + _publicAccessService.Save(entry); // Act - var updated = PublicAccessService.AddRule(c, "TestType2", "AnotherVal"); + var updated = _publicAccessService.AddRule(c, "TestType2", "AnotherVal"); //re-get - entry = PublicAccessService.GetEntryForContent(c); + entry = _publicAccessService.GetEntryForContent(c); // Assert Assert.IsTrue(updated.Success); @@ -86,10 +86,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - FileService.SaveTemplate(ct.DefaultTemplate); - ContentTypeService.Save(ct); + _fileService.SaveTemplate(ct.DefaultTemplate); + _contentTypeService.Save(ct); var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - ContentService.Save(c); + _contentService.Save(c); var entry = new PublicAccessEntry(c, c, c, new[] { new PublicAccessRule() @@ -98,14 +98,14 @@ namespace Umbraco.Tests.Integration.Services RuleValue = "TestVal" }, }); - PublicAccessService.Save(entry); + _publicAccessService.Save(entry); // Act - var updated1 = PublicAccessService.AddRule(c, "TestType", "AnotherVal1"); - var updated2 = PublicAccessService.AddRule(c, "TestType", "AnotherVal2"); + var updated1 = _publicAccessService.AddRule(c, "TestType", "AnotherVal1"); + var updated2 = _publicAccessService.AddRule(c, "TestType", "AnotherVal2"); //re-get - entry = PublicAccessService.GetEntryForContent(c); + entry = _publicAccessService.GetEntryForContent(c); // Assert Assert.IsTrue(updated1.Success); @@ -120,10 +120,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - FileService.SaveTemplate(ct.DefaultTemplate); - ContentTypeService.Save(ct); + _fileService.SaveTemplate(ct.DefaultTemplate); + _contentTypeService.Save(ct); var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - ContentService.Save(c); + _contentService.Save(c); var entry = new PublicAccessEntry(c, c, c, new[] { new PublicAccessRule() @@ -137,12 +137,12 @@ namespace Umbraco.Tests.Integration.Services RuleValue = "TestValue2" }, }); - PublicAccessService.Save(entry); + _publicAccessService.Save(entry); // Act - var removed = PublicAccessService.RemoveRule(c, "TestType", "TestValue1"); + var removed = _publicAccessService.RemoveRule(c, "TestType", "TestValue1"); //re-get - entry = PublicAccessService.GetEntryForContent(c); + entry = _publicAccessService.GetEntryForContent(c); // Assert Assert.IsTrue(removed.Success); diff --git a/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs b/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs index a54a1c1c59..ef8301a315 100644 --- a/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs @@ -8,7 +8,7 @@ using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; using Umbraco.Web.Services; -namespace Umbraco.Tests.Services +namespace Umbraco.Tests.Integration.Services { /// /// Tests covering the SectionService diff --git a/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs b/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs index db2c8196e7..a3ee817a28 100644 --- a/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs @@ -22,11 +22,11 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class TagServiceTests : UmbracoIntegrationTest { - private IContentService ContentService => GetRequiredService(); - private IContentTypeService ContentTypeService => GetRequiredService(); - private ITagService TagService => GetRequiredService(); - private IDataTypeService DataTypeService => GetRequiredService(); - public PropertyEditorCollection PropertyEditorCollection => GetRequiredService(); + private IContentService _contentService => GetRequiredService(); + private IContentTypeService _contentTypeService => GetRequiredService(); + private ITagService _tagService => GetRequiredService(); + private IDataTypeService _dataTypeService => GetRequiredService(); + private PropertyEditorCollection _propertyEditorCollection => GetRequiredService(); [Test] public void TagApiConsistencyTest() @@ -37,25 +37,25 @@ namespace Umbraco.Tests.Integration.Services { DataTypeId = 1041 }); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); IContent content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); - content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig", "goat" }); - ContentService.SaveAndPublish(content1); + content1.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow", "pig", "goat" }); + _contentService.SaveAndPublish(content1); // change - content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "elephant" }, true); - content1.RemoveTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow" }); - ContentService.SaveAndPublish(content1); + content1.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "elephant" }, true); + content1.RemoveTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow" }); + _contentService.SaveAndPublish(content1); // more changes - content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "mouse" }, true); - ContentService.SaveAndPublish(content1); - content1.RemoveTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "mouse" }); - ContentService.SaveAndPublish(content1); + content1.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "mouse" }, true); + _contentService.SaveAndPublish(content1); + content1.RemoveTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "mouse" }); + _contentService.SaveAndPublish(content1); // get it back - content1 = ContentService.GetById(content1.Id); + content1 = _contentService.GetById(content1.Id); var tagsValue = content1.GetValue("tags").ToString(); var tagsValues = JsonConvert.DeserializeObject(tagsValue); Assert.AreEqual(3, tagsValues.Length); @@ -63,7 +63,7 @@ namespace Umbraco.Tests.Integration.Services Assert.Contains("goat", tagsValues); Assert.Contains("elephant", tagsValues); - var tags = TagService.GetTagsForProperty(content1.Id, "tags").ToArray(); + var tags = _tagService.GetTagsForProperty(content1.Id, "tags").ToArray(); Assert.IsTrue(tags.All(x => x.Group == "default")); tagsValues = tags.Select(x => x.Text).ToArray(); @@ -82,22 +82,22 @@ namespace Umbraco.Tests.Integration.Services { DataTypeId = Constants.DataTypes.Tags }); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); - content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig", "goat" }); - ContentService.SaveAndPublish(content1); + content1.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow", "pig", "goat" }); + _contentService.SaveAndPublish(content1); var content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", -1); - content2.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig" }); - ContentService.SaveAndPublish(content2); + content2.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow", "pig" }); + _contentService.SaveAndPublish(content2); var content3 = MockedContent.CreateSimpleContent(contentType, "Tagged content 3", -1); - content3.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow" }); - ContentService.SaveAndPublish(content3); + content3.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow" }); + _contentService.SaveAndPublish(content3); // Act - var tags = TagService.GetAllContentTags() + var tags = _tagService.GetAllContentTags() .OrderByDescending(x => x.NodeCount) .ToList(); diff --git a/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs b/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs index 64bd89c8f8..ba7dfae0f5 100644 --- a/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs @@ -12,11 +12,12 @@ using Umbraco.Core.Models.Membership; using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Common.Builders.Extensions; using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Tests.Testing; using Umbraco.Web.Actions; -using MockedUser = Umbraco.Tests.Common.TestHelpers.Entities.MockedUser; namespace Umbraco.Tests.Integration.Services { @@ -28,9 +29,9 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class UserServiceTests : UmbracoIntegrationTest { - private UserService UserService => (UserService) GetRequiredService(); - private IContentTypeService ContentTypeService => GetRequiredService(); - private IContentService ContentService => GetRequiredService(); + private UserService _userService => (UserService) GetRequiredService(); + private IContentTypeService _contentTypeService => GetRequiredService(); + private IContentService _contentService => GetRequiredService(); [Test] public void Get_User_Permissions_For_Unassigned_Permission_Nodes() @@ -38,17 +39,17 @@ namespace Umbraco.Tests.Integration.Services // Arrange var user = CreateTestUser(out _); var contentType = MockedContentTypes.CreateSimpleContentType(); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - ContentService.Save(content); + _contentService.Save(content); // Act - var permissions = UserService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); + var permissions = _userService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); // Assert Assert.AreEqual(3, permissions.Length); @@ -64,23 +65,23 @@ namespace Umbraco.Tests.Integration.Services var user = CreateTestUser(out var userGroup); var contentType = MockedContentTypes.CreateSimpleContentType(); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - ContentService.Save(content); - ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[2], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.Save(content); + _contentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[2], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); // Act - var permissions = UserService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); + var permissions = _userService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); // Assert Assert.AreEqual(3, permissions.Length); @@ -96,23 +97,23 @@ namespace Umbraco.Tests.Integration.Services var userGroup = CreateTestUserGroup(); var contentType = MockedContentTypes.CreateSimpleContentType(); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - ContentService.Save(content); - ContentService.SetPermission(content.ElementAt(0), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content.ElementAt(0), ActionDelete.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content.ElementAt(0), ActionMove.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content.ElementAt(1), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content.ElementAt(1), ActionDelete.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content.ElementAt(2), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.Save(content); + _contentService.SetPermission(content.ElementAt(0), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content.ElementAt(0), ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content.ElementAt(0), ActionMove.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content.ElementAt(1), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content.ElementAt(1), ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content.ElementAt(2), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); // Act - var permissions = UserService.GetPermissions(userGroup, false, content[0].Id, content[1].Id, content[2].Id).ToArray(); + var permissions = _userService.GetPermissions(userGroup, false, content[0].Id, content[1].Id, content[2].Id).ToArray(); // Assert Assert.AreEqual(3, permissions.Length); @@ -128,22 +129,22 @@ namespace Umbraco.Tests.Integration.Services var userGroup = CreateTestUserGroup(); var contentType = MockedContentTypes.CreateSimpleContentType(); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - ContentService.Save(content); - ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.Save(content); + _contentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); // Act - var permissions = UserService.GetPermissions(userGroup, true, content[0].Id, content[1].Id, content[2].Id) + var permissions = _userService.GetPermissions(userGroup, true, content[0].Id, content[1].Id, content[2].Id) .ToArray(); // Assert @@ -160,35 +161,35 @@ namespace Umbraco.Tests.Integration.Services var userGroup1 = CreateTestUserGroup(); var userGroup2 = CreateTestUserGroup("test2", "Test 2"); var userGroup3 = CreateTestUserGroup("test3", "Test 3"); - var user = UserService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); + var user = _userService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); var defaultPermissionCount = userGroup3.Permissions.Count(); user.AddGroup(userGroup1); user.AddGroup(userGroup2); user.AddGroup(userGroup3); - UserService.Save(user); + _userService.Save(user); var contentType = MockedContentTypes.CreateSimpleContentType(); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - ContentService.Save(content); + _contentService.Save(content); //assign permissions - we aren't assigning anything explicit for group3 and nothing explicit for content[2] /w group2 - ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); - ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); - ContentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup2.Id }); - ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); - ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup2.Id }); - ContentService.SetPermission(content[2], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); + _contentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); + _contentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); + _contentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup2.Id }); + _contentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); + _contentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup2.Id }); + _contentService.SetPermission(content[2], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); // Act //we don't pass in any nodes so it will return all of them - var result = UserService.GetPermissions(user).ToArray(); + var result = _userService.GetPermissions(user).ToArray(); var permissions = result .GroupBy(x => x.EntityId) .ToDictionary(x => x.Key, x => x.GroupBy(a => a.UserGroupId).ToDictionary(a => a.Key, a => a.ToArray())); @@ -239,24 +240,24 @@ namespace Umbraco.Tests.Integration.Services var userGroup = CreateTestUserGroup(); var contentType = MockedContentTypes.CreateSimpleContentType(); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - ContentService.Save(content); - ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(content[2], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.Save(content); + _contentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(content[2], ActionDelete.ActionLetter, new int[] { userGroup.Id }); // Act //we don't pass in any nodes so it will return all of them - var permissions = UserService.GetPermissions(userGroup, true) + var permissions = _userService.GetPermissions(userGroup, true) .GroupBy(x => x.EntityId) .ToDictionary(x => x.Key, x => x); @@ -400,22 +401,22 @@ namespace Umbraco.Tests.Integration.Services var userGroup = CreateTestUserGroup(); var contentType = MockedContentTypes.CreateSimpleContentType(); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); var parent = MockedContent.CreateSimpleContent(contentType); - ContentService.Save(parent); + _contentService.Save(parent); var child1 = MockedContent.CreateSimpleContent(contentType, "child1", parent); - ContentService.Save(child1); + _contentService.Save(child1); var child2 = MockedContent.CreateSimpleContent(contentType, "child2", child1); - ContentService.Save(child2); + _contentService.Save(child2); - ContentService.SetPermission(parent, ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(parent, ActionDelete.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(parent, ActionMove.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(parent, ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - ContentService.SetPermission(parent, ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(parent, ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(parent, ActionDelete.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(parent, ActionMove.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(parent, ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + _contentService.SetPermission(parent, ActionDelete.ActionLetter, new int[] { userGroup.Id }); // Act - var permissions = UserService.GetPermissionsForPath(userGroup, child2.Path); + var permissions = _userService.GetPermissionsForPath(userGroup, child2.Path); // Assert var allPermissions = permissions.GetAllPermissions().ToArray(); @@ -425,10 +426,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Delete_User() { - var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - UserService.Delete(user, true); - var deleted = UserService.GetUserById(user.Id); + _userService.Delete(user, true); + var deleted = _userService.GetUserById(user.Id); // Assert Assert.That(deleted, Is.Null); @@ -437,10 +438,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Disables_User_Instead_Of_Deleting_If_Flag_Not_Set() { - var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - UserService.Delete(user); - var deleted = UserService.GetUserById(user.Id); + _userService.Delete(user); + var deleted = _userService.GetUserById(user.Id); // Assert Assert.That(deleted, Is.Not.Null); @@ -449,60 +450,60 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Exists_By_Username() { - var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - var user2 = UserService.CreateUserWithIdentity("john2@umbraco.io", "john2@umbraco.io"); - Assert.IsTrue(UserService.Exists("JohnDoe")); - Assert.IsFalse(UserService.Exists("notFound")); - Assert.IsTrue(UserService.Exists("john2@umbraco.io")); + var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user2 = _userService.CreateUserWithIdentity("john2@umbraco.io", "john2@umbraco.io"); + Assert.IsTrue(_userService.Exists("JohnDoe")); + Assert.IsFalse(_userService.Exists("notFound")); + Assert.IsTrue(_userService.Exists("john2@umbraco.io")); } [Test] public void Get_By_Email() { - var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - Assert.IsNotNull(UserService.GetByEmail(user.Email)); - Assert.IsNull(UserService.GetByEmail("do@not.find")); + Assert.IsNotNull(_userService.GetByEmail(user.Email)); + Assert.IsNull(_userService.GetByEmail("do@not.find")); } [Test] public void Get_By_Username() { - var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - Assert.IsNotNull(UserService.GetByUsername(user.Username)); - Assert.IsNull(UserService.GetByUsername("notFound")); + Assert.IsNotNull(_userService.GetByUsername(user.Username)); + Assert.IsNull(_userService.GetByUsername("notFound")); } [Test] public void Get_By_Username_With_Backslash() { - var user = UserService.CreateUserWithIdentity("mydomain\\JohnDoe", "john@umbraco.io"); + var user = _userService.CreateUserWithIdentity("mydomain\\JohnDoe", "john@umbraco.io"); - Assert.IsNotNull(UserService.GetByUsername(user.Username)); - Assert.IsNull(UserService.GetByUsername("notFound")); + Assert.IsNotNull(_userService.GetByUsername(user.Username)); + Assert.IsNull(_userService.GetByUsername("notFound")); } [Test] public void Get_By_Object_Id() { - var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - Assert.IsNotNull(UserService.GetUserById(user.Id)); - Assert.IsNull(UserService.GetUserById(9876)); + Assert.IsNotNull(_userService.GetUserById(user.Id)); + Assert.IsNull(_userService.GetUserById(9876)); } [Test] public void Find_By_Email_Starts_With() { - var users = MockedUser.CreateMulipleUsers(10); - UserService.Save(users); + var users = CreateMulipleUsers(10); + _userService.Save(users); //don't find this - var customUser = MockedUser.CreateUser(); + var customUser = CreateUser(); customUser.Email = "hello@hello.com"; - UserService.Save(customUser); + _userService.Save(customUser); - var found = UserService.FindByEmail("tes", 0, 100, out _, StringPropertyMatchType.StartsWith); + var found = _userService.FindByEmail("tes", 0, 100, out _, StringPropertyMatchType.StartsWith); Assert.AreEqual(10, found.Count()); } @@ -510,14 +511,14 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Find_By_Email_Ends_With() { - var users = MockedUser.CreateMulipleUsers(10); - UserService.Save(users); + var users = CreateMulipleUsers(10); + _userService.Save(users); //include this - var customUser = MockedUser.CreateUser(); + var customUser = CreateUser(); customUser.Email = "hello@test.com"; - UserService.Save(customUser); + _userService.Save(customUser); - var found = UserService.FindByEmail("test.com", 0, 100, out _, StringPropertyMatchType.EndsWith); + var found = _userService.FindByEmail("test.com", 0, 100, out _, StringPropertyMatchType.EndsWith); Assert.AreEqual(11, found.Count()); } @@ -525,14 +526,14 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Find_By_Email_Contains() { - var users = MockedUser.CreateMulipleUsers(10); - UserService.Save(users); + var users = CreateMulipleUsers(10); + _userService.Save(users); //include this - var customUser = MockedUser.CreateUser(); + var customUser = CreateUser(); customUser.Email = "hello@test.com"; - UserService.Save(customUser); + _userService.Save(customUser); - var found = UserService.FindByEmail("test", 0, 100, out _, StringPropertyMatchType.Contains); + var found = _userService.FindByEmail("test", 0, 100, out _, StringPropertyMatchType.Contains); Assert.AreEqual(11, found.Count()); } @@ -540,14 +541,14 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Find_By_Email_Exact() { - var users = MockedUser.CreateMulipleUsers(10); - UserService.Save(users); + var users = CreateMulipleUsers(10); + _userService.Save(users); //include this - var customUser = MockedUser.CreateUser(); + var customUser = CreateUser(); customUser.Email = "hello@test.com"; - UserService.Save(customUser); + _userService.Save(customUser); - var found = UserService.FindByEmail("hello@test.com", 0, 100, out _, StringPropertyMatchType.Exact); + var found = _userService.FindByEmail("hello@test.com", 0, 100, out _, StringPropertyMatchType.Exact); Assert.AreEqual(1, found.Count()); } @@ -555,10 +556,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Get_All_Paged_Users() { - var users = MockedUser.CreateMulipleUsers(10); - UserService.Save(users); + var users = CreateMulipleUsers(10); + _userService.Save(users); - var found = UserService.GetAll(0, 2, out var totalRecs); + var found = _userService.GetAll(0, 2, out var totalRecs); Assert.AreEqual(2, found.Count()); // + 1 because of the built in admin user @@ -570,10 +571,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Get_All_Paged_Users_With_Filter() { - var users = MockedUser.CreateMulipleUsers(10).ToArray(); - UserService.Save(users); + var users = CreateMulipleUsers(10).ToArray(); + _userService.Save(users); - var found = UserService.GetAll(0, 2, out var totalRecs, "username", Direction.Ascending, filter: "test"); + var found = _userService.GetAll(0, 2, out var totalRecs, "username", Direction.Ascending, filter: "test"); Assert.AreEqual(2, found.Count()); Assert.AreEqual(10, totalRecs); @@ -585,18 +586,18 @@ namespace Umbraco.Tests.Integration.Services public void Get_All_Paged_Users_For_Group() { var userGroup = MockedUserGroup.CreateUserGroup(); - UserService.Save(userGroup); + _userService.Save(userGroup); - var users = MockedUser.CreateMulipleUsers(10).ToArray(); + var users = CreateMulipleUsers(10).ToArray(); for (var i = 0; i < 10;) { users[i].AddGroup(userGroup.ToReadOnlyGroup()); i = i + 2; } - UserService.Save(users); + _userService.Save(users); long totalRecs; - var found = UserService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, includeUserGroups: new[] { userGroup.Alias }); + var found = _userService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, includeUserGroups: new[] { userGroup.Alias }); Assert.AreEqual(2, found.Count()); Assert.AreEqual(5, totalRecs); @@ -608,9 +609,9 @@ namespace Umbraco.Tests.Integration.Services public void Get_All_Paged_Users_For_Group_With_Filter() { var userGroup = MockedUserGroup.CreateUserGroup(); - UserService.Save(userGroup); + _userService.Save(userGroup); - var users = MockedUser.CreateMulipleUsers(10).ToArray(); + var users = CreateMulipleUsers(10).ToArray(); for (var i = 0; i < 10;) { users[i].AddGroup(userGroup.ToReadOnlyGroup()); @@ -621,10 +622,10 @@ namespace Umbraco.Tests.Integration.Services users[i].Name = "blah" + users[i].Name; i = i + 3; } - UserService.Save(users); + _userService.Save(users); long totalRecs; - var found = UserService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, userGroups: new[] { userGroup.Alias }, filter: "blah"); + var found = _userService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, userGroups: new[] { userGroup.Alias }, filter: "blah"); Assert.AreEqual(2, found.Count()); Assert.AreEqual(2, totalRecs); @@ -635,12 +636,12 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Count_All_Users() { - var users = MockedUser.CreateMulipleUsers(10); - UserService.Save(users); - var customUser = MockedUser.CreateUser(); - UserService.Save(customUser); + var users = CreateMulipleUsers(10); + _userService.Save(users); + var customUser = CreateUser(); + _userService.Save(customUser); - var found = UserService.GetCount(MemberCountType.All); + var found = _userService.GetCount(MemberCountType.All); // + 1 because of the built in admin user Assert.AreEqual(12, found); @@ -650,24 +651,24 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Count_All_Online_Users() { - var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2)); - UserService.Save(users); + var users = CreateMulipleUsers(10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2)); + _userService.Save(users); - var customUser = MockedUser.CreateUser(); + var customUser = CreateUser(); throw new NotImplementedException(); } [Test] public void Count_All_Locked_Users() { - var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.IsLockedOut = i % 2 == 0); - UserService.Save(users); + var users = CreateMulipleUsers(10, (i, member) => member.IsLockedOut = i % 2 == 0); + _userService.Save(users); - var customUser = MockedUser.CreateUser(); + var customUser = CreateUser(); customUser.IsLockedOut = true; - UserService.Save(customUser); + _userService.Save(customUser); - var found = UserService.GetCount(MemberCountType.LockedOut); + var found = _userService.GetCount(MemberCountType.LockedOut); Assert.AreEqual(6, found); } @@ -675,14 +676,14 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Count_All_Approved_Users() { - var users = MockedUser.CreateMulipleUsers(10, (i, member) => member.IsApproved = i % 2 == 0); - UserService.Save(users); + var users = CreateMulipleUsers(10, (i, member) => member.IsApproved = i % 2 == 0); + _userService.Save(users); - var customUser = MockedUser.CreateUser(); + var customUser = CreateUser(); customUser.IsApproved = false; - UserService.Save(customUser); + _userService.Save(customUser); - var found = UserService.GetCount(MemberCountType.Approved); + var found = _userService.GetCount(MemberCountType.Approved); // + 1 because of the built in admin user Assert.AreEqual(6, found); @@ -692,7 +693,7 @@ namespace Umbraco.Tests.Integration.Services public void Can_Persist_New_User() { // Act - var membershipUser = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var membershipUser = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); // Assert Assert.That(membershipUser.HasIdentity, Is.True); @@ -712,7 +713,7 @@ namespace Umbraco.Tests.Integration.Services var encodedPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password))); var globalSettings = new GlobalSettings(); var membershipUser = new User(globalSettings, "JohnDoe", "john@umbraco.io", encodedPassword, encodedPassword); - UserService.Save(membershipUser); + _userService.Save(membershipUser); // Assert Assert.That(membershipUser.HasIdentity, Is.True); @@ -732,9 +733,9 @@ namespace Umbraco.Tests.Integration.Services }; userGroup.AddAllowedSection("content"); userGroup.AddAllowedSection("mediat"); - UserService.Save(userGroup); + _userService.Save(userGroup); - var result1 = UserService.GetUserGroupById(userGroup.Id); + var result1 = _userService.GetUserGroupById(userGroup.Id); Assert.AreEqual(2, result1.AllowedSections.Count()); @@ -743,9 +744,9 @@ namespace Umbraco.Tests.Integration.Services userGroup.AddAllowedSection("test2"); userGroup.AddAllowedSection("test3"); userGroup.AddAllowedSection("test4"); - UserService.Save(userGroup); + _userService.Save(userGroup); - result1 = UserService.GetUserGroupById(userGroup.Id); + result1 = _userService.GetUserGroupById(userGroup.Id); Assert.AreEqual(6, result1.AllowedSections.Count()); @@ -758,11 +759,11 @@ namespace Umbraco.Tests.Integration.Services //now just re-add a couple result1.AddAllowedSection("test3"); result1.AddAllowedSection("test4"); - UserService.Save(result1); + _userService.Save(result1); // Assert //re-get - result1 = UserService.GetUserGroupById(userGroup.Id); + result1 = _userService.GetUserGroupById(userGroup.Id); Assert.AreEqual(2, result1.AllowedSections.Count()); } @@ -779,21 +780,21 @@ namespace Umbraco.Tests.Integration.Services Alias = "Group2", Name = "Group 2" }; - UserService.Save(userGroup1); - UserService.Save(userGroup2); + _userService.Save(userGroup1); + _userService.Save(userGroup2); //adds some allowed sections userGroup1.AddAllowedSection("test"); userGroup2.AddAllowedSection("test"); - UserService.Save(userGroup1); - UserService.Save(userGroup2); + _userService.Save(userGroup1); + _userService.Save(userGroup2); //now clear the section from all users - UserService.DeleteSectionFromAllUserGroups("test"); + _userService.DeleteSectionFromAllUserGroups("test"); // Assert - var result1 = UserService.GetUserGroupById(userGroup1.Id); - var result2 = UserService.GetUserGroupById(userGroup2.Id); + var result1 = _userService.GetUserGroupById(userGroup1.Id); + var result2 = _userService.GetUserGroupById(userGroup2.Id); Assert.IsFalse(result1.AllowedSections.Contains("test")); Assert.IsFalse(result2.AllowedSections.Contains("test")); } @@ -820,14 +821,14 @@ namespace Umbraco.Tests.Integration.Services Alias = "Group3", Name = "Group 3" }; - UserService.Save(userGroup1); - UserService.Save(userGroup2); - UserService.Save(userGroup3); + _userService.Save(userGroup1); + _userService.Save(userGroup2); + _userService.Save(userGroup3); // Assert - var result1 = UserService.GetUserGroupById(userGroup1.Id); - var result2 = UserService.GetUserGroupById(userGroup2.Id); - var result3 = UserService.GetUserGroupById(userGroup3.Id); + var result1 = _userService.GetUserGroupById(userGroup1.Id); + var result2 = _userService.GetUserGroupById(userGroup2.Id); + var result3 = _userService.GetUserGroupById(userGroup3.Id); Assert.IsTrue(result1.AllowedSections.Contains("test")); Assert.IsTrue(result2.AllowedSections.Contains("test")); Assert.IsFalse(result3.AllowedSections.Contains("test")); @@ -836,13 +837,13 @@ namespace Umbraco.Tests.Integration.Services foreach (var userGroup in new[] { userGroup1, userGroup2, userGroup3 }) { userGroup.AddAllowedSection("test"); - UserService.Save(userGroup); + _userService.Save(userGroup); } // Assert - result1 = UserService.GetUserGroupById(userGroup1.Id); - result2 = UserService.GetUserGroupById(userGroup2.Id); - result3 = UserService.GetUserGroupById(userGroup3.Id); + result1 = _userService.GetUserGroupById(userGroup1.Id); + result2 = _userService.GetUserGroupById(userGroup2.Id); + result3 = _userService.GetUserGroupById(userGroup3.Id); Assert.IsTrue(result1.AllowedSections.Contains("test")); Assert.IsTrue(result2.AllowedSections.Contains("test")); Assert.IsTrue(result3.AllowedSections.Contains("test")); @@ -852,39 +853,39 @@ namespace Umbraco.Tests.Integration.Services public void Cannot_Create_User_With_Empty_Username() { // Act & Assert - Assert.Throws(() => UserService.CreateUserWithIdentity(string.Empty, "john@umbraco.io")); + Assert.Throws(() => _userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io")); } [Test] public void Cannot_Save_User_With_Empty_Username() { // Arrange - var user = UserService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); + var user = _userService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); user.Username = string.Empty; // Act & Assert - Assert.Throws(() => UserService.Save(user)); + Assert.Throws(() => _userService.Save(user)); } [Test] public void Cannot_Save_User_With_Empty_Name() { // Arrange - var user = UserService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); + var user = _userService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); user.Name = string.Empty; // Act & Assert - Assert.Throws(() => UserService.Save(user)); + Assert.Throws(() => _userService.Save(user)); } [Test] public void Get_By_Profile_Username() { // Arrange - var user = UserService.CreateUserWithIdentity("test1", "test1@test.com"); + var user = _userService.CreateUserWithIdentity("test1", "test1@test.com"); // Act - var profile = UserService.GetProfileByUserName(user.Username); + var profile = _userService.GetProfileByUserName(user.Username); // Assert Assert.IsNotNull(profile); @@ -896,10 +897,10 @@ namespace Umbraco.Tests.Integration.Services public void Get_By_Profile_Id() { // Arrange - var user = (IUser)UserService.CreateUserWithIdentity("test1", "test1@test.com"); + var user = _userService.CreateUserWithIdentity("test1", "test1@test.com"); // Act - var profile = UserService.GetProfileById((int)user.Id); + var profile = _userService.GetProfileById((int)user.Id); // Assert Assert.IsNotNull(profile); @@ -908,18 +909,18 @@ namespace Umbraco.Tests.Integration.Services } [Test] - public void Get_By_Profile_Id_Must_return_null_if_user_not_exists() + public void Get_By_Profile_Id_Must_Return_Null_If_User_Does_Not_Exist() { - var profile = UserService.GetProfileById(42); + var profile = _userService.GetProfileById(42); // Assert Assert.IsNull(profile); } [Test] - public void GetProfilesById_Must_empty_if_users_not_exists() + public void GetProfilesById_Must_Return_Empty_If_User_Does_Not_Exist() { - var profiles = UserService.GetProfilesById(42); + var profiles = _userService.GetProfilesById(42); // Assert CollectionAssert.IsEmpty(profiles); @@ -933,7 +934,7 @@ namespace Umbraco.Tests.Integration.Services // Act - var updatedItem = (User)UserService.GetByUsername(originalUser.Username); + var updatedItem = (User)_userService.GetByUsername(originalUser.Username); // Assert Assert.IsNotNull(updatedItem); @@ -961,7 +962,7 @@ namespace Umbraco.Tests.Integration.Services CreateTestUsers(startContentItems.Select(x => x.Id).ToArray(), testUserGroup, 3); - var usersInGroup = UserService.GetAllInGroup(userGroupId); + var usersInGroup = _userService.GetAllInGroup(userGroupId); foreach (var user in usersInGroup) Assert.AreEqual(user.StartContentIds.Length, startContentItems.Length); @@ -971,27 +972,60 @@ namespace Umbraco.Tests.Integration.Services { var contentType = MockedContentTypes.CreateSimpleContentType(); - ContentTypeService.Save(contentType); + _contentTypeService.Save(contentType); var startContentItems = new List(); for (var i = 0; i < numberToCreate; i++) startContentItems.Add(MockedContent.CreateSimpleContent(contentType)); - ContentService.Save(startContentItems); + _contentService.Save(startContentItems); return startContentItems.ToArray(); } + private static IEnumerable CreateMulipleUsers(int amount, Action onCreating = null) + { + var list = new List(); + + for (var i = 0; i < amount; i++) + { + var name = "User No-" + i; + var user = new UserBuilder() + .WithName(name) + .WithEmail("test" + i + "@test.com") + .WithLogin("test" + i, "test" + i) + .Build(); + + onCreating?.Invoke(i, user); + + user.ResetDirtyProperties(false); + + list.Add(user); + } + + return list; + } + + private static User CreateUser(string suffix = "") + { + return new UserBuilder() + .WithIsApproved(true) + .WithName("TestUser" + suffix) + .WithLogin("TestUser" + suffix, "testing") + .WithEmail("test" + suffix + "@test.com") + .Build(); + } + private IUser CreateTestUser(out IUserGroup userGroup) { userGroup = CreateTestUserGroup(); - var user = UserService.CreateUserWithIdentity("test1", "test1@test.com"); + var user = _userService.CreateUserWithIdentity("test1", "test1@test.com"); user.AddGroup(userGroup.ToReadOnlyGroup()); - UserService.Save(user); + _userService.Save(user); return user; } @@ -1002,13 +1036,13 @@ namespace Umbraco.Tests.Integration.Services for (var i = 0; i < numberToCreate; i++) { - var user = UserService.CreateUserWithIdentity($"test{i}", $"test{i}@test.com"); + var user = _userService.CreateUserWithIdentity($"test{i}", $"test{i}@test.com"); user.AddGroup(userGroup.ToReadOnlyGroup()); var updateable = (User)user; updateable.StartContentIds = startContentIds; - UserService.Save(user); + _userService.Save(user); users.Add(user); } @@ -1028,7 +1062,7 @@ namespace Umbraco.Tests.Integration.Services userGroup.AddAllowedSection("content"); userGroup.AddAllowedSection("media"); - UserService.Save(userGroup); + _userService.Save(userGroup); return userGroup; } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelperTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelperTests.cs index 187e3cccd2..bbb0f1b3e3 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelperTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelperTests.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using Moq; using NUnit.Framework; using Umbraco.Core; @@ -10,8 +7,6 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; -using Umbraco.Tests.Common.TestHelpers.Entities; -using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Web.Editors; namespace Umbraco.Tests.Web.Controllers @@ -23,7 +18,7 @@ namespace Umbraco.Tests.Web.Controllers public void Admin_Is_Authorized() { var currentUser = GetAdminUser(); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); var contentService = new Mock(); var mediaService = new Mock(); @@ -44,7 +39,7 @@ namespace Umbraco.Tests.Web.Controllers [Test] public void Non_Admin_Cannot_Save_Admin() { - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); var savingUser = GetAdminUser(); var contentService = new Mock(); @@ -66,12 +61,12 @@ namespace Umbraco.Tests.Web.Controllers [Test] public void Cannot_Grant_Group_Membership_Without_Being_A_Member() { - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "Test", "icon-user", null, null, "test", new string[0], new string[0]) }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); var contentService = new Mock(); var mediaService = new Mock(); @@ -92,12 +87,12 @@ namespace Umbraco.Tests.Web.Controllers [Test] public void Can_Grant_Group_Membership_With_Being_A_Member() { - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "Test", "icon-user", null, null, "test", new string[0], new string[0]) }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); var contentService = new Mock(); var mediaService = new Mock(); @@ -126,9 +121,9 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); savingUser.Setup(x => x.StartContentIds).Returns(new[] { 1234 }); var contentService = new Mock(); @@ -166,9 +161,9 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); savingUser.Setup(x => x.StartContentIds).Returns(new[] { 1234, 4567 }); var contentService = new Mock(); @@ -206,9 +201,9 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); var contentService = new Mock(); contentService.Setup(x => x.GetById(It.IsAny())) @@ -245,9 +240,9 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); var contentService = new Mock(); contentService.Setup(x => x.GetById(It.IsAny())) @@ -285,9 +280,9 @@ namespace Umbraco.Tests.Web.Controllers }; - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); var contentService = new Mock(); var mediaService = new Mock(); @@ -324,9 +319,9 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.StartMediaIds).Returns(new[] { 9876 }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); var contentService = new Mock(); var mediaService = new Mock(); @@ -363,9 +358,9 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.StartMediaIds).Returns(new[] { 9876 }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); savingUser.Setup(x => x.StartMediaIds).Returns(new[] { 1234 }); var contentService = new Mock(); @@ -403,9 +398,9 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = MockedUser.GetUserMock(); + var currentUser = GetUserMock(); currentUser.Setup(x => x.StartMediaIds).Returns(new[] { 9876 }); - var savingUser = MockedUser.GetUserMock(); + var savingUser = GetUserMock(); savingUser.Setup(x => x.StartMediaIds).Returns(new[] { 1234, 4567 }); var contentService = new Mock(); @@ -432,9 +427,23 @@ namespace Umbraco.Tests.Web.Controllers Assert.IsTrue(result.Success); } + /// + /// Returns a and ensures that the ToUserCache and FromUserCache methods are mapped correctly for + /// dealing with start node caches + /// + /// + private static Mock GetUserMock() + { + var userCache = new Dictionary(); + var userMock = new Mock(); + userMock.Setup(x => x.FromUserCache(It.IsAny())).Returns((string key) => userCache.TryGetValue(key, out var val) ? val is int[] iVal ? iVal : null : null); + userMock.Setup(x => x.ToUserCache(It.IsAny(), It.IsAny())).Callback((string key, int[] val) => userCache[key] = val); + return userMock; + } + private IUser GetAdminUser() { - var admin = MockedUser.GetUserMock(); + var admin = GetUserMock(); admin.Setup(x => x.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "Admin", "icon-user", null, null, Constants.Security.AdminGroupAlias, new string[0], new string[0]) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/AmbiguousEventTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/AmbiguousEventTests.cs new file mode 100644 index 0000000000..6eebf5d237 --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/AmbiguousEventTests.cs @@ -0,0 +1,78 @@ +using System; +using System.Reflection; +using System.Text; +using NUnit.Framework; +using Umbraco.Core.Events; +using Umbraco.Core.Services.Implement; + +namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Services +{ + [TestFixture] + public class AmbiguousEventTests + { + [Explicit] + [TestCase(typeof(ContentService))] + [TestCase(typeof(MediaService))] + public void ListAmbiguousEvents(Type serviceType) + { + var typedEventHandler = typeof(TypedEventHandler<,>); + + // get all events + var events = serviceType.GetEvents(BindingFlags.Static | BindingFlags.Public); + + string TypeName(Type type) + { + if (!type.IsGenericType) + return type.Name; + var sb = new StringBuilder(); + TypeNameSb(type, sb); + return sb.ToString(); + } + + void TypeNameSb(Type type, StringBuilder sb) + { + var name = type.Name; + var pos = name.IndexOf('`'); + name = pos > 0 ? name.Substring(0, pos) : name; + sb.Append(name); + if (!type.IsGenericType) + return; + sb.Append("<"); + var first = true; + foreach (var arg in type.GetGenericArguments()) + { + if (first) first = false; + else sb.Append(", "); + TypeNameSb(arg, sb); + } + sb.Append(">"); + } + + foreach (var e in events) + { + // only continue if this is a TypedEventHandler + if (!e.EventHandlerType.IsGenericType) continue; + var typeDef = e.EventHandlerType.GetGenericTypeDefinition(); + if (typedEventHandler != typeDef) continue; + + // get the event args type + var eventArgsType = e.EventHandlerType.GenericTypeArguments[1]; + + // try to find the event back, based upon sender type + args type + // exclude -ing (eg Saving) events, we don't deal with them in EventDefinitionBase (they always trigger) + var found = EventNameExtractor.FindEvents(serviceType, eventArgsType, EventNameExtractor.MatchIngNames); + + if (found.Length == 1) continue; + + if (found.Length == 0) + { + Console.WriteLine($"{typeof(ContentService).Name} {e.Name} {TypeName(eventArgsType)} NotFound"); + continue; + } + + Console.WriteLine($"{typeof(ContentService).Name} {e.Name} {TypeName(eventArgsType)} Ambiguous"); + Console.WriteLine("\t" + string.Join(", ", found)); + } + } + } +} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index b65cc2ff74..846b7b9fd2 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -140,6 +140,7 @@ + @@ -154,7 +155,6 @@ - From 7461a10c78024c254fb4c00d308baafcc216f345 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 6 Oct 2020 09:54:10 +0200 Subject: [PATCH 23/36] Migrated macro service tests to new integration tests project. --- .../Services/MacroServiceTests.cs | 149 ++++++++---------- .../Testing/UmbracoIntegrationTest.cs | 3 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 3 files changed, 68 insertions(+), 85 deletions(-) rename src/{Umbraco.Tests => Umbraco.Tests.Integration}/Services/MacroServiceTests.cs (64%) diff --git a/src/Umbraco.Tests/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs similarity index 64% rename from src/Umbraco.Tests/Services/MacroServiceTests.cs rename to src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index ceecb72156..1909503308 100644 --- a/src/Umbraco.Tests/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -6,27 +6,33 @@ using NUnit.Framework; using Umbraco.Core.Cache; using Umbraco.Core.Logging; using Umbraco.Core.Models; - -using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; using Umbraco.Core.Scoping; +using Umbraco.Core.Services; +using Umbraco.Core.Services.Implement; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Common.Builders.Extensions; +using Umbraco.Tests.Integration.Testing; using Umbraco.Tests.Testing; -namespace Umbraco.Tests.Services +namespace Umbraco.Tests.Integration.Services { [TestFixture] [Apartment(ApartmentState.STA)] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] - public class MacroServiceTests : TestWithSomeContentBase + public class MacroServiceTests : UmbracoIntegrationTest { - public override void CreateTestData() - { - base.CreateTestData(); + private MacroService _macroService => (MacroService)GetRequiredService(); - var provider = TestObjects.GetScopeProvider(Logger); - using (var scope = provider.CreateScope()) + [SetUp] + public override void Setup() + { + base.Setup(); + + var sp = ScopeProvider; + using (var scope = sp.CreateScope()) { - var repository = new MacroRepository((IScopeAccessor) provider, AppCaches.Disabled, Mock.Of(), ShortStringHelper); + var repository = new MacroRepository((IScopeAccessor) sp, AppCaches.Disabled, Mock.Of(), ShortStringHelper); repository.Save(new Macro(ShortStringHelper, "test1", "Test1", "~/views/macropartials/test1.cshtml")); repository.Save(new Macro(ShortStringHelper, "test2", "Test2", "~/views/macropartials/test2.cshtml")); @@ -35,22 +41,15 @@ namespace Umbraco.Tests.Services } } - [TearDown] - public override void TearDown() - { - base.TearDown(); - } - [Test] public void Can_Get_By_Alias() { // Arrange - var macroService = ServiceContext.MacroService; // Act - var macro = macroService.GetByAlias("test1"); + var macro = _macroService.GetByAlias("test1"); - //assert + // Assert Assert.IsNotNull(macro); Assert.AreEqual("Test1", macro.Name); } @@ -59,12 +58,11 @@ namespace Umbraco.Tests.Services public void Can_Get_All() { // Arrange - var macroService = ServiceContext.MacroService; // Act - var result = macroService.GetAll(); + var result = _macroService.GetAll(); - //assert + // Assert Assert.AreEqual(3, result.Count()); } @@ -72,23 +70,23 @@ namespace Umbraco.Tests.Services public void Can_Create() { // Arrange - var macroService = ServiceContext.MacroService; // Act - var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); - macroService.Save(macro); + var macro = CreateMacro(); - //assert + _macroService.Save(macro); + + // Assert Assert.IsTrue(macro.HasIdentity); Assert.Greater(macro.Id, 0); Assert.AreNotEqual(Guid.Empty, macro.Key); - var result = macroService.GetById(macro.Id); + var result = _macroService.GetById(macro.Id); Assert.AreEqual("test", result.Alias); Assert.AreEqual("Test", result.Name); Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.MacroSource); Assert.AreEqual(1234, result.CacheDuration); - result = macroService.GetById(macro.Key); + result = _macroService.GetById(macro.Key); Assert.AreEqual("test", result.Alias); Assert.AreEqual("Test", result.Name); Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.MacroSource); @@ -99,18 +97,17 @@ namespace Umbraco.Tests.Services public void Can_Delete() { // Arrange - var macroService = ServiceContext.MacroService; var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); - macroService.Save(macro); + _macroService.Save(macro); // Act - macroService.Delete(macro); + _macroService.Delete(macro); - //assert - var result = macroService.GetById(macro.Id); + // Assert + var result = _macroService.GetById(macro.Id); Assert.IsNull(result); - result = macroService.GetById(macro.Key); + result = _macroService.GetById(macro.Key); Assert.IsNull(result); } @@ -118,20 +115,18 @@ namespace Umbraco.Tests.Services public void Can_Update() { // Arrange - var macroService = ServiceContext.MacroService; - IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); - macroService.Save(macro); + var macro = CreateMacro(); + _macroService.Save(macro); // Act var currKey = macro.Key; macro.Name = "New name"; macro.Alias = "NewAlias"; - macroService.Save(macro); + _macroService.Save(macro); + macro = _macroService.GetById(macro.Id); - macro = macroService.GetById(macro.Id); - - //assert + // Assert Assert.AreEqual("New name", macro.Name); Assert.AreEqual("NewAlias", macro.Alias); Assert.AreEqual(currKey, macro.Key); @@ -142,10 +137,9 @@ namespace Umbraco.Tests.Services public void Can_Update_Property() { // Arrange - var macroService = ServiceContext.MacroService; - IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); + var macro = CreateMacro(); macro.Properties.Add(new MacroProperty("blah", "Blah", 0, "blah")); - macroService.Save(macro); + _macroService.Save(macro); Assert.AreNotEqual(Guid.Empty, macro.Properties[0].Key); @@ -155,11 +149,11 @@ namespace Umbraco.Tests.Services macro.Properties[0].Name = "new Name"; macro.Properties[0].SortOrder = 1; macro.Properties[0].EditorAlias = "new"; - macroService.Save(macro); + _macroService.Save(macro); - macro = macroService.GetById(macro.Id); + macro = _macroService.GetById(macro.Id); - //assert + // Assert Assert.AreEqual(1, macro.Properties.Count); Assert.AreEqual(currPropKey, macro.Properties[0].Key); Assert.AreEqual("new Alias", macro.Properties[0].Alias); @@ -173,12 +167,11 @@ namespace Umbraco.Tests.Services public void Can_Update_Remove_Property() { // Arrange - var macroService = ServiceContext.MacroService; - IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); + var macro = CreateMacro(); macro.Properties.Add(new MacroProperty("blah1", "Blah1", 0, "blah1")); macro.Properties.Add(new MacroProperty("blah2", "Blah2", 1, "blah2")); macro.Properties.Add(new MacroProperty("blah3", "Blah3", 2, "blah3")); - macroService.Save(macro); + _macroService.Save(macro); var lastKey = macro.Properties[0].Key; for (var i = 1; i < macro.Properties.Count; i++) @@ -197,11 +190,11 @@ namespace Umbraco.Tests.Services var allPropKeys = macro.Properties.Values.Select(x => new { x.Alias, x.Key }).ToArray(); - macroService.Save(macro); + _macroService.Save(macro); - macro = macroService.GetById(macro.Id); + macro = _macroService.GetById(macro.Id); - //assert + // Assert Assert.AreEqual(2, macro.Properties.Count); Assert.AreEqual("newAlias", macro.Properties["newAlias"].Alias); Assert.AreEqual("new Name", macro.Properties["newAlias"].Name); @@ -211,39 +204,36 @@ namespace Umbraco.Tests.Services { Assert.AreEqual(propKey.Key, macro.Properties[propKey.Alias].Key); } - } [Test] public void Can_Add_And_Remove_Properties() { - var macroService = ServiceContext.MacroService; - var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); + var macro = CreateMacro(); - //adds some properties + // Adds some properties macro.Properties.Add(new MacroProperty("blah1", "Blah1", 0, "blah1")); macro.Properties.Add(new MacroProperty("blah2", "Blah2", 0, "blah2")); macro.Properties.Add(new MacroProperty("blah3", "Blah3", 0, "blah3")); macro.Properties.Add(new MacroProperty("blah4", "Blah4", 0, "blah4")); - macroService.Save(macro); + _macroService.Save(macro); - var result1 = macroService.GetById(macro.Id); + var result1 = _macroService.GetById(macro.Id); Assert.AreEqual(4, result1.Properties.Values.Count()); - //simulate clearing the sections + // Simulate clearing the sections foreach (var s in result1.Properties.Values.ToArray()) { result1.Properties.Remove(s.Alias); } - //now just re-add a couple + + // Now just re-add a couple result1.Properties.Add(new MacroProperty("blah3", "Blah3", 0, "blah3")); result1.Properties.Add(new MacroProperty("blah4", "Blah4", 0, "blah4")); - macroService.Save(result1); + _macroService.Save(result1); - //assert - - //re-get - result1 = macroService.GetById(result1.Id); + // Assert + result1 = _macroService.GetById(result1.Id); Assert.AreEqual(2, result1.Properties.Values.Count()); } @@ -252,25 +242,20 @@ namespace Umbraco.Tests.Services public void Cannot_Save_Macro_With_Empty_Name() { // Arrange - var macroService = ServiceContext.MacroService; - var macro = new Macro(ShortStringHelper, "test", string.Empty, "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); + var macro = CreateMacro(name: string.Empty); // Act & Assert - Assert.Throws(() => macroService.Save(macro)); + Assert.Throws(() => _macroService.Save(macro)); } - //[Test] - //public void Can_Get_Many_By_Alias() - //{ - // // Arrange - // var macroService = ServiceContext.MacroService; - - // // Act - // var result = macroService.GetAll("test1", "test2"); - - // //assert - // Assert.AreEqual(2, result.Count()); - //} - + private static IMacro CreateMacro(string name = "Test") + { + return new MacroBuilder() + .WithAlias("test") + .WithName(name) + .WithSource("~/Views/MacroPartials/Test.cshtml") + .WithCacheDuration(1234) + .Build(); + } } } diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 4448308a2e..01871641ac 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -45,8 +45,7 @@ namespace Umbraco.Tests.Integration.Testing [SingleThreaded] [NonParallelizable] public abstract class UmbracoIntegrationTest - { - + { public static LightInjectContainer CreateUmbracoContainer(out UmbracoServiceProviderFactory serviceProviderFactory) { var container = UmbracoServiceProviderFactory.CreateServiceContainer(); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 846b7b9fd2..8863b8ccb5 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -271,7 +271,6 @@ - From 11dc3459bc1c4ddb08c4a9c495e8535d8377c9bf Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 6 Oct 2020 12:02:29 +0200 Subject: [PATCH 24/36] Further update to user service and controller tests to use test builders. --- .../Builders/UserGroupBuilder.cs | 14 ++- .../Services/UserServiceTests.cs | 17 ++-- .../Builders/UserGroupBuilderTests.cs | 4 +- .../Controllers/ContentControllerUnitTests.cs | 88 ++++++++----------- .../Controllers/MediaControllerUnitTests.cs | 50 +++++------ ...terAllowedOutgoingContentAttributeTests.cs | 28 +++--- 6 files changed, 93 insertions(+), 108 deletions(-) diff --git a/src/Umbraco.Tests.Common/Builders/UserGroupBuilder.cs b/src/Umbraco.Tests.Common/Builders/UserGroupBuilder.cs index 6bdc766ee2..a5a96786ce 100644 --- a/src/Umbraco.Tests.Common/Builders/UserGroupBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/UserGroupBuilder.cs @@ -26,7 +26,7 @@ namespace Umbraco.Tests.Common.Builders private string _icon; private string _name; private IEnumerable _permissions = Enumerable.Empty(); - private IEnumerable _sectionCollection = Enumerable.Empty(); + private IEnumerable _allowedSections = Enumerable.Empty(); private string _suffix; private int? _startContentId; private int? _startMediaId; @@ -55,7 +55,7 @@ namespace Umbraco.Tests.Common.Builders public UserGroupBuilder WithPermissions(string permissions) { - _permissions = permissions.Split(); + _permissions = permissions.ToCharArray().Select(x => x.ToString()); return this; } @@ -65,6 +65,12 @@ namespace Umbraco.Tests.Common.Builders return this; } + public UserGroupBuilder WithAllowedSections(IList allowedSections) + { + _allowedSections = allowedSections; + return this; + } + public UserGroupBuilder WithStartContentId(int startContentId) { _startContentId = startContentId; @@ -107,9 +113,9 @@ namespace Umbraco.Tests.Common.Builders userGroup.StartContentId = startContentId; userGroup.StartMediaId = startMediaId; - foreach (var item in _sectionCollection) + foreach (var section in _allowedSections) { - userGroup.AddAllowedSection(item); + userGroup.AddAllowedSection(section); } return userGroup; diff --git a/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs b/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs index ba7dfae0f5..e0f2e423e1 100644 --- a/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs @@ -1052,19 +1052,16 @@ namespace Umbraco.Tests.Integration.Services private UserGroup CreateTestUserGroup(string alias = "testGroup", string name = "Test Group") { - var userGroup = new UserGroup(ShortStringHelper) - { - Alias = alias, - Name = name, - Permissions = "ABCDEFGHIJ1234567".ToCharArray().Select(x => x.ToString()) - }; - - userGroup.AddAllowedSection("content"); - userGroup.AddAllowedSection("media"); + var userGroup = new UserGroupBuilder() + .WithAlias(alias) + .WithName(name) + .WithPermissions("ABCDEFGHIJ1234567") + .WithAllowedSections(new[] { "content", "media" }) + .Build(); _userService.Save(userGroup); - return userGroup; + return (UserGroup)userGroup; } } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/UserGroupBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/UserGroupBuilderTests.cs index 2cd2887878..0cfa0649ff 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/UserGroupBuilderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/UserGroupBuilderTests.cs @@ -1,4 +1,4 @@ -using System; +using System.Linq; using NUnit.Framework; using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Common.Builders.Extensions; @@ -41,7 +41,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders Assert.AreEqual(testName, userGroup.Name); Assert.AreEqual(testUserCount, userGroup.UserCount); Assert.AreEqual(testIcon, userGroup.Icon); - Assert.AreEqual(testPermissions, string.Join(string.Empty, userGroup.Permissions)); + Assert.AreEqual(testPermissions.Length, userGroup.Permissions.Count()); Assert.AreEqual(testStartContentId, userGroup.StartContentId); Assert.AreEqual(testStartMediaId, userGroup.StartMediaId); } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerUnitTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerUnitTests.cs index 56f52215a2..14d888470f 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerUnitTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerUnitTests.cs @@ -1,27 +1,23 @@ -using System.Collections.Generic; -using Moq; +using Moq; using NUnit.Framework; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Core.Services; -using Umbraco.Tests.Common.TestHelpers.Entities; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Common.Builders.Extensions; namespace Umbraco.Tests.Web.Controllers { [TestFixture] public class ContentControllerUnitTests { - [Test] public void Access_Allowed_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List()) }); - var user = userMock.Object; + var user = CreateUser(id: 9); var contentMock = new Mock(); contentMock.Setup(c => c.Path).Returns("-1,1234,5678"); var content = contentMock.Object; @@ -44,9 +40,7 @@ namespace Umbraco.Tests.Web.Controllers public void No_Content_Found() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - var user = userMock.Object; + var user = CreateUser(id: 9); var contentMock = new Mock(); contentMock.Setup(c => c.Path).Returns("-1,1234,5678"); var content = contentMock.Object; @@ -72,10 +66,7 @@ namespace Umbraco.Tests.Web.Controllers public void No_Access_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - userMock.Setup(u => u.StartContentIds).Returns(new[] { 9876 }); - var user = userMock.Object; + var user = CreateUser(id: 9, startContentId: 9876); var contentMock = new Mock(); contentMock.Setup(c => c.Path).Returns("-1,1234,5678"); var content = contentMock.Object; @@ -103,9 +94,7 @@ namespace Umbraco.Tests.Web.Controllers public void No_Access_By_Permission() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - var user = userMock.Object; + var user = CreateUser(id: 9); var contentMock = new Mock(); contentMock.Setup(c => c.Path).Returns("-1,1234,5678"); var content = contentMock.Object; @@ -134,10 +123,7 @@ namespace Umbraco.Tests.Web.Controllers public void Access_Allowed_By_Permission() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List()) }); - var user = userMock.Object; + var user = CreateUser(id: 9); var contentMock = new Mock(); contentMock.Setup(c => c.Path).Returns("-1,1234,5678"); var content = contentMock.Object; @@ -166,10 +152,7 @@ namespace Umbraco.Tests.Web.Controllers public void Access_To_Root_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List()) }); - var user = userMock.Object; + var user = CreateUser(); var contentServiceMock = new Mock(); var contentService = contentServiceMock.Object; var userServiceMock = new Mock(); @@ -188,10 +171,7 @@ namespace Umbraco.Tests.Web.Controllers public void Access_To_Recycle_Bin_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List()) }); - var user = userMock.Object; + var user = CreateUser(); var contentServiceMock = new Mock(); var contentService = contentServiceMock.Object; var userServiceMock = new Mock(); @@ -210,10 +190,7 @@ namespace Umbraco.Tests.Web.Controllers public void No_Access_To_Recycle_Bin_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.StartContentIds).Returns(new[] { 1234 }); - var user = userMock.Object; + var user = CreateUser(startContentId: 1234); var contentServiceMock = new Mock(); var contentService = contentServiceMock.Object; var userServiceMock = new Mock(); @@ -234,10 +211,8 @@ namespace Umbraco.Tests.Web.Controllers public void No_Access_To_Root_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.StartContentIds).Returns(new[] { 1234 }); - var user = userMock.Object; + var user = CreateUser(startContentId: 1234); + var contentServiceMock = new Mock(); var contentService = contentServiceMock.Object; var userServiceMock = new Mock(); @@ -258,10 +233,7 @@ namespace Umbraco.Tests.Web.Controllers public void Access_To_Root_By_Permission() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List()) }); - var user = userMock.Object; + var user = CreateUser(); var userServiceMock = new Mock(); var permissions = new EntityPermissionCollection @@ -276,7 +248,6 @@ namespace Umbraco.Tests.Web.Controllers var entityServiceMock = new Mock(); var entityService = entityServiceMock.Object; - //act var result = ContentPermissionsHelper.CheckPermissions(-1, user, userService, contentService, entityService, out var foundContent, new[] { 'A' }); @@ -288,9 +259,7 @@ namespace Umbraco.Tests.Web.Controllers public void No_Access_To_Root_By_Permission() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - var user = userMock.Object; + var user = CreateUser(withUserGroup: false); var userServiceMock = new Mock(); var permissions = new EntityPermissionCollection @@ -316,10 +285,7 @@ namespace Umbraco.Tests.Web.Controllers public void Access_To_Recycle_Bin_By_Permission() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List()) }); - var user = userMock.Object; + var user = CreateUser(); var userServiceMock = new Mock(); var permissions = new EntityPermissionCollection @@ -346,9 +312,7 @@ namespace Umbraco.Tests.Web.Controllers public void No_Access_To_Recycle_Bin_By_Permission() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - var user = userMock.Object; + var user = CreateUser(withUserGroup: false); var userServiceMock = new Mock(); var permissions = new EntityPermissionCollection @@ -369,6 +333,24 @@ namespace Umbraco.Tests.Web.Controllers //assert Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Denied, result); } + + private IUser CreateUser(int id = 0, int startContentId = -1, bool withUserGroup = true) + { + var builder = new UserBuilder() + .WithId(id) + .WithStartContentIds(startContentId == -1 ? new int[0] : new[] { startContentId }); + if (withUserGroup) + { + builder = builder + .AddUserGroup() + .WithId(1) + .WithName("admin") + .WithAlias("admin") + .Done(); + } + + return builder.Build(); + } } //NOTE: The below self hosted stuff does work so need to get some tests written. Some are not possible atm because diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MediaControllerUnitTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MediaControllerUnitTests.cs index aef08cec5a..124c934b2f 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MediaControllerUnitTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MediaControllerUnitTests.cs @@ -5,7 +5,8 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; -using Umbraco.Tests.Common.TestHelpers.Entities; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Common.Builders.Extensions; using Umbraco.Web.BackOffice.Controllers; using Umbraco.Web.Common.Exceptions; @@ -18,10 +19,7 @@ namespace Umbraco.Tests.Web.Controllers public void Access_Allowed_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List()) }); - var user = userMock.Object; + var user = CreateUser(id: 9); var mediaMock = new Mock(); mediaMock.Setup(m => m.Path).Returns("-1,1234,5678"); var media = mediaMock.Object; @@ -42,9 +40,7 @@ namespace Umbraco.Tests.Web.Controllers public void Throws_Exception_When_No_Media_Found() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - var user = userMock.Object; + var user = CreateUser(id: 9); var mediaMock = new Mock(); mediaMock.Setup(m => m.Path).Returns("-1,1234,5678"); var media = mediaMock.Object; @@ -62,10 +58,7 @@ namespace Umbraco.Tests.Web.Controllers public void No_Access_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - userMock.Setup(u => u.StartMediaIds).Returns(new[] { 9876 }); - var user = userMock.Object; + var user = CreateUser(id: 9, startMediaId: 9876); var mediaMock = new Mock(); mediaMock.Setup(m => m.Path).Returns("-1,1234,5678"); var media = mediaMock.Object; @@ -88,10 +81,7 @@ namespace Umbraco.Tests.Web.Controllers public void Access_To_Root_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List()) }); - var user = userMock.Object; + var user = CreateUser(); var mediaServiceMock = new Mock(); var mediaService = mediaServiceMock.Object; var entityServiceMock = new Mock(); @@ -108,10 +98,7 @@ namespace Umbraco.Tests.Web.Controllers public void No_Access_To_Root_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.StartMediaIds).Returns(new[] { 1234 }); - var user = userMock.Object; + var user = CreateUser(startMediaId: 1234); var mediaServiceMock = new Mock(); var mediaService = mediaServiceMock.Object; var entityServiceMock = new Mock(); @@ -130,10 +117,7 @@ namespace Umbraco.Tests.Web.Controllers public void Access_To_Recycle_Bin_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.Groups).Returns(new[] { new ReadOnlyUserGroup(1, "admin", "", -1, -1, "admin", new string[0], new List()) }); - var user = userMock.Object; + var user = CreateUser(); var mediaServiceMock = new Mock(); var mediaService = mediaServiceMock.Object; var entityServiceMock = new Mock(); @@ -150,10 +134,7 @@ namespace Umbraco.Tests.Web.Controllers public void No_Access_To_Recycle_Bin_By_Path() { //arrange - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(0); - userMock.Setup(u => u.StartMediaIds).Returns(new[] { 1234 }); - var user = userMock.Object; + var user = CreateUser(startMediaId: 1234); var mediaServiceMock = new Mock(); var mediaService = mediaServiceMock.Object; var entityServiceMock = new Mock(); @@ -167,5 +148,18 @@ namespace Umbraco.Tests.Web.Controllers //assert Assert.IsFalse(result); } + + private IUser CreateUser(int id = 0, int startMediaId = -1) + { + return new UserBuilder() + .WithId(id) + .WithStartMediaIds(new[] { startMediaId }) + .AddUserGroup() + .WithId(1) + .WithName("admin") + .WithAlias("admin") + .Done() + .Build(); + } } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingContentAttributeTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingContentAttributeTests.cs index f6e551dc27..6717b0e046 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingContentAttributeTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingContentAttributeTests.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.Net.Http.Headers; using Microsoft.AspNetCore.Mvc; using Moq; using NUnit.Framework; @@ -10,11 +9,11 @@ using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; using Umbraco.Core.Security; using Umbraco.Core.Services; -using Umbraco.Tests.Common.TestHelpers.Entities; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Common.Builders.Extensions; using Umbraco.Web.Actions; using Umbraco.Web.BackOffice.Filters; using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Security; namespace Umbraco.Tests.Web.Controllers { @@ -78,10 +77,7 @@ namespace Umbraco.Tests.Web.Controllers [Test] public void Filter_On_Start_Node() { - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - userMock.Setup(u => u.StartContentIds).Returns(new[] { 5 }); - var user = userMock.Object; + var user = CreateUser(id: 9, startContentId: 5); var userServiceMock = new Mock(); var userService = userServiceMock.Object; var entityServiceMock = new Mock(); @@ -124,10 +120,7 @@ namespace Umbraco.Tests.Web.Controllers } var ids = list.Select(x => (int)x.Id).ToArray(); - var userMock = MockedUser.GetUserMock(); - userMock.Setup(u => u.Id).Returns(9); - userMock.Setup(u => u.StartContentIds).Returns(new int[0]); - var user = userMock.Object; + var user = CreateUser(id: 9, startContentId: 0); var userServiceMock = new Mock(); //we're only assigning 3 nodes browse permissions so that is what we expect as a result @@ -155,6 +148,19 @@ namespace Umbraco.Tests.Web.Controllers Assert.AreEqual(3, list.ElementAt(2).Id); } + private IUser CreateUser(int id = 0, int startContentId = -1) + { + return new UserBuilder() + .WithId(id) + .WithStartContentIds(new[] { startContentId }) + .AddUserGroup() + .WithId(1) + .WithName("admin") + .WithAlias("admin") + .Done() + .Build(); + } + private class MyTestClass { public IEnumerable MyList { get; set; } From 0e5c013c36bb4982b7a3e584ff8470c3529034e4 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 6 Oct 2020 12:43:24 +0200 Subject: [PATCH 25/36] Updated from PR review. --- .../Services/ContentServiceEventTests.cs | 66 ++-- .../Services/LocalizationServiceTests.cs | 130 +++---- .../Services/MacroServiceTests.cs | 48 +-- .../Services/MediaServiceTests.cs | 82 ++--- .../Services/PublicAccessServiceTests.cs | 54 +-- .../Services/SectionServiceTests.cs | 14 +- .../Services/TagServiceTests.cs | 50 +-- .../Services/UserServiceTests.cs | 324 +++++++++--------- 8 files changed, 384 insertions(+), 384 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs index e2b6d20d82..5afc045231 100644 --- a/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ContentServiceEventTests.cs @@ -20,16 +20,16 @@ namespace Umbraco.Tests.Integration.Services Logger = UmbracoTestOptions.Logger.Console)] public class ContentServiceEventTests : UmbracoIntegrationTest { - private IContentTypeService _contentTypeService => GetRequiredService(); - private IContentService _contentService => GetRequiredService(); - private ILocalizationService _localizationService => GetRequiredService(); - private IFileService _fileService => GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + private ContentService ContentService => (ContentService)GetRequiredService(); + private ILocalizationService LocalizationService => GetRequiredService(); + private IFileService FileService => GetRequiredService(); private GlobalSettings _globalSettings; - public override void Setup() + [SetUp] + public void SetupTest() { - base.Setup(); ContentRepositoryBase.ThrowOnWarning = true; _globalSettings = new GlobalSettings(); } @@ -43,22 +43,22 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Saving_Culture() { - _localizationService.Save(new Language(_globalSettings, "fr-FR")); + LocalizationService.Save(new Language(_globalSettings, "fr-FR")); var contentType = MockedContentTypes.CreateTextPageContentType(); - _fileService.SaveTemplate(contentType.DefaultTemplate); + FileService.SaveTemplate(contentType.DefaultTemplate); contentType.Variations = ContentVariation.Culture; foreach (var propertyType in contentType.PropertyTypes) propertyType.Variations = ContentVariation.Culture; - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); document.SetCultureName("hello", "en-US"); document.SetCultureName("bonjour", "fr-FR"); - _contentService.Save(document); + ContentService.Save(document); //re-get - dirty properties need resetting - document = _contentService.GetById(document.Id); + document = ContentService.GetById(document.Id); // properties: title, bodyText, keywords, description document.SetValue("title", "title-en", "en-US"); @@ -87,7 +87,7 @@ namespace Umbraco.Tests.Integration.Services ContentService.Saved += OnSaved; try { - _contentService.Save(document); + ContentService.Save(document); } finally { @@ -100,8 +100,8 @@ namespace Umbraco.Tests.Integration.Services public void Saving_Set_Value() { var contentType = MockedContentTypes.CreateTextPageContentType(); - _fileService.SaveTemplate(contentType.DefaultTemplate); - _contentTypeService.Save(contentType); + FileService.SaveTemplate(contentType.DefaultTemplate); + ContentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); @@ -131,7 +131,7 @@ namespace Umbraco.Tests.Integration.Services ContentService.Saved += OnSaved; try { - _contentService.Save(document); + ContentService.Save(document); } finally { @@ -143,25 +143,25 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Publishing_Culture() { - _localizationService.Save(new Language(_globalSettings, "fr-FR")); + LocalizationService.Save(new Language(_globalSettings, "fr-FR")); var contentType = MockedContentTypes.CreateTextPageContentType(); - _fileService.SaveTemplate(contentType.DefaultTemplate); + FileService.SaveTemplate(contentType.DefaultTemplate); contentType.Variations = ContentVariation.Culture; foreach (var propertyType in contentType.PropertyTypes) propertyType.Variations = ContentVariation.Culture; - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); document.SetCultureName("hello", "en-US"); document.SetCultureName("bonjour", "fr-FR"); - _contentService.Save(document); + ContentService.Save(document); Assert.IsFalse(document.IsCulturePublished("fr-FR")); Assert.IsFalse(document.IsCulturePublished("en-US")); //re-get - dirty properties need resetting - document = _contentService.GetById(document.Id); + document = ContentService.GetById(document.Id); void OnPublishing(IContentService sender, ContentPublishingEventArgs e) { @@ -187,7 +187,7 @@ namespace Umbraco.Tests.Integration.Services ContentService.Published += OnPublished; try { - _contentService.SaveAndPublish(document, "fr-FR"); + ContentService.SaveAndPublish(document, "fr-FR"); } finally { @@ -195,7 +195,7 @@ namespace Umbraco.Tests.Integration.Services ContentService.Published -= OnPublished; } - document = _contentService.GetById(document.Id); + document = ContentService.GetById(document.Id); // ensure it works and does not throw Assert.IsTrue(document.IsCulturePublished("fr-FR")); @@ -206,8 +206,8 @@ namespace Umbraco.Tests.Integration.Services public void Publishing_Set_Value() { var contentType = MockedContentTypes.CreateTextPageContentType(); - _fileService.SaveTemplate(contentType.DefaultTemplate); - _contentTypeService.Save(contentType); + FileService.SaveTemplate(contentType.DefaultTemplate); + ContentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); @@ -240,7 +240,7 @@ namespace Umbraco.Tests.Integration.Services ContentService.Saved += OnSaved; try { - _contentService.SaveAndPublish(document); + ContentService.SaveAndPublish(document); } finally { @@ -255,12 +255,12 @@ namespace Umbraco.Tests.Integration.Services var contentType = MockedContentTypes.CreateTextPageContentType(); var titleProperty = contentType.PropertyTypes.First(x => x.Alias == "title"); titleProperty.Mandatory = true; // make this required! - _fileService.SaveTemplate(contentType.DefaultTemplate); - _contentTypeService.Save(contentType); + FileService.SaveTemplate(contentType.DefaultTemplate); + ContentTypeService.Save(contentType); IContent document = new Content("content", -1, contentType); - var result = _contentService.SaveAndPublish(document); + var result = ContentService.SaveAndPublish(document); Assert.IsFalse(result.Success); Assert.AreEqual("title", result.InvalidProperties.First().Alias); @@ -283,7 +283,7 @@ namespace Umbraco.Tests.Integration.Services ContentService.Saving += OnSaving; try { - result = _contentService.SaveAndPublish(document); + result = ContentService.SaveAndPublish(document); Assert.IsTrue(result.Success); //will succeed now because we were able to specify the required value in the Saving event } finally @@ -295,16 +295,16 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Unpublishing_Culture() { - _localizationService.Save(new Language(_globalSettings, "fr-FR")); + LocalizationService.Save(new Language(_globalSettings, "fr-FR")); var contentType = MockedContentTypes.CreateTextPageContentType(); - _fileService.SaveTemplate(contentType.DefaultTemplate); + FileService.SaveTemplate(contentType.DefaultTemplate); contentType.Variations = ContentVariation.Culture; foreach (var propertyType in contentType.PropertyTypes) propertyType.Variations = ContentVariation.Culture; - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); - var contentService = (ContentService)_contentService; + var contentService = (ContentService)ContentService; IContent document = new Content("content", -1, contentType); document.SetCultureName("hello", "en-US"); diff --git a/src/Umbraco.Tests.Integration/Services/LocalizationServiceTests.cs b/src/Umbraco.Tests.Integration/Services/LocalizationServiceTests.cs index 5c17666619..83d3476324 100644 --- a/src/Umbraco.Tests.Integration/Services/LocalizationServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/LocalizationServiceTests.cs @@ -31,7 +31,7 @@ namespace Umbraco.Tests.Integration.Services private int _englishLangId; private GlobalSettings _globalSettings; - private ILocalizationService _localizationService => GetRequiredService(); + private ILocalizationService LocalizationService => GetRequiredService(); [SetUp] public void SetUp() @@ -43,7 +43,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Get_Root_Dictionary_Items() { - var rootItems = _localizationService.GetRootDictionaryItems(); + var rootItems = LocalizationService.GetRootDictionaryItems(); Assert.NotNull(rootItems); Assert.IsTrue(rootItems.Any()); @@ -52,14 +52,14 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Determint_If_DictionaryItem_Exists() { - var exists = _localizationService.DictionaryItemExists("Parent"); + var exists = LocalizationService.DictionaryItemExists("Parent"); Assert.IsTrue(exists); } [Test] public void Can_Get_All_Languages() { - var languages = _localizationService.GetAllLanguages(); + var languages = LocalizationService.GetAllLanguages(); Assert.NotNull(languages); Assert.IsTrue(languages.Any()); Assert.That(languages.Count(), Is.EqualTo(3)); @@ -68,37 +68,37 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Get_Dictionary_Item_By_Int_Id() { - var parentItem = _localizationService.GetDictionaryItemById(_parentItemIntId); + var parentItem = LocalizationService.GetDictionaryItemById(_parentItemIntId); Assert.NotNull(parentItem); - var childItem = _localizationService.GetDictionaryItemById(_childItemIntId); + var childItem = LocalizationService.GetDictionaryItemById(_childItemIntId); Assert.NotNull(childItem); } [Test] public void Can_Get_Dictionary_Item_By_Guid_Id() { - var parentItem = _localizationService.GetDictionaryItemById(_parentItemGuidId); + var parentItem = LocalizationService.GetDictionaryItemById(_parentItemGuidId); Assert.NotNull(parentItem); - var childItem = _localizationService.GetDictionaryItemById(_childItemGuidId); + var childItem = LocalizationService.GetDictionaryItemById(_childItemGuidId); Assert.NotNull(childItem); } [Test] public void Can_Get_Dictionary_Item_By_Key() { - var parentItem = _localizationService.GetDictionaryItemByKey("Parent"); + var parentItem = LocalizationService.GetDictionaryItemByKey("Parent"); Assert.NotNull(parentItem); - var childItem = _localizationService.GetDictionaryItemByKey("Child"); + var childItem = LocalizationService.GetDictionaryItemByKey("Child"); Assert.NotNull(childItem); } [Test] public void Can_Get_Dictionary_Item_Children() { - var item = _localizationService.GetDictionaryItemChildren(_parentItemGuidId); + var item = LocalizationService.GetDictionaryItemChildren(_parentItemGuidId); Assert.NotNull(item); Assert.That(item.Count(), Is.EqualTo(1)); @@ -114,8 +114,8 @@ namespace Umbraco.Tests.Integration.Services { using (var scope = ScopeProvider.CreateScope()) { - var en = _localizationService.GetLanguageById(_englishLangId); - var dk = _localizationService.GetLanguageById(_danishLangId); + var en = LocalizationService.GetLanguageById(_englishLangId); + var dk = LocalizationService.GetLanguageById(_danishLangId); var currParentId = _childItemGuidId; for (var i = 0; i < 25; i++) @@ -137,8 +137,8 @@ namespace Umbraco.Tests.Integration.Services new DictionaryTranslation(dk, "BørnVærdi2 " + i) } }; - _localizationService.Save(desc1); - _localizationService.Save(desc2); + LocalizationService.Save(desc1); + LocalizationService.Save(desc2); currParentId = desc1.Key; } @@ -146,7 +146,7 @@ namespace Umbraco.Tests.Integration.Services scope.Database.AsUmbracoDatabase().EnableSqlTrace = true; scope.Database.AsUmbracoDatabase().EnableSqlCount = true; - var items = _localizationService.GetDictionaryItemDescendants(_parentItemGuidId).ToArray(); + var items = LocalizationService.GetDictionaryItemDescendants(_parentItemGuidId).ToArray(); Debug.WriteLine("SQL CALLS: " + scope.Database.AsUmbracoDatabase().SqlCount); @@ -159,8 +159,8 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_GetLanguageById() { - var danish = _localizationService.GetLanguageById(_danishLangId); - var english = _localizationService.GetLanguageById(_englishLangId); + var danish = LocalizationService.GetLanguageById(_danishLangId); + var english = LocalizationService.GetLanguageById(_englishLangId); Assert.NotNull(danish); Assert.NotNull(english); } @@ -168,8 +168,8 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_GetLanguageByIsoCode() { - var danish = _localizationService.GetLanguageByIsoCode("da-DK"); - var english = _localizationService.GetLanguageByIsoCode("en-GB"); + var danish = LocalizationService.GetLanguageByIsoCode("da-DK"); + var english = LocalizationService.GetLanguageByIsoCode("en-GB"); Assert.NotNull(danish); Assert.NotNull(english); } @@ -177,14 +177,14 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Does_Not_Fail_When_Language_Doesnt_Exist() { - var language = _localizationService.GetLanguageByIsoCode("sv-SE"); + var language = LocalizationService.GetLanguageByIsoCode("sv-SE"); Assert.Null(language); } [Test] public void Does_Not_Fail_When_DictionaryItem_Doesnt_Exist() { - var item = _localizationService.GetDictionaryItemByKey("RandomKey"); + var item = LocalizationService.GetDictionaryItemByKey("RandomKey"); Assert.Null(item); } @@ -192,34 +192,34 @@ namespace Umbraco.Tests.Integration.Services public void Can_Delete_Language() { var norwegian = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian" }; - _localizationService.Save(norwegian, 0); + LocalizationService.Save(norwegian, 0); Assert.That(norwegian.HasIdentity, Is.True); var languageId = norwegian.Id; - _localizationService.Delete(norwegian); + LocalizationService.Delete(norwegian); - var language = _localizationService.GetLanguageById(languageId); + var language = LocalizationService.GetLanguageById(languageId); Assert.Null(language); } [Test] public void Can_Delete_Language_Used_As_Fallback() { - var danish = _localizationService.GetLanguageByIsoCode("da-DK"); + var danish = LocalizationService.GetLanguageByIsoCode("da-DK"); var norwegian = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian", FallbackLanguageId = danish.Id }; - _localizationService.Save(norwegian, 0); + LocalizationService.Save(norwegian, 0); var languageId = danish.Id; - _localizationService.Delete(danish); + LocalizationService.Delete(danish); - var language = _localizationService.GetLanguageById(languageId); + var language = LocalizationService.GetLanguageById(languageId); Assert.Null(language); } [Test] public void Can_Create_DictionaryItem_At_Root() { - var english = _localizationService.GetLanguageByIsoCode("en-US"); + var english = LocalizationService.GetLanguageByIsoCode("en-US"); var item = (IDictionaryItem)new DictionaryItem("Testing123") { @@ -228,10 +228,10 @@ namespace Umbraco.Tests.Integration.Services new DictionaryTranslation(english, "Hello world") } }; - _localizationService.Save(item); + LocalizationService.Save(item); //re-get - item = _localizationService.GetDictionaryItemById(item.Id); + item = LocalizationService.GetDictionaryItemById(item.Id); Assert.Greater(item.Id, 0); Assert.IsTrue(item.HasIdentity); @@ -243,18 +243,18 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Create_DictionaryItem_At_Root_With_Identity() { - var item = _localizationService.CreateDictionaryItemWithIdentity( + var item = LocalizationService.CreateDictionaryItemWithIdentity( "Testing12345", null, "Hellooooo"); //re-get - item = _localizationService.GetDictionaryItemById(item.Id); + item = LocalizationService.GetDictionaryItemById(item.Id); Assert.IsNotNull(item); Assert.Greater(item.Id, 0); Assert.IsTrue(item.HasIdentity); Assert.IsFalse(item.ParentId.HasValue); Assert.AreEqual("Testing12345", item.ItemKey); - var allLangs = _localizationService.GetAllLanguages(); + var allLangs = LocalizationService.GetAllLanguages(); Assert.Greater(allLangs.Count(), 0); foreach (var language in allLangs) { @@ -265,20 +265,20 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Add_Translation_To_Existing_Dictionary_Item() { - var english = _localizationService.GetLanguageByIsoCode("en-US"); + var english = LocalizationService.GetLanguageByIsoCode("en-US"); var item = (IDictionaryItem) new DictionaryItem("Testing123"); - _localizationService.Save(item); + LocalizationService.Save(item); //re-get - item = _localizationService.GetDictionaryItemById(item.Id); + item = LocalizationService.GetDictionaryItemById(item.Id); item.Translations = new List { new DictionaryTranslation(english, "Hello world") }; - _localizationService.Save(item); + LocalizationService.Save(item); Assert.AreEqual(1, item.Translations.Count()); foreach (var translation in item.Translations) @@ -289,14 +289,14 @@ namespace Umbraco.Tests.Integration.Services item.Translations = new List(item.Translations) { new DictionaryTranslation( - _localizationService.GetLanguageByIsoCode("en-GB"), + LocalizationService.GetLanguageByIsoCode("en-GB"), "My new value") }; - _localizationService.Save(item); + LocalizationService.Save(item); //re-get - item = _localizationService.GetDictionaryItemById(item.Id); + item = LocalizationService.GetDictionaryItemById(item.Id); Assert.AreEqual(2, item.Translations.Count()); Assert.AreEqual("Hello world", item.Translations.First().Value); @@ -306,27 +306,27 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Delete_DictionaryItem() { - var item = _localizationService.GetDictionaryItemByKey("Child"); + var item = LocalizationService.GetDictionaryItemByKey("Child"); Assert.NotNull(item); - _localizationService.Delete(item); + LocalizationService.Delete(item); - var deletedItem = _localizationService.GetDictionaryItemByKey("Child"); + var deletedItem = LocalizationService.GetDictionaryItemByKey("Child"); Assert.Null(deletedItem); } [Test] public void Can_Update_Existing_DictionaryItem() { - var item = _localizationService.GetDictionaryItemByKey("Child"); + var item = LocalizationService.GetDictionaryItemByKey("Child"); foreach (var translation in item.Translations) { translation.Value = translation.Value + "UPDATED"; } - _localizationService.Save(item); + LocalizationService.Save(item); - var updatedItem = _localizationService.GetDictionaryItemByKey("Child"); + var updatedItem = LocalizationService.GetDictionaryItemByKey("Child"); Assert.NotNull(updatedItem); foreach (var translation in updatedItem.Translations) @@ -339,7 +339,7 @@ namespace Umbraco.Tests.Integration.Services public void Find_BaseData_Language() { // Act - var languages = _localizationService.GetAllLanguages(); + var languages = LocalizationService.GetAllLanguages(); // Assert Assert.That(3, Is.EqualTo(languages.Count())); @@ -353,8 +353,8 @@ namespace Umbraco.Tests.Integration.Services var language = new Core.Models.Language(_globalSettings, isoCode); // Act - _localizationService.Save(language); - var result = _localizationService.GetLanguageByIsoCode(isoCode); + LocalizationService.Save(language); + var result = LocalizationService.GetLanguageByIsoCode(isoCode); // Assert Assert.NotNull(result); @@ -367,8 +367,8 @@ namespace Umbraco.Tests.Integration.Services var language = new Core.Models.Language(_globalSettings, isoCode); // Act - _localizationService.Save(language); - var result = _localizationService.GetLanguageById(language.Id); + LocalizationService.Save(language); + var result = LocalizationService.GetLanguageById(language.Id); // Assert Assert.NotNull(result); @@ -378,16 +378,16 @@ namespace Umbraco.Tests.Integration.Services public void Set_Default_Language() { var language = new Language(_globalSettings, "en-AU") {IsDefault = true}; - _localizationService.Save(language); - var result = _localizationService.GetLanguageById(language.Id); + LocalizationService.Save(language); + var result = LocalizationService.GetLanguageById(language.Id); Assert.IsTrue(result.IsDefault); var language2 = new Language(_globalSettings, "en-NZ") {IsDefault = true}; - _localizationService.Save(language2); - var result2 = _localizationService.GetLanguageById(language2.Id); + LocalizationService.Save(language2); + var result2 = LocalizationService.GetLanguageById(language2.Id); //re-get - result = _localizationService.GetLanguageById(language.Id); + result = LocalizationService.GetLanguageById(language.Id); Assert.IsTrue(result2.IsDefault); Assert.IsFalse(result.IsDefault); @@ -398,11 +398,11 @@ namespace Umbraco.Tests.Integration.Services { var isoCode = "en-AU"; var language = new Core.Models.Language(_globalSettings, isoCode); - _localizationService.Save(language); + LocalizationService.Save(language); // Act - _localizationService.Delete(language); - var result = _localizationService.GetLanguageByIsoCode(isoCode); + LocalizationService.Delete(language); + var result = LocalizationService.GetLanguageByIsoCode(isoCode); // Assert Assert.Null(result); @@ -412,8 +412,8 @@ namespace Umbraco.Tests.Integration.Services { var danish = new Language(_globalSettings, "da-DK") { CultureName = "Danish" }; var english = new Language(_globalSettings, "en-GB") { CultureName = "English" }; - _localizationService.Save(danish, 0); - _localizationService.Save(english, 0); + LocalizationService.Save(danish, 0); + LocalizationService.Save(english, 0); _danishLangId = danish.Id; _englishLangId = english.Id; @@ -425,7 +425,7 @@ namespace Umbraco.Tests.Integration.Services new DictionaryTranslation(danish, "ForældreVærdi") } }; - _localizationService.Save(parentItem); + LocalizationService.Save(parentItem); _parentItemGuidId = parentItem.Key; _parentItemIntId = parentItem.Id; @@ -437,7 +437,7 @@ namespace Umbraco.Tests.Integration.Services new DictionaryTranslation(danish, "BørnVærdi") } }; - _localizationService.Save(childItem); + LocalizationService.Save(childItem); _childItemGuidId = childItem.Key; _childItemIntId = childItem.Id; } diff --git a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index 1909503308..2064365cbb 100644 --- a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class MacroServiceTests : UmbracoIntegrationTest { - private MacroService _macroService => (MacroService)GetRequiredService(); + private MacroService MacroService => (MacroService)GetRequiredService(); [SetUp] public override void Setup() @@ -47,7 +47,7 @@ namespace Umbraco.Tests.Integration.Services // Arrange // Act - var macro = _macroService.GetByAlias("test1"); + var macro = MacroService.GetByAlias("test1"); // Assert Assert.IsNotNull(macro); @@ -60,7 +60,7 @@ namespace Umbraco.Tests.Integration.Services // Arrange // Act - var result = _macroService.GetAll(); + var result = MacroService.GetAll(); // Assert Assert.AreEqual(3, result.Count()); @@ -74,19 +74,19 @@ namespace Umbraco.Tests.Integration.Services // Act var macro = CreateMacro(); - _macroService.Save(macro); + MacroService.Save(macro); // Assert Assert.IsTrue(macro.HasIdentity); Assert.Greater(macro.Id, 0); Assert.AreNotEqual(Guid.Empty, macro.Key); - var result = _macroService.GetById(macro.Id); + var result = MacroService.GetById(macro.Id); Assert.AreEqual("test", result.Alias); Assert.AreEqual("Test", result.Name); Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.MacroSource); Assert.AreEqual(1234, result.CacheDuration); - result = _macroService.GetById(macro.Key); + result = MacroService.GetById(macro.Key); Assert.AreEqual("test", result.Alias); Assert.AreEqual("Test", result.Name); Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.MacroSource); @@ -98,16 +98,16 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); - _macroService.Save(macro); + MacroService.Save(macro); // Act - _macroService.Delete(macro); + MacroService.Delete(macro); // Assert - var result = _macroService.GetById(macro.Id); + var result = MacroService.GetById(macro.Id); Assert.IsNull(result); - result = _macroService.GetById(macro.Key); + result = MacroService.GetById(macro.Key); Assert.IsNull(result); } @@ -116,15 +116,15 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var macro = CreateMacro(); - _macroService.Save(macro); + MacroService.Save(macro); // Act var currKey = macro.Key; macro.Name = "New name"; macro.Alias = "NewAlias"; - _macroService.Save(macro); + MacroService.Save(macro); - macro = _macroService.GetById(macro.Id); + macro = MacroService.GetById(macro.Id); // Assert Assert.AreEqual("New name", macro.Name); @@ -139,7 +139,7 @@ namespace Umbraco.Tests.Integration.Services // Arrange var macro = CreateMacro(); macro.Properties.Add(new MacroProperty("blah", "Blah", 0, "blah")); - _macroService.Save(macro); + MacroService.Save(macro); Assert.AreNotEqual(Guid.Empty, macro.Properties[0].Key); @@ -149,9 +149,9 @@ namespace Umbraco.Tests.Integration.Services macro.Properties[0].Name = "new Name"; macro.Properties[0].SortOrder = 1; macro.Properties[0].EditorAlias = "new"; - _macroService.Save(macro); + MacroService.Save(macro); - macro = _macroService.GetById(macro.Id); + macro = MacroService.GetById(macro.Id); // Assert Assert.AreEqual(1, macro.Properties.Count); @@ -171,7 +171,7 @@ namespace Umbraco.Tests.Integration.Services macro.Properties.Add(new MacroProperty("blah1", "Blah1", 0, "blah1")); macro.Properties.Add(new MacroProperty("blah2", "Blah2", 1, "blah2")); macro.Properties.Add(new MacroProperty("blah3", "Blah3", 2, "blah3")); - _macroService.Save(macro); + MacroService.Save(macro); var lastKey = macro.Properties[0].Key; for (var i = 1; i < macro.Properties.Count; i++) @@ -190,9 +190,9 @@ namespace Umbraco.Tests.Integration.Services var allPropKeys = macro.Properties.Values.Select(x => new { x.Alias, x.Key }).ToArray(); - _macroService.Save(macro); + MacroService.Save(macro); - macro = _macroService.GetById(macro.Id); + macro = MacroService.GetById(macro.Id); // Assert Assert.AreEqual(2, macro.Properties.Count); @@ -216,9 +216,9 @@ namespace Umbraco.Tests.Integration.Services macro.Properties.Add(new MacroProperty("blah2", "Blah2", 0, "blah2")); macro.Properties.Add(new MacroProperty("blah3", "Blah3", 0, "blah3")); macro.Properties.Add(new MacroProperty("blah4", "Blah4", 0, "blah4")); - _macroService.Save(macro); + MacroService.Save(macro); - var result1 = _macroService.GetById(macro.Id); + var result1 = MacroService.GetById(macro.Id); Assert.AreEqual(4, result1.Properties.Values.Count()); // Simulate clearing the sections @@ -230,10 +230,10 @@ namespace Umbraco.Tests.Integration.Services // Now just re-add a couple result1.Properties.Add(new MacroProperty("blah3", "Blah3", 0, "blah3")); result1.Properties.Add(new MacroProperty("blah4", "Blah4", 0, "blah4")); - _macroService.Save(result1); + MacroService.Save(result1); // Assert - result1 = _macroService.GetById(result1.Id); + result1 = MacroService.GetById(result1.Id); Assert.AreEqual(2, result1.Properties.Values.Count()); } @@ -245,7 +245,7 @@ namespace Umbraco.Tests.Integration.Services var macro = CreateMacro(name: string.Empty); // Act & Assert - Assert.Throws(() => _macroService.Save(macro)); + Assert.Throws(() => MacroService.Save(macro)); } private static IMacro CreateMacro(string name = "Test") diff --git a/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs index 89c01b54d3..a43f21d061 100644 --- a/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MediaServiceTests.cs @@ -19,8 +19,8 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true)] public class MediaServiceTests : UmbracoIntegrationTest { - private IMediaService _mediaService => GetRequiredService(); - private IMediaTypeService _mediaTypeService => GetRequiredService(); + private IMediaService MediaService => GetRequiredService(); + private IMediaTypeService MediaTypeService => GetRequiredService(); /// /// Used to list out all ambiguous events that will require dispatching with a name @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Integration.Services [Test, Explicit] public void List_Ambiguous_Events() { - var events = _mediaService.GetType().GetEvents(BindingFlags.Static | BindingFlags.Public); + var events = MediaService.GetType().GetEvents(BindingFlags.Static | BindingFlags.Public); var typedEventHandler = typeof(TypedEventHandler<,>); foreach (var e in events) { @@ -52,30 +52,30 @@ namespace Umbraco.Tests.Integration.Services public void Get_Paged_Children_With_Media_Type_Filter() { var mediaType1 = MockedContentTypes.CreateImageMediaType("Image2"); - _mediaTypeService.Save(mediaType1); + MediaTypeService.Save(mediaType1); var mediaType2 = MockedContentTypes.CreateImageMediaType("Image3"); - _mediaTypeService.Save(mediaType2); + MediaTypeService.Save(mediaType2); for (var i = 0; i < 10; i++) { var m1 = MockedMedia.CreateMediaImage(mediaType1, -1); - _mediaService.Save(m1); + MediaService.Save(m1); var m2 = MockedMedia.CreateMediaImage(mediaType2, -1); - _mediaService.Save(m2); + MediaService.Save(m2); } long total; var provider = ScopeProvider; using (provider.CreateScope()) { - var result = _mediaService.GetPagedChildren(-1, 0, 11, out total, + var result = MediaService.GetPagedChildren(-1, 0, 11, out total, provider.SqlContext.Query() .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)), Ordering.By("SortOrder", Direction.Ascending)); Assert.AreEqual(11, result.Count()); Assert.AreEqual(20, total); - result = _mediaService.GetPagedChildren(-1, 1, 11, out total, + result = MediaService.GetPagedChildren(-1, 1, 11, out total, provider.SqlContext.Query() .Where(x => new[] { mediaType1.Id, mediaType2.Id }.Contains(x.ContentTypeId)), Ordering.By("SortOrder", Direction.Ascending)); @@ -89,10 +89,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var mediaItems = CreateTrashedTestMedia(); - var media = _mediaService.GetById(mediaItems.Item3.Id); + var media = MediaService.GetById(mediaItems.Item3.Id); // Act - _mediaService.Move(media, mediaItems.Item2.Id); + MediaService.Move(media, mediaItems.Item2.Id); // Assert Assert.That(media.ParentId, Is.EqualTo(mediaItems.Item2.Id)); @@ -104,10 +104,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var mediaItems = CreateTrashedTestMedia(); - var media = _mediaService.GetById(mediaItems.Item1.Id); + var media = MediaService.GetById(mediaItems.Item1.Id); // Act - _mediaService.MoveToRecycleBin(media); + MediaService.MoveToRecycleBin(media); // Assert Assert.That(media.ParentId, Is.EqualTo(-21)); @@ -119,11 +119,11 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var mediaItems = CreateTrashedTestMedia(); - var media = _mediaService.GetById(mediaItems.Item4.Id); + var media = MediaService.GetById(mediaItems.Item4.Id); // Act - moving out of recycle bin - _mediaService.Move(media, mediaItems.Item1.Id); - var mediaChild = _mediaService.GetById(mediaItems.Item5.Id); + MediaService.Move(media, mediaItems.Item1.Id); + var mediaChild = MediaService.GetById(mediaItems.Item5.Id); // Assert Assert.That(media.ParentId, Is.EqualTo(mediaItems.Item1.Id)); @@ -137,11 +137,11 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var mediaType = MockedContentTypes.CreateVideoMediaType(); - _mediaTypeService.Save(mediaType); - var media = _mediaService.CreateMedia(string.Empty, -1, "video"); + MediaTypeService.Save(mediaType); + var media = MediaService.CreateMedia(string.Empty, -1, "video"); // Act & Assert - Assert.Throws(() => _mediaService.Save(media)); + Assert.Throws(() => MediaService.Save(media)); } /* [Test] @@ -163,13 +163,13 @@ namespace Umbraco.Tests.Integration.Services public void Can_Get_Media_By_Path() { var mediaType = MockedContentTypes.CreateImageMediaType("Image2"); - _mediaTypeService.Save(mediaType); + MediaTypeService.Save(mediaType); var media = MockedMedia.CreateMediaImage(mediaType, -1); - _mediaService.Save(media); + MediaService.Save(media); var mediaPath = "/media/test-image.png"; - var resolvedMedia = _mediaService.GetMediaByPath(mediaPath); + var resolvedMedia = MediaService.GetMediaByPath(mediaPath); Assert.IsNotNull(resolvedMedia); Assert.That(resolvedMedia.GetValue(Constants.Conventions.Media.File).ToString() == mediaPath); @@ -179,13 +179,13 @@ namespace Umbraco.Tests.Integration.Services public void Can_Get_Media_With_Crop_By_Path() { var mediaType = MockedContentTypes.CreateImageMediaTypeWithCrop("Image2"); - _mediaTypeService.Save(mediaType); + MediaTypeService.Save(mediaType); var media = MockedMedia.CreateMediaImageWithCrop(mediaType, -1); - _mediaService.Save(media); + MediaService.Save(media); var mediaPath = "/media/test-image.png"; - var resolvedMedia = _mediaService.GetMediaByPath(mediaPath); + var resolvedMedia = MediaService.GetMediaByPath(mediaPath); Assert.IsNotNull(resolvedMedia); Assert.That(resolvedMedia.GetValue(Constants.Conventions.Media.File).ToString().Contains(mediaPath)); @@ -195,14 +195,14 @@ namespace Umbraco.Tests.Integration.Services public void Can_Get_Paged_Children() { var mediaType = MockedContentTypes.CreateImageMediaType("Image2"); - _mediaTypeService.Save(mediaType); + MediaTypeService.Save(mediaType); for (var i = 0; i < 10; i++) { var c1 = MockedMedia.CreateMediaImage(mediaType, -1); - _mediaService.Save(c1); + MediaService.Save(c1); } - var service = _mediaService; + var service = MediaService; long total; var entities = service.GetPagedChildren(-1, 0, 6, out total).ToArray(); @@ -217,25 +217,25 @@ namespace Umbraco.Tests.Integration.Services public void Can_Get_Paged_Children_Dont_Get_Descendants() { var mediaType = MockedContentTypes.CreateImageMediaType("Image2"); - _mediaTypeService.Save(mediaType); + MediaTypeService.Save(mediaType); // only add 9 as we also add a folder with children for (var i = 0; i < 9; i++) { var m1 = MockedMedia.CreateMediaImage(mediaType, -1); - _mediaService.Save(m1); + MediaService.Save(m1); } var mediaTypeForFolder = MockedContentTypes.CreateImageMediaType("Folder2"); - _mediaTypeService.Save(mediaTypeForFolder); + MediaTypeService.Save(mediaTypeForFolder); var mediaFolder = MockedMedia.CreateMediaFolder(mediaTypeForFolder, -1); - _mediaService.Save(mediaFolder); + MediaService.Save(mediaFolder); for (var i = 0; i < 10; i++) { var m1 = MockedMedia.CreateMediaImage(mediaType, mediaFolder.Id); - _mediaService.Save(m1); + MediaService.Save(m1); } - var service = _mediaService; + var service = MediaService; long total; // children in root including the folder - not the descendants in the folder @@ -258,28 +258,28 @@ namespace Umbraco.Tests.Integration.Services private Tuple CreateTrashedTestMedia() { //Create and Save folder-Media -> 1050 - var folderMediaType = _mediaTypeService.Get(1031); + var folderMediaType = MediaTypeService.Get(1031); var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1); - _mediaService.Save(folder); + MediaService.Save(folder); //Create and Save folder-Media -> 1051 var folder2 = MockedMedia.CreateMediaFolder(folderMediaType, -1); - _mediaService.Save(folder2); + MediaService.Save(folder2); //Create and Save image-Media -> 1052 - var imageMediaType = _mediaTypeService.Get(1032); + var imageMediaType = MediaTypeService.Get(1032); var image = (Media)MockedMedia.CreateMediaImage(imageMediaType, 1050); - _mediaService.Save(image); + MediaService.Save(image); //Create and Save folder-Media that is trashed -> 1053 var folderTrashed = (Media)MockedMedia.CreateMediaFolder(folderMediaType, -21); folderTrashed.Trashed = true; - _mediaService.Save(folderTrashed); + MediaService.Save(folderTrashed); //Create and Save image-Media child of folderTrashed -> 1054 var imageTrashed = (Media)MockedMedia.CreateMediaImage(imageMediaType, folderTrashed.Id); imageTrashed.Trashed = true; - _mediaService.Save(imageTrashed); + MediaService.Save(imageTrashed); return new Tuple(folder, folder2, image, folderTrashed, imageTrashed); } diff --git a/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs b/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs index 42419565a2..5294e8015b 100644 --- a/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/PublicAccessServiceTests.cs @@ -15,20 +15,20 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class PublicAccessServiceTests : UmbracoIntegrationTest { - private IContentService _contentService => GetRequiredService(); - private IContentTypeService _contentTypeService => GetRequiredService(); - private IFileService _fileService => GetRequiredService(); - private IPublicAccessService _publicAccessService => GetRequiredService(); + private IContentService ContentService => GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + private IFileService FileService => GetRequiredService(); + private IPublicAccessService PublicAccessService => GetRequiredService(); [Test] public void Can_Add_New_Entry() { // Arrange var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - _fileService.SaveTemplate(ct.DefaultTemplate); - _contentTypeService.Save(ct); + FileService.SaveTemplate(ct.DefaultTemplate); + ContentTypeService.Save(ct); var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - _contentService.Save(c); + ContentService.Save(c); // Act var entry = new PublicAccessEntry(c, c, c, new[] @@ -39,7 +39,7 @@ namespace Umbraco.Tests.Integration.Services RuleValue = "TestVal" }, }); - var result = _publicAccessService.Save(entry); + var result = PublicAccessService.Save(entry); // Assert Assert.IsTrue(result.Success); @@ -56,10 +56,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - _fileService.SaveTemplate(ct.DefaultTemplate); - _contentTypeService.Save(ct); + FileService.SaveTemplate(ct.DefaultTemplate); + ContentTypeService.Save(ct); var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - _contentService.Save(c); + ContentService.Save(c); var entry = new PublicAccessEntry(c, c, c, new[] { new PublicAccessRule() @@ -68,12 +68,12 @@ namespace Umbraco.Tests.Integration.Services RuleValue = "TestVal" }, }); - _publicAccessService.Save(entry); + PublicAccessService.Save(entry); // Act - var updated = _publicAccessService.AddRule(c, "TestType2", "AnotherVal"); + var updated = PublicAccessService.AddRule(c, "TestType2", "AnotherVal"); //re-get - entry = _publicAccessService.GetEntryForContent(c); + entry = PublicAccessService.GetEntryForContent(c); // Assert Assert.IsTrue(updated.Success); @@ -86,10 +86,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - _fileService.SaveTemplate(ct.DefaultTemplate); - _contentTypeService.Save(ct); + FileService.SaveTemplate(ct.DefaultTemplate); + ContentTypeService.Save(ct); var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - _contentService.Save(c); + ContentService.Save(c); var entry = new PublicAccessEntry(c, c, c, new[] { new PublicAccessRule() @@ -98,14 +98,14 @@ namespace Umbraco.Tests.Integration.Services RuleValue = "TestVal" }, }); - _publicAccessService.Save(entry); + PublicAccessService.Save(entry); // Act - var updated1 = _publicAccessService.AddRule(c, "TestType", "AnotherVal1"); - var updated2 = _publicAccessService.AddRule(c, "TestType", "AnotherVal2"); + var updated1 = PublicAccessService.AddRule(c, "TestType", "AnotherVal1"); + var updated2 = PublicAccessService.AddRule(c, "TestType", "AnotherVal2"); //re-get - entry = _publicAccessService.GetEntryForContent(c); + entry = PublicAccessService.GetEntryForContent(c); // Assert Assert.IsTrue(updated1.Success); @@ -120,10 +120,10 @@ namespace Umbraco.Tests.Integration.Services { // Arrange var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); - _fileService.SaveTemplate(ct.DefaultTemplate); - _contentTypeService.Save(ct); + FileService.SaveTemplate(ct.DefaultTemplate); + ContentTypeService.Save(ct); var c = MockedContent.CreateSimpleContent(ct, "Test", -1); - _contentService.Save(c); + ContentService.Save(c); var entry = new PublicAccessEntry(c, c, c, new[] { new PublicAccessRule() @@ -137,12 +137,12 @@ namespace Umbraco.Tests.Integration.Services RuleValue = "TestValue2" }, }); - _publicAccessService.Save(entry); + PublicAccessService.Save(entry); // Act - var removed = _publicAccessService.RemoveRule(c, "TestType", "TestValue1"); + var removed = PublicAccessService.RemoveRule(c, "TestType", "TestValue1"); //re-get - entry = _publicAccessService.GetEntryForContent(c); + entry = PublicAccessService.GetEntryForContent(c); // Assert Assert.IsTrue(removed.Success); diff --git a/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs b/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs index ef8301a315..f34ea32cff 100644 --- a/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/SectionServiceTests.cs @@ -18,8 +18,8 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class SectionServiceTests : UmbracoIntegrationTest { - private ISectionService _sectionService => GetRequiredService(); - private IUserService _userService => GetRequiredService(); + private ISectionService SectionService => GetRequiredService(); + private IUserService UserService => GetRequiredService(); [Test] public void SectionService_Can_Get_Allowed_Sections_For_User() @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Integration.Services var user = CreateTestUser(); // Act - var result = _sectionService.GetAllowedSections(user.Id).ToList(); + var result = SectionService.GetAllowedSections(user.Id).ToList(); // Assert Assert.AreEqual(3, result.Count); @@ -43,7 +43,7 @@ namespace Umbraco.Tests.Integration.Services Username = "testUser", Email = "testuser@test.com", }; - _userService.Save(user, false); + UserService.Save(user, false); var userGroupA = new UserGroup(ShortStringHelper) { @@ -53,7 +53,7 @@ namespace Umbraco.Tests.Integration.Services userGroupA.AddAllowedSection("media"); userGroupA.AddAllowedSection("settings"); // TODO: This is failing the test - _userService.Save(userGroupA, new[] { user.Id }, false); + UserService.Save(userGroupA, new[] { user.Id }, false); var userGroupB = new UserGroup(ShortStringHelper) { @@ -62,9 +62,9 @@ namespace Umbraco.Tests.Integration.Services }; userGroupB.AddAllowedSection("settings"); userGroupB.AddAllowedSection("member"); - _userService.Save(userGroupB, new[] { user.Id }, false); + UserService.Save(userGroupB, new[] { user.Id }, false); - return _userService.GetUserById(user.Id); + return UserService.GetUserById(user.Id); } } } diff --git a/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs b/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs index a3ee817a28..585c1319a4 100644 --- a/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/TagServiceTests.cs @@ -22,11 +22,11 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class TagServiceTests : UmbracoIntegrationTest { - private IContentService _contentService => GetRequiredService(); - private IContentTypeService _contentTypeService => GetRequiredService(); - private ITagService _tagService => GetRequiredService(); - private IDataTypeService _dataTypeService => GetRequiredService(); - private PropertyEditorCollection _propertyEditorCollection => GetRequiredService(); + private IContentService ContentService => GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + private ITagService TagService => GetRequiredService(); + private IDataTypeService DataTypeService => GetRequiredService(); + private PropertyEditorCollection PropertyEditorCollection => GetRequiredService(); [Test] public void TagApiConsistencyTest() @@ -37,25 +37,25 @@ namespace Umbraco.Tests.Integration.Services { DataTypeId = 1041 }); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); IContent content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); - content1.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow", "pig", "goat" }); - _contentService.SaveAndPublish(content1); + content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig", "goat" }); + ContentService.SaveAndPublish(content1); // change - content1.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "elephant" }, true); - content1.RemoveTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow" }); - _contentService.SaveAndPublish(content1); + content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "elephant" }, true); + content1.RemoveTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow" }); + ContentService.SaveAndPublish(content1); // more changes - content1.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "mouse" }, true); - _contentService.SaveAndPublish(content1); - content1.RemoveTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "mouse" }); - _contentService.SaveAndPublish(content1); + content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "mouse" }, true); + ContentService.SaveAndPublish(content1); + content1.RemoveTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "mouse" }); + ContentService.SaveAndPublish(content1); // get it back - content1 = _contentService.GetById(content1.Id); + content1 = ContentService.GetById(content1.Id); var tagsValue = content1.GetValue("tags").ToString(); var tagsValues = JsonConvert.DeserializeObject(tagsValue); Assert.AreEqual(3, tagsValues.Length); @@ -63,7 +63,7 @@ namespace Umbraco.Tests.Integration.Services Assert.Contains("goat", tagsValues); Assert.Contains("elephant", tagsValues); - var tags = _tagService.GetTagsForProperty(content1.Id, "tags").ToArray(); + var tags = TagService.GetTagsForProperty(content1.Id, "tags").ToArray(); Assert.IsTrue(tags.All(x => x.Group == "default")); tagsValues = tags.Select(x => x.Text).ToArray(); @@ -82,22 +82,22 @@ namespace Umbraco.Tests.Integration.Services { DataTypeId = Constants.DataTypes.Tags }); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var content1 = MockedContent.CreateSimpleContent(contentType, "Tagged content 1", -1); - content1.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow", "pig", "goat" }); - _contentService.SaveAndPublish(content1); + content1.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig", "goat" }); + ContentService.SaveAndPublish(content1); var content2 = MockedContent.CreateSimpleContent(contentType, "Tagged content 2", -1); - content2.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow", "pig" }); - _contentService.SaveAndPublish(content2); + content2.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow", "pig" }); + ContentService.SaveAndPublish(content2); var content3 = MockedContent.CreateSimpleContent(contentType, "Tagged content 3", -1); - content3.AssignTags(_propertyEditorCollection, _dataTypeService, "tags", new[] { "cow" }); - _contentService.SaveAndPublish(content3); + content3.AssignTags(PropertyEditorCollection, DataTypeService, "tags", new[] { "cow" }); + ContentService.SaveAndPublish(content3); // Act - var tags = _tagService.GetAllContentTags() + var tags = TagService.GetAllContentTags() .OrderByDescending(x => x.NodeCount) .ToList(); diff --git a/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs b/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs index e0f2e423e1..fbe51da837 100644 --- a/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/UserServiceTests.cs @@ -29,9 +29,9 @@ namespace Umbraco.Tests.Integration.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)] public class UserServiceTests : UmbracoIntegrationTest { - private UserService _userService => (UserService) GetRequiredService(); - private IContentTypeService _contentTypeService => GetRequiredService(); - private IContentService _contentService => GetRequiredService(); + private UserService UserService => (UserService) GetRequiredService(); + private IContentTypeService ContentTypeService => GetRequiredService(); + private IContentService ContentService => GetRequiredService(); [Test] public void Get_User_Permissions_For_Unassigned_Permission_Nodes() @@ -39,17 +39,17 @@ namespace Umbraco.Tests.Integration.Services // Arrange var user = CreateTestUser(out _); var contentType = MockedContentTypes.CreateSimpleContentType(); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - _contentService.Save(content); + ContentService.Save(content); // Act - var permissions = _userService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); + var permissions = UserService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); // Assert Assert.AreEqual(3, permissions.Length); @@ -65,23 +65,23 @@ namespace Umbraco.Tests.Integration.Services var user = CreateTestUser(out var userGroup); var contentType = MockedContentTypes.CreateSimpleContentType(); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - _contentService.Save(content); - _contentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[2], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.Save(content); + ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[2], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); // Act - var permissions = _userService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); + var permissions = UserService.GetPermissions(user, content[0].Id, content[1].Id, content[2].Id).ToArray(); // Assert Assert.AreEqual(3, permissions.Length); @@ -97,23 +97,23 @@ namespace Umbraco.Tests.Integration.Services var userGroup = CreateTestUserGroup(); var contentType = MockedContentTypes.CreateSimpleContentType(); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - _contentService.Save(content); - _contentService.SetPermission(content.ElementAt(0), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content.ElementAt(0), ActionDelete.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content.ElementAt(0), ActionMove.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content.ElementAt(1), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content.ElementAt(1), ActionDelete.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content.ElementAt(2), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.Save(content); + ContentService.SetPermission(content.ElementAt(0), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content.ElementAt(0), ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content.ElementAt(0), ActionMove.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content.ElementAt(1), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content.ElementAt(1), ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content.ElementAt(2), ActionBrowse.ActionLetter, new int[] { userGroup.Id }); // Act - var permissions = _userService.GetPermissions(userGroup, false, content[0].Id, content[1].Id, content[2].Id).ToArray(); + var permissions = UserService.GetPermissions(userGroup, false, content[0].Id, content[1].Id, content[2].Id).ToArray(); // Assert Assert.AreEqual(3, permissions.Length); @@ -129,22 +129,22 @@ namespace Umbraco.Tests.Integration.Services var userGroup = CreateTestUserGroup(); var contentType = MockedContentTypes.CreateSimpleContentType(); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - _contentService.Save(content); - _contentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.Save(content); + ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); // Act - var permissions = _userService.GetPermissions(userGroup, true, content[0].Id, content[1].Id, content[2].Id) + var permissions = UserService.GetPermissions(userGroup, true, content[0].Id, content[1].Id, content[2].Id) .ToArray(); // Assert @@ -161,35 +161,35 @@ namespace Umbraco.Tests.Integration.Services var userGroup1 = CreateTestUserGroup(); var userGroup2 = CreateTestUserGroup("test2", "Test 2"); var userGroup3 = CreateTestUserGroup("test3", "Test 3"); - var user = _userService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); + var user = UserService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); var defaultPermissionCount = userGroup3.Permissions.Count(); user.AddGroup(userGroup1); user.AddGroup(userGroup2); user.AddGroup(userGroup3); - _userService.Save(user); + UserService.Save(user); var contentType = MockedContentTypes.CreateSimpleContentType(); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - _contentService.Save(content); + ContentService.Save(content); //assign permissions - we aren't assigning anything explicit for group3 and nothing explicit for content[2] /w group2 - _contentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); - _contentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); - _contentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup2.Id }); - _contentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); - _contentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup2.Id }); - _contentService.SetPermission(content[2], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); + ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); + ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); + ContentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup2.Id }); + ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup1.Id }); + ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup2.Id }); + ContentService.SetPermission(content[2], ActionDelete.ActionLetter, new int[] { userGroup1.Id }); // Act //we don't pass in any nodes so it will return all of them - var result = _userService.GetPermissions(user).ToArray(); + var result = UserService.GetPermissions(user).ToArray(); var permissions = result .GroupBy(x => x.EntityId) .ToDictionary(x => x.Key, x => x.GroupBy(a => a.UserGroupId).ToDictionary(a => a.Key, a => a.ToArray())); @@ -240,24 +240,24 @@ namespace Umbraco.Tests.Integration.Services var userGroup = CreateTestUserGroup(); var contentType = MockedContentTypes.CreateSimpleContentType(); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var content = new[] { MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType), MockedContent.CreateSimpleContent(contentType) }; - _contentService.Save(content); - _contentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(content[2], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.Save(content); + ContentService.SetPermission(content[0], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[0], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[0], ActionMove.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[1], ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[1], ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(content[2], ActionDelete.ActionLetter, new int[] { userGroup.Id }); // Act //we don't pass in any nodes so it will return all of them - var permissions = _userService.GetPermissions(userGroup, true) + var permissions = UserService.GetPermissions(userGroup, true) .GroupBy(x => x.EntityId) .ToDictionary(x => x.Key, x => x); @@ -401,22 +401,22 @@ namespace Umbraco.Tests.Integration.Services var userGroup = CreateTestUserGroup(); var contentType = MockedContentTypes.CreateSimpleContentType(); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var parent = MockedContent.CreateSimpleContent(contentType); - _contentService.Save(parent); + ContentService.Save(parent); var child1 = MockedContent.CreateSimpleContent(contentType, "child1", parent); - _contentService.Save(child1); + ContentService.Save(child1); var child2 = MockedContent.CreateSimpleContent(contentType, "child2", child1); - _contentService.Save(child2); + ContentService.Save(child2); - _contentService.SetPermission(parent, ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(parent, ActionDelete.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(parent, ActionMove.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(parent, ActionBrowse.ActionLetter, new int[] { userGroup.Id }); - _contentService.SetPermission(parent, ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(parent, ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(parent, ActionDelete.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(parent, ActionMove.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(parent, ActionBrowse.ActionLetter, new int[] { userGroup.Id }); + ContentService.SetPermission(parent, ActionDelete.ActionLetter, new int[] { userGroup.Id }); // Act - var permissions = _userService.GetPermissionsForPath(userGroup, child2.Path); + var permissions = UserService.GetPermissionsForPath(userGroup, child2.Path); // Assert var allPermissions = permissions.GetAllPermissions().ToArray(); @@ -426,10 +426,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Can_Delete_User() { - var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - _userService.Delete(user, true); - var deleted = _userService.GetUserById(user.Id); + UserService.Delete(user, true); + var deleted = UserService.GetUserById(user.Id); // Assert Assert.That(deleted, Is.Null); @@ -438,10 +438,10 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Disables_User_Instead_Of_Deleting_If_Flag_Not_Set() { - var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - _userService.Delete(user); - var deleted = _userService.GetUserById(user.Id); + UserService.Delete(user); + var deleted = UserService.GetUserById(user.Id); // Assert Assert.That(deleted, Is.Not.Null); @@ -450,60 +450,60 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Exists_By_Username() { - var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - var user2 = _userService.CreateUserWithIdentity("john2@umbraco.io", "john2@umbraco.io"); - Assert.IsTrue(_userService.Exists("JohnDoe")); - Assert.IsFalse(_userService.Exists("notFound")); - Assert.IsTrue(_userService.Exists("john2@umbraco.io")); + var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user2 = UserService.CreateUserWithIdentity("john2@umbraco.io", "john2@umbraco.io"); + Assert.IsTrue(UserService.Exists("JohnDoe")); + Assert.IsFalse(UserService.Exists("notFound")); + Assert.IsTrue(UserService.Exists("john2@umbraco.io")); } [Test] public void Get_By_Email() { - var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - Assert.IsNotNull(_userService.GetByEmail(user.Email)); - Assert.IsNull(_userService.GetByEmail("do@not.find")); + Assert.IsNotNull(UserService.GetByEmail(user.Email)); + Assert.IsNull(UserService.GetByEmail("do@not.find")); } [Test] public void Get_By_Username() { - var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - Assert.IsNotNull(_userService.GetByUsername(user.Username)); - Assert.IsNull(_userService.GetByUsername("notFound")); + Assert.IsNotNull(UserService.GetByUsername(user.Username)); + Assert.IsNull(UserService.GetByUsername("notFound")); } [Test] public void Get_By_Username_With_Backslash() { - var user = _userService.CreateUserWithIdentity("mydomain\\JohnDoe", "john@umbraco.io"); + var user = UserService.CreateUserWithIdentity("mydomain\\JohnDoe", "john@umbraco.io"); - Assert.IsNotNull(_userService.GetByUsername(user.Username)); - Assert.IsNull(_userService.GetByUsername("notFound")); + Assert.IsNotNull(UserService.GetByUsername(user.Username)); + Assert.IsNull(UserService.GetByUsername("notFound")); } [Test] public void Get_By_Object_Id() { - var user = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var user = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); - Assert.IsNotNull(_userService.GetUserById(user.Id)); - Assert.IsNull(_userService.GetUserById(9876)); + Assert.IsNotNull(UserService.GetUserById(user.Id)); + Assert.IsNull(UserService.GetUserById(9876)); } [Test] public void Find_By_Email_Starts_With() { var users = CreateMulipleUsers(10); - _userService.Save(users); + UserService.Save(users); //don't find this var customUser = CreateUser(); customUser.Email = "hello@hello.com"; - _userService.Save(customUser); + UserService.Save(customUser); - var found = _userService.FindByEmail("tes", 0, 100, out _, StringPropertyMatchType.StartsWith); + var found = UserService.FindByEmail("tes", 0, 100, out _, StringPropertyMatchType.StartsWith); Assert.AreEqual(10, found.Count()); } @@ -512,13 +512,13 @@ namespace Umbraco.Tests.Integration.Services public void Find_By_Email_Ends_With() { var users = CreateMulipleUsers(10); - _userService.Save(users); + UserService.Save(users); //include this var customUser = CreateUser(); customUser.Email = "hello@test.com"; - _userService.Save(customUser); + UserService.Save(customUser); - var found = _userService.FindByEmail("test.com", 0, 100, out _, StringPropertyMatchType.EndsWith); + var found = UserService.FindByEmail("test.com", 0, 100, out _, StringPropertyMatchType.EndsWith); Assert.AreEqual(11, found.Count()); } @@ -527,13 +527,13 @@ namespace Umbraco.Tests.Integration.Services public void Find_By_Email_Contains() { var users = CreateMulipleUsers(10); - _userService.Save(users); + UserService.Save(users); //include this var customUser = CreateUser(); customUser.Email = "hello@test.com"; - _userService.Save(customUser); + UserService.Save(customUser); - var found = _userService.FindByEmail("test", 0, 100, out _, StringPropertyMatchType.Contains); + var found = UserService.FindByEmail("test", 0, 100, out _, StringPropertyMatchType.Contains); Assert.AreEqual(11, found.Count()); } @@ -542,13 +542,13 @@ namespace Umbraco.Tests.Integration.Services public void Find_By_Email_Exact() { var users = CreateMulipleUsers(10); - _userService.Save(users); + UserService.Save(users); //include this var customUser = CreateUser(); customUser.Email = "hello@test.com"; - _userService.Save(customUser); + UserService.Save(customUser); - var found = _userService.FindByEmail("hello@test.com", 0, 100, out _, StringPropertyMatchType.Exact); + var found = UserService.FindByEmail("hello@test.com", 0, 100, out _, StringPropertyMatchType.Exact); Assert.AreEqual(1, found.Count()); } @@ -557,9 +557,9 @@ namespace Umbraco.Tests.Integration.Services public void Get_All_Paged_Users() { var users = CreateMulipleUsers(10); - _userService.Save(users); + UserService.Save(users); - var found = _userService.GetAll(0, 2, out var totalRecs); + var found = UserService.GetAll(0, 2, out var totalRecs); Assert.AreEqual(2, found.Count()); // + 1 because of the built in admin user @@ -572,9 +572,9 @@ namespace Umbraco.Tests.Integration.Services public void Get_All_Paged_Users_With_Filter() { var users = CreateMulipleUsers(10).ToArray(); - _userService.Save(users); + UserService.Save(users); - var found = _userService.GetAll(0, 2, out var totalRecs, "username", Direction.Ascending, filter: "test"); + var found = UserService.GetAll(0, 2, out var totalRecs, "username", Direction.Ascending, filter: "test"); Assert.AreEqual(2, found.Count()); Assert.AreEqual(10, totalRecs); @@ -586,7 +586,7 @@ namespace Umbraco.Tests.Integration.Services public void Get_All_Paged_Users_For_Group() { var userGroup = MockedUserGroup.CreateUserGroup(); - _userService.Save(userGroup); + UserService.Save(userGroup); var users = CreateMulipleUsers(10).ToArray(); for (var i = 0; i < 10;) @@ -594,10 +594,10 @@ namespace Umbraco.Tests.Integration.Services users[i].AddGroup(userGroup.ToReadOnlyGroup()); i = i + 2; } - _userService.Save(users); + UserService.Save(users); long totalRecs; - var found = _userService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, includeUserGroups: new[] { userGroup.Alias }); + var found = UserService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, includeUserGroups: new[] { userGroup.Alias }); Assert.AreEqual(2, found.Count()); Assert.AreEqual(5, totalRecs); @@ -609,7 +609,7 @@ namespace Umbraco.Tests.Integration.Services public void Get_All_Paged_Users_For_Group_With_Filter() { var userGroup = MockedUserGroup.CreateUserGroup(); - _userService.Save(userGroup); + UserService.Save(userGroup); var users = CreateMulipleUsers(10).ToArray(); for (var i = 0; i < 10;) @@ -622,10 +622,10 @@ namespace Umbraco.Tests.Integration.Services users[i].Name = "blah" + users[i].Name; i = i + 3; } - _userService.Save(users); + UserService.Save(users); long totalRecs; - var found = _userService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, userGroups: new[] { userGroup.Alias }, filter: "blah"); + var found = UserService.GetAll(0, 2, out totalRecs, "username", Direction.Ascending, userGroups: new[] { userGroup.Alias }, filter: "blah"); Assert.AreEqual(2, found.Count()); Assert.AreEqual(2, totalRecs); @@ -637,11 +637,11 @@ namespace Umbraco.Tests.Integration.Services public void Count_All_Users() { var users = CreateMulipleUsers(10); - _userService.Save(users); + UserService.Save(users); var customUser = CreateUser(); - _userService.Save(customUser); + UserService.Save(customUser); - var found = _userService.GetCount(MemberCountType.All); + var found = UserService.GetCount(MemberCountType.All); // + 1 because of the built in admin user Assert.AreEqual(12, found); @@ -652,7 +652,7 @@ namespace Umbraco.Tests.Integration.Services public void Count_All_Online_Users() { var users = CreateMulipleUsers(10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2)); - _userService.Save(users); + UserService.Save(users); var customUser = CreateUser(); throw new NotImplementedException(); @@ -662,13 +662,13 @@ namespace Umbraco.Tests.Integration.Services public void Count_All_Locked_Users() { var users = CreateMulipleUsers(10, (i, member) => member.IsLockedOut = i % 2 == 0); - _userService.Save(users); + UserService.Save(users); var customUser = CreateUser(); customUser.IsLockedOut = true; - _userService.Save(customUser); + UserService.Save(customUser); - var found = _userService.GetCount(MemberCountType.LockedOut); + var found = UserService.GetCount(MemberCountType.LockedOut); Assert.AreEqual(6, found); } @@ -677,13 +677,13 @@ namespace Umbraco.Tests.Integration.Services public void Count_All_Approved_Users() { var users = CreateMulipleUsers(10, (i, member) => member.IsApproved = i % 2 == 0); - _userService.Save(users); + UserService.Save(users); var customUser = CreateUser(); customUser.IsApproved = false; - _userService.Save(customUser); + UserService.Save(customUser); - var found = _userService.GetCount(MemberCountType.Approved); + var found = UserService.GetCount(MemberCountType.Approved); // + 1 because of the built in admin user Assert.AreEqual(6, found); @@ -693,7 +693,7 @@ namespace Umbraco.Tests.Integration.Services public void Can_Persist_New_User() { // Act - var membershipUser = _userService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); + var membershipUser = UserService.CreateUserWithIdentity("JohnDoe", "john@umbraco.io"); // Assert Assert.That(membershipUser.HasIdentity, Is.True); @@ -713,7 +713,7 @@ namespace Umbraco.Tests.Integration.Services var encodedPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password))); var globalSettings = new GlobalSettings(); var membershipUser = new User(globalSettings, "JohnDoe", "john@umbraco.io", encodedPassword, encodedPassword); - _userService.Save(membershipUser); + UserService.Save(membershipUser); // Assert Assert.That(membershipUser.HasIdentity, Is.True); @@ -733,9 +733,9 @@ namespace Umbraco.Tests.Integration.Services }; userGroup.AddAllowedSection("content"); userGroup.AddAllowedSection("mediat"); - _userService.Save(userGroup); + UserService.Save(userGroup); - var result1 = _userService.GetUserGroupById(userGroup.Id); + var result1 = UserService.GetUserGroupById(userGroup.Id); Assert.AreEqual(2, result1.AllowedSections.Count()); @@ -744,9 +744,9 @@ namespace Umbraco.Tests.Integration.Services userGroup.AddAllowedSection("test2"); userGroup.AddAllowedSection("test3"); userGroup.AddAllowedSection("test4"); - _userService.Save(userGroup); + UserService.Save(userGroup); - result1 = _userService.GetUserGroupById(userGroup.Id); + result1 = UserService.GetUserGroupById(userGroup.Id); Assert.AreEqual(6, result1.AllowedSections.Count()); @@ -759,11 +759,11 @@ namespace Umbraco.Tests.Integration.Services //now just re-add a couple result1.AddAllowedSection("test3"); result1.AddAllowedSection("test4"); - _userService.Save(result1); + UserService.Save(result1); // Assert //re-get - result1 = _userService.GetUserGroupById(userGroup.Id); + result1 = UserService.GetUserGroupById(userGroup.Id); Assert.AreEqual(2, result1.AllowedSections.Count()); } @@ -780,21 +780,21 @@ namespace Umbraco.Tests.Integration.Services Alias = "Group2", Name = "Group 2" }; - _userService.Save(userGroup1); - _userService.Save(userGroup2); + UserService.Save(userGroup1); + UserService.Save(userGroup2); //adds some allowed sections userGroup1.AddAllowedSection("test"); userGroup2.AddAllowedSection("test"); - _userService.Save(userGroup1); - _userService.Save(userGroup2); + UserService.Save(userGroup1); + UserService.Save(userGroup2); //now clear the section from all users - _userService.DeleteSectionFromAllUserGroups("test"); + UserService.DeleteSectionFromAllUserGroups("test"); // Assert - var result1 = _userService.GetUserGroupById(userGroup1.Id); - var result2 = _userService.GetUserGroupById(userGroup2.Id); + var result1 = UserService.GetUserGroupById(userGroup1.Id); + var result2 = UserService.GetUserGroupById(userGroup2.Id); Assert.IsFalse(result1.AllowedSections.Contains("test")); Assert.IsFalse(result2.AllowedSections.Contains("test")); } @@ -821,14 +821,14 @@ namespace Umbraco.Tests.Integration.Services Alias = "Group3", Name = "Group 3" }; - _userService.Save(userGroup1); - _userService.Save(userGroup2); - _userService.Save(userGroup3); + UserService.Save(userGroup1); + UserService.Save(userGroup2); + UserService.Save(userGroup3); // Assert - var result1 = _userService.GetUserGroupById(userGroup1.Id); - var result2 = _userService.GetUserGroupById(userGroup2.Id); - var result3 = _userService.GetUserGroupById(userGroup3.Id); + var result1 = UserService.GetUserGroupById(userGroup1.Id); + var result2 = UserService.GetUserGroupById(userGroup2.Id); + var result3 = UserService.GetUserGroupById(userGroup3.Id); Assert.IsTrue(result1.AllowedSections.Contains("test")); Assert.IsTrue(result2.AllowedSections.Contains("test")); Assert.IsFalse(result3.AllowedSections.Contains("test")); @@ -837,13 +837,13 @@ namespace Umbraco.Tests.Integration.Services foreach (var userGroup in new[] { userGroup1, userGroup2, userGroup3 }) { userGroup.AddAllowedSection("test"); - _userService.Save(userGroup); + UserService.Save(userGroup); } // Assert - result1 = _userService.GetUserGroupById(userGroup1.Id); - result2 = _userService.GetUserGroupById(userGroup2.Id); - result3 = _userService.GetUserGroupById(userGroup3.Id); + result1 = UserService.GetUserGroupById(userGroup1.Id); + result2 = UserService.GetUserGroupById(userGroup2.Id); + result3 = UserService.GetUserGroupById(userGroup3.Id); Assert.IsTrue(result1.AllowedSections.Contains("test")); Assert.IsTrue(result2.AllowedSections.Contains("test")); Assert.IsTrue(result3.AllowedSections.Contains("test")); @@ -853,39 +853,39 @@ namespace Umbraco.Tests.Integration.Services public void Cannot_Create_User_With_Empty_Username() { // Act & Assert - Assert.Throws(() => _userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io")); + Assert.Throws(() => UserService.CreateUserWithIdentity(string.Empty, "john@umbraco.io")); } [Test] public void Cannot_Save_User_With_Empty_Username() { // Arrange - var user = _userService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); + var user = UserService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); user.Username = string.Empty; // Act & Assert - Assert.Throws(() => _userService.Save(user)); + Assert.Throws(() => UserService.Save(user)); } [Test] public void Cannot_Save_User_With_Empty_Name() { // Arrange - var user = _userService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); + var user = UserService.CreateUserWithIdentity("John Doe", "john@umbraco.io"); user.Name = string.Empty; // Act & Assert - Assert.Throws(() => _userService.Save(user)); + Assert.Throws(() => UserService.Save(user)); } [Test] public void Get_By_Profile_Username() { // Arrange - var user = _userService.CreateUserWithIdentity("test1", "test1@test.com"); + var user = UserService.CreateUserWithIdentity("test1", "test1@test.com"); // Act - var profile = _userService.GetProfileByUserName(user.Username); + var profile = UserService.GetProfileByUserName(user.Username); // Assert Assert.IsNotNull(profile); @@ -897,10 +897,10 @@ namespace Umbraco.Tests.Integration.Services public void Get_By_Profile_Id() { // Arrange - var user = _userService.CreateUserWithIdentity("test1", "test1@test.com"); + var user = UserService.CreateUserWithIdentity("test1", "test1@test.com"); // Act - var profile = _userService.GetProfileById((int)user.Id); + var profile = UserService.GetProfileById((int)user.Id); // Assert Assert.IsNotNull(profile); @@ -911,7 +911,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void Get_By_Profile_Id_Must_Return_Null_If_User_Does_Not_Exist() { - var profile = _userService.GetProfileById(42); + var profile = UserService.GetProfileById(42); // Assert Assert.IsNull(profile); @@ -920,7 +920,7 @@ namespace Umbraco.Tests.Integration.Services [Test] public void GetProfilesById_Must_Return_Empty_If_User_Does_Not_Exist() { - var profiles = _userService.GetProfilesById(42); + var profiles = UserService.GetProfilesById(42); // Assert CollectionAssert.IsEmpty(profiles); @@ -934,7 +934,7 @@ namespace Umbraco.Tests.Integration.Services // Act - var updatedItem = (User)_userService.GetByUsername(originalUser.Username); + var updatedItem = (User)UserService.GetByUsername(originalUser.Username); // Assert Assert.IsNotNull(updatedItem); @@ -962,7 +962,7 @@ namespace Umbraco.Tests.Integration.Services CreateTestUsers(startContentItems.Select(x => x.Id).ToArray(), testUserGroup, 3); - var usersInGroup = _userService.GetAllInGroup(userGroupId); + var usersInGroup = UserService.GetAllInGroup(userGroupId); foreach (var user in usersInGroup) Assert.AreEqual(user.StartContentIds.Length, startContentItems.Length); @@ -972,14 +972,14 @@ namespace Umbraco.Tests.Integration.Services { var contentType = MockedContentTypes.CreateSimpleContentType(); - _contentTypeService.Save(contentType); + ContentTypeService.Save(contentType); var startContentItems = new List(); for (var i = 0; i < numberToCreate; i++) startContentItems.Add(MockedContent.CreateSimpleContent(contentType)); - _contentService.Save(startContentItems); + ContentService.Save(startContentItems); return startContentItems.ToArray(); } @@ -1021,11 +1021,11 @@ namespace Umbraco.Tests.Integration.Services { userGroup = CreateTestUserGroup(); - var user = _userService.CreateUserWithIdentity("test1", "test1@test.com"); + var user = UserService.CreateUserWithIdentity("test1", "test1@test.com"); user.AddGroup(userGroup.ToReadOnlyGroup()); - _userService.Save(user); + UserService.Save(user); return user; } @@ -1036,13 +1036,13 @@ namespace Umbraco.Tests.Integration.Services for (var i = 0; i < numberToCreate; i++) { - var user = _userService.CreateUserWithIdentity($"test{i}", $"test{i}@test.com"); + var user = UserService.CreateUserWithIdentity($"test{i}", $"test{i}@test.com"); user.AddGroup(userGroup.ToReadOnlyGroup()); var updateable = (User)user; updateable.StartContentIds = startContentIds; - _userService.Save(user); + UserService.Save(user); users.Add(user); } @@ -1059,7 +1059,7 @@ namespace Umbraco.Tests.Integration.Services .WithAllowedSections(new[] { "content", "media" }) .Build(); - _userService.Save(userGroup); + UserService.Save(userGroup); return (UserGroup)userGroup; } From da5f9e7520651725c01776a830c96df03766ab5d Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 13:02:29 +0200 Subject: [PATCH 26/36] Migrate MacroParserTests While the namespace is Umbraco.Web.Macros the implementation is in Umbraco.Infrastructure assembly, so I assume it has been migrated. --- .../Umbraco.Web.Common}/Macros/MacroParserTests.cs | 0 src/Umbraco.Tests/Umbraco.Tests.csproj | 1 - 2 files changed, 1 deletion(-) rename src/{Umbraco.Tests => Umbraco.Tests.UnitTests/Umbraco.Web.Common}/Macros/MacroParserTests.cs (100%) diff --git a/src/Umbraco.Tests/Macros/MacroParserTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Macros/MacroParserTests.cs similarity index 100% rename from src/Umbraco.Tests/Macros/MacroParserTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Macros/MacroParserTests.cs diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 1b3361cf76..d0082fdee1 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -244,7 +244,6 @@ - From 65bd5ea3ef54e1e201768b168d7ee3e7e2cfeb95 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 13:11:44 +0200 Subject: [PATCH 27/36] Move AngularIntegrationTests They all say they belong to Web but their implementations are in Core/Infrastructure/Backoffice, so I assume they belong in the new test suite --- .../AngularIntegration/ContentModelSerializationTests.cs | 0 .../AngularIntegration/JsInitializationTests.cs | 0 .../AngularIntegration/ServerVariablesParserTests.cs | 2 -- src/Umbraco.Tests/Umbraco.Tests.csproj | 3 --- 4 files changed, 5 deletions(-) rename src/{Umbraco.Tests/Web => Umbraco.Tests.UnitTests/Umbraco.Web.Common}/AngularIntegration/ContentModelSerializationTests.cs (100%) rename src/{Umbraco.Tests/Web => Umbraco.Tests.UnitTests/Umbraco.Web.Common}/AngularIntegration/JsInitializationTests.cs (100%) rename src/{Umbraco.Tests/Web => Umbraco.Tests.UnitTests/Umbraco.Web.Common}/AngularIntegration/ServerVariablesParserTests.cs (99%) diff --git a/src/Umbraco.Tests/Web/AngularIntegration/ContentModelSerializationTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs similarity index 100% rename from src/Umbraco.Tests/Web/AngularIntegration/ContentModelSerializationTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs diff --git a/src/Umbraco.Tests/Web/AngularIntegration/JsInitializationTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/JsInitializationTests.cs similarity index 100% rename from src/Umbraco.Tests/Web/AngularIntegration/JsInitializationTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/JsInitializationTests.cs diff --git a/src/Umbraco.Tests/Web/AngularIntegration/ServerVariablesParserTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ServerVariablesParserTests.cs similarity index 99% rename from src/Umbraco.Tests/Web/AngularIntegration/ServerVariablesParserTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ServerVariablesParserTests.cs index 74ec6e0034..b0eba4c382 100644 --- a/src/Umbraco.Tests/Web/AngularIntegration/ServerVariablesParserTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ServerVariablesParserTests.cs @@ -8,8 +8,6 @@ namespace Umbraco.Tests.Web.AngularIntegration [TestFixture] public class ServerVariablesParserTests { - - [Test] public void Parse() { diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index d0082fdee1..621737a14f 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -203,9 +203,6 @@ - - - From 8e48f2cc3179e18d156417bce88940af995b1c72 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 6 Oct 2020 13:24:32 +0200 Subject: [PATCH 28/36] Further updates from PR comments and additional use of test model builders. --- .../Services/MacroServiceTests.cs | 4 +- .../UserEditorAuthorizationHelperTests.cs | 134 ++++++++---------- .../Controllers/ContentControllerUnitTests.cs | 4 +- .../Controllers/MediaControllerUnitTests.cs | 4 +- ...terAllowedOutgoingContentAttributeTests.cs | 9 +- 5 files changed, 67 insertions(+), 88 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index 2064365cbb..4f533df188 100644 --- a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -25,10 +25,8 @@ namespace Umbraco.Tests.Integration.Services private MacroService MacroService => (MacroService)GetRequiredService(); [SetUp] - public override void Setup() + public void SetupTest() { - base.Setup(); - var sp = ScopeProvider; using (var scope = sp.CreateScope()) { diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelperTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelperTests.cs index bbb0f1b3e3..2fd0c7b8ea 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelperTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Editors/UserEditorAuthorizationHelperTests.cs @@ -7,6 +7,8 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; +using Umbraco.Tests.Common.Builders; +using Umbraco.Tests.Common.Builders.Extensions; using Umbraco.Web.Editors; namespace Umbraco.Tests.Web.Controllers @@ -17,8 +19,8 @@ namespace Umbraco.Tests.Web.Controllers [Test] public void Admin_Is_Authorized() { - var currentUser = GetAdminUser(); - var savingUser = GetUserMock(); + var currentUser = CreateAdminUser(); + var savingUser = CreateUser(); var contentService = new Mock(); var mediaService = new Mock(); @@ -31,7 +33,7 @@ namespace Umbraco.Tests.Web.Controllers userService.Object, entityService.Object); - var result = authHelper.IsAuthorized(currentUser, savingUser.Object, new int[0], new int[0], new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new int[0], new string[0]); Assert.IsTrue(result.Success); } @@ -39,8 +41,8 @@ namespace Umbraco.Tests.Web.Controllers [Test] public void Non_Admin_Cannot_Save_Admin() { - var currentUser = GetUserMock(); - var savingUser = GetAdminUser(); + var currentUser = CreateUser(); + var savingUser = CreateAdminUser(); var contentService = new Mock(); var mediaService = new Mock(); @@ -53,7 +55,7 @@ namespace Umbraco.Tests.Web.Controllers userService.Object, entityService.Object); - var result = authHelper.IsAuthorized(currentUser.Object, savingUser, new int[0], new int[0], new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new int[0], new string[0]); Assert.IsFalse(result.Success); } @@ -61,12 +63,8 @@ namespace Umbraco.Tests.Web.Controllers [Test] public void Cannot_Grant_Group_Membership_Without_Being_A_Member() { - var currentUser = GetUserMock(); - currentUser.Setup(x => x.Groups).Returns(new[] - { - new ReadOnlyUserGroup(1, "Test", "icon-user", null, null, "test", new string[0], new string[0]) - }); - var savingUser = GetUserMock(); + var currentUser = CreateUser(withGroup: true); + var savingUser = CreateUser(); var contentService = new Mock(); var mediaService = new Mock(); @@ -79,7 +77,7 @@ namespace Umbraco.Tests.Web.Controllers userService.Object, entityService.Object); - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new int[0], new[] {"FunGroup"}); + var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new int[0], new[] {"FunGroup"}); Assert.IsFalse(result.Success); } @@ -87,12 +85,8 @@ namespace Umbraco.Tests.Web.Controllers [Test] public void Can_Grant_Group_Membership_With_Being_A_Member() { - var currentUser = GetUserMock(); - currentUser.Setup(x => x.Groups).Returns(new[] - { - new ReadOnlyUserGroup(1, "Test", "icon-user", null, null, "test", new string[0], new string[0]) - }); - var savingUser = GetUserMock(); + var currentUser = CreateUser(withGroup: true); + var savingUser = CreateUser(); var contentService = new Mock(); var mediaService = new Mock(); @@ -105,7 +99,7 @@ namespace Umbraco.Tests.Web.Controllers userService.Object, entityService.Object); - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new int[0], new[] { "test" }); + var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new int[0], new[] { "test" }); Assert.IsTrue(result.Success); } @@ -121,10 +115,8 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = GetUserMock(); - currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = GetUserMock(); - savingUser.Setup(x => x.StartContentIds).Returns(new[] { 1234 }); + var currentUser = CreateUser(startContentIds: new[] { 9876 }); + var savingUser = CreateUser(startContentIds: new[] { 1234 }); var contentService = new Mock(); contentService.Setup(x => x.GetById(It.IsAny())) @@ -145,7 +137,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Object); //adding 5555 which currentUser has access to since it's a child of 9876 ... adding is still ok even though currentUser doesn't have access to 1234 - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new[] { 1234, 5555 }, new int[0], new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new[] { 1234, 5555 }, new int[0], new string[0]); Assert.IsTrue(result.Success); } @@ -161,10 +153,8 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = GetUserMock(); - currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = GetUserMock(); - savingUser.Setup(x => x.StartContentIds).Returns(new[] { 1234, 4567 }); + var currentUser = CreateUser(startContentIds: new[] { 9876 }); + var savingUser = CreateUser(startContentIds: new[] { 1234, 4567 }); var contentService = new Mock(); contentService.Setup(x => x.GetById(It.IsAny())) @@ -185,7 +175,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Object); //removing 4567 start node even though currentUser doesn't have acces to it ... removing is ok - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new[] { 1234 }, new int[0], new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new[] { 1234 }, new int[0], new string[0]); Assert.IsTrue(result.Success); } @@ -201,9 +191,8 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = GetUserMock(); - currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = GetUserMock(); + var currentUser = CreateUser(startContentIds: new[] { 9876 }); + var savingUser = CreateUser(); var contentService = new Mock(); contentService.Setup(x => x.GetById(It.IsAny())) @@ -224,7 +213,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Object); //adding 1234 but currentUser doesn't have access to it ... nope - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new []{1234}, new int[0], new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new []{1234}, new int[0], new string[0]); Assert.IsFalse(result.Success); } @@ -240,9 +229,8 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = GetUserMock(); - currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = GetUserMock(); + var currentUser = CreateUser(startContentIds: new[] { 9876 }); + var savingUser = CreateUser(); var contentService = new Mock(); contentService.Setup(x => x.GetById(It.IsAny())) @@ -263,7 +251,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Object); //adding 5555 which currentUser has access to since it's a child of 9876 ... ok - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new[] { 5555 }, new int[0], new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new[] { 5555 }, new int[0], new string[0]); Assert.IsTrue(result.Success); } @@ -280,9 +268,8 @@ namespace Umbraco.Tests.Web.Controllers }; - var currentUser = GetUserMock(); - currentUser.Setup(x => x.StartContentIds).Returns(new[] { 9876 }); - var savingUser = GetUserMock(); + var currentUser = CreateUser(startMediaIds: new[] { 9876 }); + var savingUser = CreateUser(); var contentService = new Mock(); var mediaService = new Mock(); @@ -303,7 +290,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Object); //adding 1234 but currentUser doesn't have access to it ... nope - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new[] {1234}, new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new[] {1234}, new string[0]); Assert.IsFalse(result.Success); } @@ -319,9 +306,8 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = GetUserMock(); - currentUser.Setup(x => x.StartMediaIds).Returns(new[] { 9876 }); - var savingUser = GetUserMock(); + var currentUser = CreateUser(startMediaIds: new[] { 9876 }); + var savingUser = CreateUser(); var contentService = new Mock(); var mediaService = new Mock(); @@ -342,7 +328,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Object); //adding 5555 which currentUser has access to since it's a child of 9876 ... ok - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new[] { 5555 }, new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new[] { 5555 }, new string[0]); Assert.IsTrue(result.Success); } @@ -358,10 +344,8 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = GetUserMock(); - currentUser.Setup(x => x.StartMediaIds).Returns(new[] { 9876 }); - var savingUser = GetUserMock(); - savingUser.Setup(x => x.StartMediaIds).Returns(new[] { 1234 }); + var currentUser = CreateUser(startMediaIds: new[] { 9876 }); + var savingUser = CreateUser(startMediaIds: new[] { 1234 }); var contentService = new Mock(); var mediaService = new Mock(); @@ -382,7 +366,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Object); //adding 5555 which currentUser has access to since it's a child of 9876 ... adding is still ok even though currentUser doesn't have access to 1234 - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new[] { 1234, 5555 }, new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new[] { 1234, 5555 }, new string[0]); Assert.IsTrue(result.Success); } @@ -398,10 +382,8 @@ namespace Umbraco.Tests.Web.Controllers {4567, "-1,4567"}, }; - var currentUser = GetUserMock(); - currentUser.Setup(x => x.StartMediaIds).Returns(new[] { 9876 }); - var savingUser = GetUserMock(); - savingUser.Setup(x => x.StartMediaIds).Returns(new[] { 1234, 4567 }); + var currentUser = CreateUser(startMediaIds: new[] { 9876 }); + var savingUser = CreateUser(startMediaIds: new[] { 1234, 4567 }); var contentService = new Mock(); var mediaService = new Mock(); @@ -422,33 +404,37 @@ namespace Umbraco.Tests.Web.Controllers entityService.Object); //removing 4567 start node even though currentUser doesn't have acces to it ... removing is ok - var result = authHelper.IsAuthorized(currentUser.Object, savingUser.Object, new int[0], new[] { 1234 }, new string[0]); + var result = authHelper.IsAuthorized(currentUser, savingUser, new int[0], new[] { 1234 }, new string[0]); Assert.IsTrue(result.Success); } - /// - /// Returns a and ensures that the ToUserCache and FromUserCache methods are mapped correctly for - /// dealing with start node caches - /// - /// - private static Mock GetUserMock() + private static IUser CreateUser(bool withGroup = false, int[] startContentIds = null, int[] startMediaIds = null) { - var userCache = new Dictionary(); - var userMock = new Mock(); - userMock.Setup(x => x.FromUserCache(It.IsAny())).Returns((string key) => userCache.TryGetValue(key, out var val) ? val is int[] iVal ? iVal : null : null); - userMock.Setup(x => x.ToUserCache(It.IsAny(), It.IsAny())).Callback((string key, int[] val) => userCache[key] = val); - return userMock; + var builder = new UserBuilder() + .WithStartContentIds(startContentIds != null ? startContentIds : new int[0]) + .WithStartMediaIds(startMediaIds != null ? startMediaIds : new int[0]); + if (withGroup) + { + builder = (UserBuilder)builder + .AddUserGroup() + .WithName("Test") + .WithAlias("test") + .Done(); + } + + return builder.Build(); } - private IUser GetAdminUser() + private static IUser CreateAdminUser() { - var admin = GetUserMock(); - admin.Setup(x => x.Groups).Returns(new[] - { - new ReadOnlyUserGroup(1, "Admin", "icon-user", null, null, Constants.Security.AdminGroupAlias, new string[0], new string[0]) - }); - return admin.Object; + return new UserBuilder() + .AddUserGroup() + .WithId(1) + .WithName("Admin") + .WithAlias(Constants.Security.AdminGroupAlias) + .Done() + .Build(); } } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerUnitTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerUnitTests.cs index 14d888470f..2f76db452a 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerUnitTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/ContentControllerUnitTests.cs @@ -334,11 +334,11 @@ namespace Umbraco.Tests.Web.Controllers Assert.AreEqual(ContentPermissionsHelper.ContentAccess.Denied, result); } - private IUser CreateUser(int id = 0, int startContentId = -1, bool withUserGroup = true) + private IUser CreateUser(int id = 0, int? startContentId = null, bool withUserGroup = true) { var builder = new UserBuilder() .WithId(id) - .WithStartContentIds(startContentId == -1 ? new int[0] : new[] { startContentId }); + .WithStartContentIds(startContentId.HasValue ? new[] { startContentId.Value } : new int[0]); if (withUserGroup) { builder = builder diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MediaControllerUnitTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MediaControllerUnitTests.cs index 124c934b2f..91305e463c 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MediaControllerUnitTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MediaControllerUnitTests.cs @@ -149,11 +149,11 @@ namespace Umbraco.Tests.Web.Controllers Assert.IsFalse(result); } - private IUser CreateUser(int id = 0, int startMediaId = -1) + private IUser CreateUser(int id = 0, int? startMediaId = null) { return new UserBuilder() .WithId(id) - .WithStartMediaIds(new[] { startMediaId }) + .WithStartMediaIds(startMediaId.HasValue ? new[] { startMediaId.Value } : new int[0]) .AddUserGroup() .WithId(1) .WithName("admin") diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingContentAttributeTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingContentAttributeTests.cs index 6717b0e046..5c186c890c 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingContentAttributeTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Filters/FilterAllowedOutgoingContentAttributeTests.cs @@ -148,16 +148,11 @@ namespace Umbraco.Tests.Web.Controllers Assert.AreEqual(3, list.ElementAt(2).Id); } - private IUser CreateUser(int id = 0, int startContentId = -1) + private IUser CreateUser(int id = 0, int? startContentId = null) { return new UserBuilder() .WithId(id) - .WithStartContentIds(new[] { startContentId }) - .AddUserGroup() - .WithId(1) - .WithName("admin") - .WithAlias("admin") - .Done() + .WithStartContentIds(startContentId.HasValue ? new[] { startContentId.Value } : new int[0]) .Build(); } From 32b43feac42325c318cb26b9036e008a848d780a Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 13:45:21 +0200 Subject: [PATCH 29/36] Remove unused imports --- .../Packaging/CreatedPackagesRepositoryTests.cs | 1 - .../Services/ContentServicePublishBranchTests.cs | 2 -- .../Services/EntityServiceTests.cs | 1 - .../Services/MacroServiceTests.cs | 1 - .../Umbraco.Core/Packaging/PackageExtractionTests.cs | 7 +------ .../Umbraco.Core/Services/LocalizedTextServiceTests.cs | 3 --- .../AngularIntegration/JsInitializationTests.cs | 3 +-- .../Umbraco.Web.Common/Macros/MacroParserTests.cs | 1 - 8 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs index f95a7be093..c08913298b 100644 --- a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; -using System.Threading.Tasks; using System.Xml.Linq; using NUnit.Framework; using Umbraco.Core; diff --git a/src/Umbraco.Tests.Integration/Services/ContentServicePublishBranchTests.cs b/src/Umbraco.Tests.Integration/Services/ContentServicePublishBranchTests.cs index ba0f033b5f..9e45e40c42 100644 --- a/src/Umbraco.Tests.Integration/Services/ContentServicePublishBranchTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ContentServicePublishBranchTests.cs @@ -6,9 +6,7 @@ using Umbraco.Core; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Models; using Umbraco.Core.Services; -using Umbraco.Tests.Common.Builders; using Umbraco.Tests.Integration.Testing; -using Umbraco.Tests.TestHelpers; using Umbraco.Tests.Testing; // ReSharper disable CommentTypo diff --git a/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs b/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs index fee2f07469..60bb9a7c03 100644 --- a/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using System.Threading.Tasks; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Configuration.Models; diff --git a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index e8d3518367..2580f32b14 100644 --- a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using System.Threading; -using System.Threading.Tasks; using Moq; using NUnit.Framework; using Umbraco.Core.Cache; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs index d9dcf1bfe9..509d9639e3 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs @@ -1,14 +1,9 @@ -using System; -using System.IO; +using System.IO; using System.Linq; using Moq; using NUnit.Framework; -using Umbraco.Core.Composing; using Umbraco.Core.Hosting; -using Umbraco.Core.IO; using Umbraco.Core.Packaging; -using Umbraco.Tests.TestHelpers; -using Umbraco.Tests.UnitTests.AutoFixture; namespace Umbraco.Tests.Packaging { diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/LocalizedTextServiceTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/LocalizedTextServiceTests.cs index 2217028c64..126ca1821e 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/LocalizedTextServiceTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Services/LocalizedTextServiceTests.cs @@ -2,13 +2,10 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Xml.Linq; using Moq; using NUnit.Framework; using Umbraco.Core.Logging; -using Umbraco.Core.Services; using Umbraco.Core.Services.Implement; namespace Umbraco.Tests.Services diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/JsInitializationTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/JsInitializationTests.cs index 90355429c4..f081d0f203 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/JsInitializationTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/JsInitializationTests.cs @@ -1,5 +1,4 @@ -using System.Linq; -using NUnit.Framework; +using NUnit.Framework; using Umbraco.Core; using Umbraco.Web.WebAssets; diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Macros/MacroParserTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Macros/MacroParserTests.cs index 898ae4b20e..1d9e9012e0 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Macros/MacroParserTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/Macros/MacroParserTests.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using NUnit.Framework; -using Umbraco.Core.Macros; using Umbraco.Web.Macros; namespace Umbraco.Tests.Macros From c7aad452eeecda0b753d2d22a43e8503d43f3631 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 14:16:29 +0200 Subject: [PATCH 30/36] Clean --- .../CreatedPackagesRepositoryTests.cs | 5 ++-- .../Services/CachedDataTypeServiceTests.cs | 2 +- .../Services/MacroServiceTests.cs | 2 -- .../Testing/UmbracoIntegrationTest.cs | 26 ++++++------------- .../Packaging/PackageExtractionTests.cs | 4 +-- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs index c08913298b..5bd401a5d4 100644 --- a/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs +++ b/src/Umbraco.Tests.Integration/Packaging/CreatedPackagesRepositoryTests.cs @@ -29,12 +29,11 @@ namespace Umbraco.Tests.Packaging _testBaseFolder = Guid.NewGuid(); } - public override void TearDown() + [TearDown] + public void DeleteTestFolder() { - base.TearDown(); //clear out files/folders Directory.Delete(HostingEnvironment.MapPathContentRoot("~/" + _testBaseFolder), true); - } private IContentService ContentService => GetRequiredService(); diff --git a/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs b/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs index 7ff14b4697..40144cd55c 100644 --- a/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Services [Test] public void DataTypeService_Can_Get_All() { - var dataTypeService = (DataTypeService) GetRequiredService(); + var dataTypeService = GetRequiredService(); IDataType dataType = new DataType(new LabelPropertyEditor(Logger, IOHelper, DataTypeService, LocalizedTextService, LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; dataTypeService.Save(dataType); diff --git a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index 2580f32b14..3dcab4c746 100644 --- a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -29,8 +29,6 @@ namespace Umbraco.Tests.Services public void CreateTestData() { - // base.CreateTestData(); - var provider = ScopeProvider; using (var scope = provider.CreateScope()) { diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index fb57a543ac..94c14ce2f3 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -46,7 +46,6 @@ namespace Umbraco.Tests.Integration.Testing [NonParallelizable] public abstract class UmbracoIntegrationTest { - public static LightInjectContainer CreateUmbracoContainer(out UmbracoServiceProviderFactory serviceProviderFactory) { var container = UmbracoServiceProviderFactory.CreateServiceContainer(); @@ -247,13 +246,12 @@ namespace Umbraco.Tests.Integration.Testing CustomTestSetup(services); } - public virtual void Configure(IApplicationBuilder app) { Services.GetRequiredService().EnsureBackofficeSecurity(); Services.GetRequiredService().EnsureUmbracoContext(); - - // get the currently set ptions + + // get the currently set options var testOptions = TestOptionAttributeBase.GetTestOptions(); if (testOptions.Boot) { @@ -262,7 +260,7 @@ namespace Umbraco.Tests.Integration.Testing } #endregion - + #region LocalDb @@ -347,10 +345,7 @@ namespace Umbraco.Tests.Integration.Testing var newSchemaDbId = db.AttachSchema(); // Add teardown callback - OnTestTearDown(() => - { - db.Detach(newSchemaDbId); - }); + OnTestTearDown(() => db.Detach(newSchemaDbId)); // We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings if (!databaseFactory.Configured) @@ -374,21 +369,16 @@ namespace Umbraco.Tests.Integration.Testing break; case UmbracoTestOptions.Database.NewSchemaPerFixture: - // If we try to AttachSchema before the old schema has been detached - // the process will be blocked since readyQueue remain empty - // Probably because the DB is blocked because it hasn't been detached - // Also if we attach a new schema for every test isn't it just essentially - // the same as NewSchemaPerTest? + // Only attach schema once per fixture + // Doing it more than once will block the process since the old db hasn't been detached + // and it would be the same as NewSchemaPerTest even if it didn't block if (FirstTestInFixture) { // New DB + Schema var newSchemaFixtureDbId = db.AttachSchema(); // Add teardown callback - OnFixtureTearDown(() => - { - db.Detach(newSchemaFixtureDbId); - }); + OnFixtureTearDown(() => db.Detach(newSchemaFixtureDbId)); } // We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs index 509d9639e3..ad76b060ce 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Packaging/PackageExtractionTests.cs @@ -16,9 +16,7 @@ namespace Umbraco.Tests.Packaging { const string testPackagesDirName = "Umbraco.Core\\Packaging\\Packages"; var testDir = TestContext.CurrentContext.TestDirectory.Split("bin")[0]; - var hostingEnvironment = Mock.Of( - x => x.ToAbsolute(It.IsAny()) == "/" && x.ApplicationPhysicalPath == testDir); - var path = Path.Combine(hostingEnvironment.ApplicationPhysicalPath, testPackagesDirName, packageName); + var path = Path.Combine(testDir, testPackagesDirName, packageName); return new FileInfo(path); } From 2d785adfe66564af4186db136668ed3f24b4ec92 Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 14:22:16 +0200 Subject: [PATCH 31/36] Don't get IDataTypeService twice --- .../Services/CachedDataTypeServiceTests.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs b/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs index 40144cd55c..655eaf2393 100644 --- a/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/CachedDataTypeServiceTests.cs @@ -28,15 +28,13 @@ namespace Umbraco.Tests.Services [Test] public void DataTypeService_Can_Get_All() { - var dataTypeService = GetRequiredService(); - IDataType dataType = new DataType(new LabelPropertyEditor(Logger, IOHelper, DataTypeService, LocalizedTextService, LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; - dataTypeService.Save(dataType); + DataTypeService.Save(dataType); //Get all the first time (no cache) - var all = dataTypeService.GetAll(); + var all = DataTypeService.GetAll(); //Get all a second time (with cache) - all = dataTypeService.GetAll(); + all = DataTypeService.GetAll(); Assert.Pass(); } From b233caf9b724fb3b7bcff72ef51ce63803b438db Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 14:35:51 +0200 Subject: [PATCH 32/36] Use EntityService instead of var service in EntityServiceTests It's more descriptive --- .../Services/EntityServiceTests.cs | 155 ++++++------------ 1 file changed, 50 insertions(+), 105 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs b/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs index 60bb9a7c03..2a12df8dcd 100644 --- a/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/EntityServiceTests.cs @@ -68,29 +68,27 @@ namespace Umbraco.Tests.Services root = c1; // make a hierarchy } - var service = EntityService; - long total; - var entities = service.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 0, 6, out total).ToArray(); + var entities = EntityService.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 0, 6, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(6)); Assert.That(total, Is.EqualTo(10)); Assert.AreEqual(ids[0], entities[0].Id); - entities = service.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 1, 6, out total).ToArray(); + entities = EntityService.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 1, 6, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(4)); Assert.That(total, Is.EqualTo(10)); Assert.AreEqual(ids[6], entities[0].Id); //Test ordering direction - entities = service.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 0, 6, out total, + entities = EntityService.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 0, 6, out total, ordering: Ordering.By("Path", Direction.Descending)).ToArray(); Assert.That(entities.Length, Is.EqualTo(6)); Assert.That(total, Is.EqualTo(10)); Assert.AreEqual(ids[ids.Count - 1], entities[0].Id); - entities = service.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 1, 6, out total, + entities = EntityService.GetPagedDescendants(rootId, UmbracoObjectTypes.Document, 1, 6, out total, ordering: Ordering.By("Path", Direction.Descending)).ToArray(); Assert.That(entities.Length, Is.EqualTo(4)); Assert.That(total, Is.EqualTo(10)); @@ -113,29 +111,27 @@ namespace Umbraco.Tests.Services ids.Add(c1.Id); } - var service = EntityService; - long total; - var entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 0, 6, out total).ToArray(); + var entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 0, 6, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(6)); Assert.That(total, Is.EqualTo(10)); Assert.AreEqual(ids[0], entities[0].Id); - entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 1, 6, out total).ToArray(); + entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 1, 6, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(4)); Assert.That(total, Is.EqualTo(10)); Assert.AreEqual(ids[6], entities[0].Id); //Test ordering direction - entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 0, 6, out total, + entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 0, 6, out total, ordering: Ordering.By("SortOrder", Direction.Descending)).ToArray(); Assert.That(entities.Length, Is.EqualTo(6)); Assert.That(total, Is.EqualTo(10)); Assert.AreEqual(ids[ids.Count - 1], entities[0].Id); - entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 1, 6, out total, + entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Document, 1, 6, out total, ordering: Ordering.By("SortOrder", Direction.Descending)).ToArray(); Assert.That(entities.Length, Is.EqualTo(4)); Assert.That(total, Is.EqualTo(10)); @@ -164,13 +160,11 @@ namespace Umbraco.Tests.Services } } - var service = EntityService; - long total; - var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 31, out total).ToArray(); + var entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 31, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(31)); Assert.That(total, Is.EqualTo(60)); - entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 1, 31, out total).ToArray(); + entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 1, 31, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(29)); Assert.That(total, Is.EqualTo(60)); } @@ -205,11 +199,9 @@ namespace Umbraco.Tests.Services ContentService.MoveToRecycleBin(content); } - var service = EntityService; - long total; //search at root to see if it returns recycled - var entities = service.GetPagedDescendants(-1, UmbracoObjectTypes.Document, 0, 1000, out total) + var entities = EntityService.GetPagedDescendants(-1, UmbracoObjectTypes.Document, 0, 1000, out total) .Select(x => x.Id) .ToArray(); @@ -249,11 +241,9 @@ namespace Umbraco.Tests.Services ContentService.MoveToRecycleBin(content); } - var service = EntityService; - long total; //search at root to see if it returns recycled - var entities = service.GetPagedDescendants(UmbracoObjectTypes.Document, 0, 1000, out total, includeTrashed: false) + var entities = EntityService.GetPagedDescendants(UmbracoObjectTypes.Document, 0, 1000, out total, includeTrashed: false) .Select(x => x.Id) .ToArray(); @@ -283,14 +273,12 @@ namespace Umbraco.Tests.Services } } - var service = EntityService; - long total; - var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 10, out total, + var entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 10, out total, filter: SqlContext.Query().Where(x => x.Name.Contains("ssss"))).ToArray(); Assert.That(entities.Length, Is.EqualTo(10)); Assert.That(total, Is.EqualTo(10)); - entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 50, out total, + entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Document, 0, 50, out total, filter: SqlContext.Query().Where(x => x.Name.Contains("tttt"))).ToArray(); Assert.That(entities.Length, Is.EqualTo(50)); Assert.That(total, Is.EqualTo(50)); @@ -310,13 +298,11 @@ namespace Umbraco.Tests.Services MediaService.Save(c1); } - var service = EntityService; - long total; - var entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 0, 6, out total).ToArray(); + var entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 0, 6, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(6)); Assert.That(total, Is.EqualTo(10)); - entities = service.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 1, 6, out total).ToArray(); + entities = EntityService.GetPagedChildren(root.Id, UmbracoObjectTypes.Media, 1, 6, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(4)); Assert.That(total, Is.EqualTo(10)); } @@ -344,13 +330,11 @@ namespace Umbraco.Tests.Services } } - var service = EntityService; - long total; - var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 31, out total).ToArray(); + var entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 31, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(31)); Assert.That(total, Is.EqualTo(60)); - entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 1, 31, out total).ToArray(); + entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 1, 31, out total).ToArray(); Assert.That(entities.Length, Is.EqualTo(29)); Assert.That(total, Is.EqualTo(60)); } @@ -386,11 +370,9 @@ namespace Umbraco.Tests.Services MediaService.MoveToRecycleBin(content); } - var service = EntityService; - long total; //search at root to see if it returns recycled - var entities = service.GetPagedDescendants(-1, UmbracoObjectTypes.Media, 0, 1000, out total) + var entities = EntityService.GetPagedDescendants(-1, UmbracoObjectTypes.Media, 0, 1000, out total) .Select(x => x.Id) .ToArray(); @@ -431,11 +413,9 @@ namespace Umbraco.Tests.Services MediaService.MoveToRecycleBin(content); } - var service = EntityService; - long total; //search at root to see if it returns recycled - var entities = service.GetPagedDescendants(UmbracoObjectTypes.Media, 0, 1000, out total, includeTrashed: false) + var entities = EntityService.GetPagedDescendants(UmbracoObjectTypes.Media, 0, 1000, out total, includeTrashed: false) .Select(x => x.Id) .ToArray(); @@ -468,14 +448,12 @@ namespace Umbraco.Tests.Services } } - var service = EntityService; - long total; - var entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 10, out total, + var entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 10, out total, filter: SqlContext.Query().Where(x => x.Name.Contains("ssss"))).ToArray(); Assert.That(entities.Length, Is.EqualTo(10)); Assert.That(total, Is.EqualTo(10)); - entities = service.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 50, out total, + entities = EntityService.GetPagedDescendants(root.Id, UmbracoObjectTypes.Media, 0, 50, out total, filter: SqlContext.Query().Where(x => x.Name.Contains("tttt"))).ToArray(); Assert.That(entities.Length, Is.EqualTo(50)); Assert.That(total, Is.EqualTo(50)); @@ -484,9 +462,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_Content_By_UmbracoObjectTypes() { - var service = EntityService; - - var entities = service.GetAll(UmbracoObjectTypes.Document).ToArray(); + var entities = EntityService.GetAll(UmbracoObjectTypes.Document).ToArray(); Assert.That(entities.Any(), Is.True); Assert.That(entities.Length, Is.EqualTo(4)); @@ -496,10 +472,8 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_Content_By_UmbracoObjectType_Id() { - var service = EntityService; - var objectTypeId = Constants.ObjectTypes.Document; - var entities = service.GetAll(objectTypeId).ToArray(); + var entities = EntityService.GetAll(objectTypeId).ToArray(); Assert.That(entities.Any(), Is.True); Assert.That(entities.Length, Is.EqualTo(4)); @@ -509,9 +483,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_Content_By_Type() { - var service = EntityService; - - var entities = service.GetAll().ToArray(); + var entities = EntityService.GetAll().ToArray(); Assert.That(entities.Any(), Is.True); Assert.That(entities.Length, Is.EqualTo(4)); @@ -521,9 +493,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Child_Content_By_ParentId_And_UmbracoObjectType() { - var service = EntityService; - - var entities = service.GetChildren(-1, UmbracoObjectTypes.Document).ToArray(); + var entities = EntityService.GetChildren(-1, UmbracoObjectTypes.Document).ToArray(); Assert.That(entities.Any(), Is.True); Assert.That(entities.Length, Is.EqualTo(1)); @@ -533,8 +503,6 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Content_By_UmbracoObjectType_With_Variant_Names() { - var service = EntityService; - var alias = "test" + Guid.NewGuid(); var contentType = MockedContentTypes.CreateSimpleContentType(alias, alias, false); contentType.Variations = ContentVariation.Culture; @@ -545,7 +513,7 @@ namespace Umbraco.Tests.Services c1.SetCultureName("Test - ES", _langEs.IsoCode); ContentService.Save(c1); - var result = service.Get(c1.Id, UmbracoObjectTypes.Document); + var result = EntityService.Get(c1.Id, UmbracoObjectTypes.Document); Assert.AreEqual("Test - FR", result.Name); // got name from default culture Assert.IsNotNull(result as IDocumentEntitySlim); var doc = (IDocumentEntitySlim)result; @@ -557,8 +525,6 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Child_Content_By_ParentId_And_UmbracoObjectType_With_Variant_Names() { - var service = EntityService; - var contentType = MockedContentTypes.CreateSimpleContentType("test1", "Test1", false); contentType.Variations = ContentVariation.Culture; ContentTypeService.Save(contentType); @@ -582,7 +548,7 @@ namespace Umbraco.Tests.Services ContentService.Save(c1); } - var entities = service.GetChildren(root.Id, UmbracoObjectTypes.Document).ToArray(); + var entities = EntityService.GetChildren(root.Id, UmbracoObjectTypes.Document).ToArray(); Assert.AreEqual(10, entities.Length); @@ -610,9 +576,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Children_By_ParentId() { - var service = EntityService; - - var entities = service.GetChildren(folderId); + var entities = EntityService.GetChildren(folderId); Assert.That(entities.Any(), Is.True); Assert.That(entities.Count(), Is.EqualTo(3)); @@ -622,9 +586,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Descendants_By_ParentId() { - var service = EntityService; - - var entities = service.GetDescendants(folderId); + var entities = EntityService.GetDescendants(folderId); Assert.That(entities.Any(), Is.True); Assert.That(entities.Count(), Is.EqualTo(4)); @@ -634,19 +596,16 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Throws_When_Getting_All_With_Invalid_Type() { - var service = EntityService; var objectTypeId = Constants.ObjectTypes.ContentItem; - Assert.Throws(() => service.GetAll()); - Assert.Throws(() => service.GetAll(objectTypeId)); + Assert.Throws(() => EntityService.GetAll()); + Assert.Throws(() => EntityService.GetAll(objectTypeId)); } [Test] public void EntityService_Can_Find_All_ContentTypes_By_UmbracoObjectTypes() { - var service = EntityService; - - var entities = service.GetAll(UmbracoObjectTypes.DocumentType).ToArray(); + var entities = EntityService.GetAll(UmbracoObjectTypes.DocumentType).ToArray(); Assert.That(entities.Any(), Is.True); Assert.That(entities.Count(), Is.EqualTo(1)); @@ -655,10 +614,8 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_ContentTypes_By_UmbracoObjectType_Id() { - var service = EntityService; - var objectTypeId = Constants.ObjectTypes.DocumentType; - var entities = service.GetAll(objectTypeId).ToArray(); + var entities = EntityService.GetAll(objectTypeId).ToArray(); Assert.That(entities.Any(), Is.True); Assert.That(entities.Count(), Is.EqualTo(1)); @@ -667,9 +624,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_ContentTypes_By_Type() { - var service = EntityService; - - var entities = service.GetAll().ToArray(); + var entities = EntityService.GetAll().ToArray(); Assert.That(entities.Any(), Is.True); Assert.That(entities.Count(), Is.EqualTo(1)); @@ -678,9 +633,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Find_All_Media_By_UmbracoObjectTypes() { - var service = EntityService; - - var entities = service.GetAll(UmbracoObjectTypes.Media).ToArray(); + var entities = EntityService.GetAll(UmbracoObjectTypes.Media).ToArray(); Assert.That(entities.Any(), Is.True); Assert.That(entities.Length, Is.EqualTo(5)); @@ -695,9 +648,8 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_ObjectType() - { - var service = EntityService; - var mediaObjectType = service.GetObjectType(1031); + { ; + var mediaObjectType = EntityService.GetObjectType(1031); Assert.NotNull(mediaObjectType); Assert.AreEqual(mediaObjectType, UmbracoObjectTypes.MediaType); @@ -706,8 +658,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Key_For_Id_With_Unknown_Type() { - var service = EntityService; - var result = service.GetKey(1052, UmbracoObjectTypes.Unknown); + var result = EntityService.GetKey(1052, UmbracoObjectTypes.Unknown); Assert.IsTrue(result.Success); Assert.AreEqual(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), result.Result); @@ -716,8 +667,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Key_For_Id() { - var service = EntityService; - var result = service.GetKey(1052, UmbracoObjectTypes.DocumentType); + var result = EntityService.GetKey(1052, UmbracoObjectTypes.DocumentType); Assert.IsTrue(result.Success); Assert.AreEqual(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), result.Result); @@ -726,9 +676,8 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Cannot_Get_Key_For_Id_With_Incorrect_Object_Type() { - var service = EntityService; - var result1 = service.GetKey(1052, UmbracoObjectTypes.DocumentType); - var result2 = service.GetKey(1052, UmbracoObjectTypes.MediaType); + var result1 = EntityService.GetKey(1052, UmbracoObjectTypes.DocumentType); + var result2 = EntityService.GetKey(1052, UmbracoObjectTypes.MediaType); Assert.IsTrue(result1.Success); Assert.IsFalse(result2.Success); @@ -737,8 +686,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Id_For_Key_With_Unknown_Type() { - var service = EntityService; - var result = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.Unknown); + var result = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.Unknown); Assert.IsTrue(result.Success); Assert.AreEqual(1052, result.Result); @@ -747,8 +695,7 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Can_Get_Id_For_Key() { - var service = EntityService; - var result = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType); + var result = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType); Assert.IsTrue(result.Success); Assert.AreEqual(1052, result.Result); @@ -757,9 +704,8 @@ namespace Umbraco.Tests.Services [Test] public void EntityService_Cannot_Get_Id_For_Key_With_Incorrect_Object_Type() { - var service = EntityService; - var result1 = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType); - var result2 = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.MediaType); + var result1 = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.DocumentType); + var result2 = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.MediaType); Assert.IsTrue(result1.Success); Assert.IsFalse(result2.Success); @@ -768,25 +714,24 @@ namespace Umbraco.Tests.Services [Test] public void ReserveId() { - var service = EntityService; var guid = Guid.NewGuid(); // can reserve - var reservedId = service.ReserveId(guid); + var reservedId = EntityService.ReserveId(guid); Assert.IsTrue(reservedId > 0); // can get it back - var id = service.GetId(guid, UmbracoObjectTypes.DocumentType); + var id = EntityService.GetId(guid, UmbracoObjectTypes.DocumentType); Assert.IsTrue(id.Success); Assert.AreEqual(reservedId, id.Result); // anything goes - id = service.GetId(guid, UmbracoObjectTypes.Media); + id = EntityService.GetId(guid, UmbracoObjectTypes.Media); Assert.IsTrue(id.Success); Assert.AreEqual(reservedId, id.Result); // a random guid won't work - Assert.IsFalse(service.GetId(Guid.NewGuid(), UmbracoObjectTypes.DocumentType).Success); + Assert.IsFalse(EntityService.GetId(Guid.NewGuid(), UmbracoObjectTypes.DocumentType).Success); } private static bool _isSetup = false; From b28d45cde58edfe5e26622771f6c6e93b9c217ef Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 14:41:10 +0200 Subject: [PATCH 33/36] Use same pattern for getting Services in all tests --- .../Services/ConsentServiceTests.cs | 42 ++++++----- .../Services/DataTypeServiceTests.cs | 19 ++--- .../Services/KeyValueServiceTests.cs | 35 ++++------ .../Services/MacroServiceTests.cs | 70 +++++++------------ 4 files changed, 63 insertions(+), 103 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs b/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs index cfb8303a0d..3cc8666099 100644 --- a/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/ConsentServiceTests.cs @@ -12,14 +12,14 @@ namespace Umbraco.Tests.Services [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)] public class ConsentServiceTests : UmbracoIntegrationTest { + private IConsentService ConsentService => GetRequiredService(); + [Test] public void CanCrudConsent() { - var consentService = GetRequiredService(); - // can register - var consent = consentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted, "no comment"); + var consent = ConsentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted, "no comment"); Assert.AreNotEqual(0, consent.Id); Assert.IsTrue(consent.Current); @@ -33,16 +33,16 @@ namespace Umbraco.Tests.Services // can register more - consentService.RegisterConsent("user/1234", "app1", "do-something-else", ConsentState.Granted, "no comment"); - consentService.RegisterConsent("user/1236", "app1", "do-something", ConsentState.Granted, "no comment"); - consentService.RegisterConsent("user/1237", "app2", "do-something", ConsentState.Granted, "no comment"); + ConsentService.RegisterConsent("user/1234", "app1", "do-something-else", ConsentState.Granted, "no comment"); + ConsentService.RegisterConsent("user/1236", "app1", "do-something", ConsentState.Granted, "no comment"); + ConsentService.RegisterConsent("user/1237", "app2", "do-something", ConsentState.Granted, "no comment"); // can get by source - var consents = consentService.LookupConsent(source: "user/1235").ToArray(); + var consents = ConsentService.LookupConsent(source: "user/1235").ToArray(); Assert.IsEmpty(consents); - consents = consentService.LookupConsent(source: "user/1234").ToArray(); + consents = ConsentService.LookupConsent(source: "user/1234").ToArray(); Assert.AreEqual(2, consents.Length); Assert.IsTrue(consents.All(x => x.Source == "user/1234")); Assert.IsTrue(consents.Any(x => x.Action == "do-something")); @@ -50,23 +50,23 @@ namespace Umbraco.Tests.Services // can get by context - consents = consentService.LookupConsent(context: "app3").ToArray(); + consents = ConsentService.LookupConsent(context: "app3").ToArray(); Assert.IsEmpty(consents); - consents = consentService.LookupConsent(context: "app2").ToArray(); + consents = ConsentService.LookupConsent(context: "app2").ToArray(); Assert.AreEqual(1, consents.Length); - consents = consentService.LookupConsent(context: "app1").ToArray(); + consents = ConsentService.LookupConsent(context: "app1").ToArray(); Assert.AreEqual(3, consents.Length); Assert.IsTrue(consents.Any(x => x.Action == "do-something")); Assert.IsTrue(consents.Any(x => x.Action == "do-something-else")); // can get by action - consents = consentService.LookupConsent(action: "do-whatever").ToArray(); + consents = ConsentService.LookupConsent(action: "do-whatever").ToArray(); Assert.IsEmpty(consents); - consents = consentService.LookupConsent(context: "app1", action: "do-something").ToArray(); + consents = ConsentService.LookupConsent(context: "app1", action: "do-something").ToArray(); Assert.AreEqual(2, consents.Length); Assert.IsTrue(consents.All(x => x.Action == "do-something")); Assert.IsTrue(consents.Any(x => x.Source == "user/1234")); @@ -74,23 +74,23 @@ namespace Umbraco.Tests.Services // can revoke - consent = consentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Revoked, "no comment"); + consent = ConsentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Revoked, "no comment"); - consents = consentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something").ToArray(); + consents = ConsentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something").ToArray(); Assert.AreEqual(1, consents.Length); Assert.IsTrue(consents[0].Current); Assert.AreEqual(ConsentState.Revoked, consents[0].State); // can filter - consents = consentService.LookupConsent(context: "app1", action: "do-", actionStartsWith: true).ToArray(); + consents = ConsentService.LookupConsent(context: "app1", action: "do-", actionStartsWith: true).ToArray(); Assert.AreEqual(3, consents.Length); Assert.IsTrue(consents.All(x => x.Context == "app1")); Assert.IsTrue(consents.All(x => x.Action.StartsWith("do-"))); // can get history - consents = consentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something", includeHistory: true).ToArray(); + consents = ConsentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something", includeHistory: true).ToArray(); Assert.AreEqual(1, consents.Length); Assert.IsTrue(consents[0].Current); Assert.AreEqual(ConsentState.Revoked, consents[0].State); @@ -104,19 +104,17 @@ namespace Umbraco.Tests.Services // cannot be stupid Assert.Throws(() => - consentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted | ConsentState.Revoked, "no comment")); + ConsentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted | ConsentState.Revoked, "no comment")); } [Test] public void CanRegisterConsentWithoutComment() { - var consentService = GetRequiredService(); - // Attept to add consent without a comment - consentService.RegisterConsent("user/1234", "app1", "consentWithoutComment", ConsentState.Granted); + ConsentService.RegisterConsent("user/1234", "app1", "consentWithoutComment", ConsentState.Granted); // Attempt to retrieve the consent we just added without a comment - var consents = consentService.LookupConsent(source: "user/1234", action: "consentWithoutComment").ToArray(); + var consents = ConsentService.LookupConsent(source: "user/1234", action: "consentWithoutComment").ToArray(); // Confirm we got our expected consent record Assert.AreEqual(1, consents.Length); diff --git a/src/Umbraco.Tests.Integration/Services/DataTypeServiceTests.cs b/src/Umbraco.Tests.Integration/Services/DataTypeServiceTests.cs index 0072095771..c124c291e6 100644 --- a/src/Umbraco.Tests.Integration/Services/DataTypeServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/DataTypeServiceTests.cs @@ -28,18 +28,15 @@ namespace Umbraco.Tests.Services [Test] public void DataTypeService_Can_Persist_New_DataTypeDefinition() { - // Arrange - var dataTypeService = DataTypeService; - // Act IDataType dataType = new DataType(new LabelPropertyEditor(Logger, IOHelper, DataTypeService, LocalizedTextService, LocalizationService, ShortStringHelper)) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; - dataTypeService.Save(dataType); + DataTypeService.Save(dataType); // Assert Assert.That(dataType, Is.Not.Null); Assert.That(dataType.HasIdentity, Is.True); - dataType = dataTypeService.GetDataType(dataType.Id); + dataType = DataTypeService.GetDataType(dataType.Id); Assert.That(dataType, Is.Not.Null); } @@ -47,9 +44,8 @@ namespace Umbraco.Tests.Services public void DataTypeService_Can_Delete_Textfield_DataType_And_Clear_Usages() { // Arrange - var dataTypeService = DataTypeService; var textfieldId = "Umbraco.Textbox"; - var dataTypeDefinitions = dataTypeService.GetByEditorAlias(textfieldId); + var dataTypeDefinitions = DataTypeService.GetByEditorAlias(textfieldId); var doctype = MockedContentTypes.CreateSimpleContentType("umbTextpage", "Textpage"); ContentTypeService.Save(doctype); @@ -57,9 +53,9 @@ namespace Umbraco.Tests.Services // Act var definition = dataTypeDefinitions.First(); var definitionId = definition.Id; - dataTypeService.Delete(definition); + DataTypeService.Delete(definition); - var deletedDefinition = dataTypeService.GetDataType(definitionId); + var deletedDefinition = DataTypeService.GetDataType(definitionId); // Assert Assert.That(deletedDefinition, Is.Null); @@ -73,14 +69,11 @@ namespace Umbraco.Tests.Services [Test] public void Cannot_Save_DataType_With_Empty_Name() { - // Arrange - var dataTypeService = DataTypeService; - // Act var dataTypeDefinition = new DataType(new LabelPropertyEditor(Logger, IOHelper, DataTypeService, LocalizedTextService,LocalizationService, ShortStringHelper)) { Name = string.Empty, DatabaseType = ValueStorageType.Ntext }; // Act & Assert - Assert.Throws(() => dataTypeService.Save(dataTypeDefinition)); + Assert.Throws(() => DataTypeService.Save(dataTypeDefinition)); } } } diff --git a/src/Umbraco.Tests.Integration/Services/KeyValueServiceTests.cs b/src/Umbraco.Tests.Integration/Services/KeyValueServiceTests.cs index 03e9d84787..17c601e9ec 100644 --- a/src/Umbraco.Tests.Integration/Services/KeyValueServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/KeyValueServiceTests.cs @@ -21,11 +21,8 @@ namespace Umbraco.Tests.Services [Test] public void GetValue_ForMissingKey_ReturnsNull() { - // Arrange - var keyValueService = KeyValueService; - // Act - var value = keyValueService.GetValue("foo"); + var value = KeyValueService.GetValue("foo"); // Assert Assert.IsNull(value); @@ -34,12 +31,10 @@ namespace Umbraco.Tests.Services [Test] public void GetValue_ForExistingKey_ReturnsValue() { - // Arrange - var keyValueService = KeyValueService; - keyValueService.SetValue("foo", "bar"); + KeyValueService.SetValue("foo", "bar"); // Act - var value = keyValueService.GetValue("foo"); + var value = KeyValueService.GetValue("foo"); // Assert Assert.AreEqual("bar", value); @@ -48,13 +43,11 @@ namespace Umbraco.Tests.Services [Test] public void SetValue_ForExistingKey_SavesValue() { - // Arrange - var keyValueService = KeyValueService; - keyValueService.SetValue("foo", "bar"); + KeyValueService.SetValue("foo", "bar"); // Act - keyValueService.SetValue("foo", "buzz"); - var value = keyValueService.GetValue("foo"); + KeyValueService.SetValue("foo", "buzz"); + var value = KeyValueService.GetValue("foo"); // Assert Assert.AreEqual("buzz", value); @@ -63,13 +56,11 @@ namespace Umbraco.Tests.Services [Test] public void TrySetValue_ForExistingKeyWithProvidedValue_ReturnsTrueAndSetsValue() { - // Arrange - var keyValueService = KeyValueService; - keyValueService.SetValue("foo", "bar"); + KeyValueService.SetValue("foo", "bar"); // Act - var result = keyValueService.TrySetValue("foo", "bar", "buzz"); - var value = keyValueService.GetValue("foo"); + var result = KeyValueService.TrySetValue("foo", "bar", "buzz"); + var value = KeyValueService.GetValue("foo"); // Assert Assert.IsTrue(result); @@ -79,13 +70,11 @@ namespace Umbraco.Tests.Services [Test] public void TrySetValue_ForExistingKeyWithoutProvidedValue_ReturnsFalseAndDoesNotSetValue() { - // Arrange - var keyValueService = KeyValueService; - keyValueService.SetValue("foo", "bar"); + KeyValueService.SetValue("foo", "bar"); // Act - var result = keyValueService.TrySetValue("foo", "bang", "buzz"); - var value = keyValueService.GetValue("foo"); + var result = KeyValueService.TrySetValue("foo", "bang", "buzz"); + var value = KeyValueService.GetValue("foo"); // Assert Assert.IsFalse(result); diff --git a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index 3dcab4c746..7da49067db 100644 --- a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -50,11 +50,8 @@ namespace Umbraco.Tests.Services [Test] public void Can_Get_By_Alias() { - // Arrange - var macroService = MacroService; - // Act - var macro = macroService.GetByAlias("test1"); + var macro = MacroService.GetByAlias("test1"); //assert Assert.IsNotNull(macro); @@ -64,11 +61,8 @@ namespace Umbraco.Tests.Services [Test] public void Can_Get_All() { - // Arrange - var macroService = MacroService; - // Act - var result = macroService.GetAll(); + var result = MacroService.GetAll(); //assert Assert.AreEqual(3, result.Count()); @@ -77,24 +71,21 @@ namespace Umbraco.Tests.Services [Test] public void Can_Create() { - // Arrange - var macroService = MacroService; - // Act var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); - macroService.Save(macro); + MacroService.Save(macro); //assert Assert.IsTrue(macro.HasIdentity); Assert.Greater(macro.Id, 0); Assert.AreNotEqual(Guid.Empty, macro.Key); - var result = macroService.GetById(macro.Id); + var result = MacroService.GetById(macro.Id); Assert.AreEqual("test", result.Alias); Assert.AreEqual("Test", result.Name); Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.MacroSource); Assert.AreEqual(1234, result.CacheDuration); - result = macroService.GetById(macro.Key); + result = MacroService.GetById(macro.Key); Assert.AreEqual("test", result.Alias); Assert.AreEqual("Test", result.Name); Assert.AreEqual("~/Views/MacroPartials/Test.cshtml", result.MacroSource); @@ -104,38 +95,34 @@ namespace Umbraco.Tests.Services [Test] public void Can_Delete() { - // Arrange - var macroService = MacroService; var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); - macroService.Save(macro); + MacroService.Save(macro); // Act - macroService.Delete(macro); + MacroService.Delete(macro); //assert - var result = macroService.GetById(macro.Id); + var result = MacroService.GetById(macro.Id); Assert.IsNull(result); - result = macroService.GetById(macro.Key); + result = MacroService.GetById(macro.Key); Assert.IsNull(result); } [Test] public void Can_Update() { - // Arrange - var macroService = MacroService; IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); - macroService.Save(macro); + MacroService.Save(macro); // Act var currKey = macro.Key; macro.Name = "New name"; macro.Alias = "NewAlias"; - macroService.Save(macro); + MacroService.Save(macro); - macro = macroService.GetById(macro.Id); + macro = MacroService.GetById(macro.Id); //assert Assert.AreEqual("New name", macro.Name); @@ -147,11 +134,9 @@ namespace Umbraco.Tests.Services [Test] public void Can_Update_Property() { - // Arrange - var macroService = MacroService; IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); macro.Properties.Add(new MacroProperty("blah", "Blah", 0, "blah")); - macroService.Save(macro); + MacroService.Save(macro); Assert.AreNotEqual(Guid.Empty, macro.Properties[0].Key); @@ -161,9 +146,9 @@ namespace Umbraco.Tests.Services macro.Properties[0].Name = "new Name"; macro.Properties[0].SortOrder = 1; macro.Properties[0].EditorAlias = "new"; - macroService.Save(macro); + MacroService.Save(macro); - macro = macroService.GetById(macro.Id); + macro = MacroService.GetById(macro.Id); //assert Assert.AreEqual(1, macro.Properties.Count); @@ -178,13 +163,11 @@ namespace Umbraco.Tests.Services [Test] public void Can_Update_Remove_Property() { - // Arrange - var macroService = MacroService; IMacro macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); macro.Properties.Add(new MacroProperty("blah1", "Blah1", 0, "blah1")); macro.Properties.Add(new MacroProperty("blah2", "Blah2", 1, "blah2")); macro.Properties.Add(new MacroProperty("blah3", "Blah3", 2, "blah3")); - macroService.Save(macro); + MacroService.Save(macro); var lastKey = macro.Properties[0].Key; for (var i = 1; i < macro.Properties.Count; i++) @@ -203,9 +186,9 @@ namespace Umbraco.Tests.Services var allPropKeys = macro.Properties.Values.Select(x => new { x.Alias, x.Key }).ToArray(); - macroService.Save(macro); + MacroService.Save(macro); - macro = macroService.GetById(macro.Id); + macro = MacroService.GetById(macro.Id); //assert Assert.AreEqual(2, macro.Properties.Count); @@ -223,7 +206,6 @@ namespace Umbraco.Tests.Services [Test] public void Can_Add_And_Remove_Properties() { - var macroService = MacroService; var macro = new Macro(ShortStringHelper, "test", "Test", "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); //adds some properties @@ -231,9 +213,9 @@ namespace Umbraco.Tests.Services macro.Properties.Add(new MacroProperty("blah2", "Blah2", 0, "blah2")); macro.Properties.Add(new MacroProperty("blah3", "Blah3", 0, "blah3")); macro.Properties.Add(new MacroProperty("blah4", "Blah4", 0, "blah4")); - macroService.Save(macro); + MacroService.Save(macro); - var result1 = macroService.GetById(macro.Id); + var result1 = MacroService.GetById(macro.Id); Assert.AreEqual(4, result1.Properties.Values.Count()); //simulate clearing the sections @@ -244,12 +226,12 @@ namespace Umbraco.Tests.Services //now just re-add a couple result1.Properties.Add(new MacroProperty("blah3", "Blah3", 0, "blah3")); result1.Properties.Add(new MacroProperty("blah4", "Blah4", 0, "blah4")); - macroService.Save(result1); + MacroService.Save(result1); //assert //re-get - result1 = macroService.GetById(result1.Id); + result1 = MacroService.GetById(result1.Id); Assert.AreEqual(2, result1.Properties.Values.Count()); } @@ -257,22 +239,20 @@ namespace Umbraco.Tests.Services [Test] public void Cannot_Save_Macro_With_Empty_Name() { - // Arrange - var macroService = MacroService; var macro = new Macro(ShortStringHelper, "test", string.Empty, "~/Views/MacroPartials/Test.cshtml", cacheDuration: 1234); // Act & Assert - Assert.Throws(() => macroService.Save(macro)); + Assert.Throws(() => MacroService.Save(macro)); } //[Test] //public void Can_Get_Many_By_Alias() //{ // // Arrange - // var macroService = MacroService; + // var MacroService = MacroService; // // Act - // var result = macroService.GetAll("test1", "test2"); + // var result = MacroService.GetAll("test1", "test2"); // //assert // Assert.AreEqual(2, result.Count()); From e6fcfb09bd19084ec078bd4219dec06d120b1d6c Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 14:49:11 +0200 Subject: [PATCH 34/36] Fix commented out test --- src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index 7da49067db..0c38f77a9e 100644 --- a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -248,9 +248,6 @@ namespace Umbraco.Tests.Services //[Test] //public void Can_Get_Many_By_Alias() //{ - // // Arrange - // var MacroService = MacroService; - // // Act // var result = MacroService.GetAll("test1", "test2"); From 55a9623c84e040dec24bb0521a3cefc02cf9d78e Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 15:21:27 +0200 Subject: [PATCH 35/36] Fix csproj after merge --- src/Umbraco.Tests/Umbraco.Tests.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 7f5a93cede..36bcee250b 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -140,8 +140,6 @@ - - @@ -155,8 +153,6 @@ - - From 9f05ae77925807663eec2c51e787361efc272fdc Mon Sep 17 00:00:00 2001 From: Mole Date: Tue, 6 Oct 2020 15:22:47 +0200 Subject: [PATCH 36/36] Don't save macro twice --- src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs index 75eaa85467..04c5661c35 100644 --- a/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs +++ b/src/Umbraco.Tests.Integration/Services/MacroServiceTests.cs @@ -65,8 +65,6 @@ namespace Umbraco.Tests.Integration.Services var macro = CreateMacro(); MacroService.Save(macro); - MacroService.Save(macro); - // Assert Assert.IsTrue(macro.HasIdentity); Assert.Greater(macro.Id, 0);