Skip to content

Commit

Permalink
Fix/1708 sql incremental naming (#1713)
Browse files Browse the repository at this point in the history
* Add missing tracer to MsSql integration test platform.

* Move 2 tests to integration tests.

* Fix: throw correct exception.

* Fix ServicesTests
  • Loading branch information
kavics authored Jul 6, 2022
1 parent d124ccd commit 667b44b
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 52 deletions.
2 changes: 2 additions & 0 deletions src/ContentRepository.MsSql/MsSqlDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ protected override Exception GetException(Exception innerException, string messa
return innerException;
if (innerException is NodeIsOutOfDateException)
return innerException;
if (innerException is NodeAlreadyExistsException)
return innerException;

if (!(innerException is SqlException sqlEx))
return null;
Expand Down
52 changes: 0 additions & 52 deletions src/Tests/SenseNet.ContentRepository.Tests/AutoNamingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,58 +75,6 @@ public void ContentNaming_FromDisplayName()
}
}
[TestMethod]
public void ContentNaming_AllowIncrementalNaming_Allowed()
{
Test(() =>
{
InstallContentTypes();
var testRoot = new SystemFolder(Repository.Root);
testRoot.Save();

Content content1, content2;
do
{
content1 = Content.CreateNew(ContentType_Car1Name, testRoot, null);
content2 = Content.CreateNew(ContentType_Car1Name, testRoot, null);
} while (content1.Name != content2.Name);
content1.Save();
content2.Save();
});
}
[TestMethod]
public void ContentNaming_AllowIncrementalNaming_Disallowed()
{
Test(() =>
{
var thrown = false;
try
{
InstallContentTypes();
var testRoot = new SystemFolder(Repository.Root);
testRoot.Save();

Content content1, content2;
do
{
content1 = Content.CreateNew(ContentType_Car2Name, testRoot, null);
content2 = Content.CreateNew(ContentType_Car2Name, testRoot, null);
} while (content1.Name != content2.Name);
content1.Save();
content2.Save();
}
catch (NodeAlreadyExistsException)
{
thrown = true;
}
catch (AggregateException ae)
{
thrown = ae.InnerException is NodeAlreadyExistsException;
}
if (!thrown)
Assert.Fail("The expected NodeAlreadyExistsException was not thrown.");
});
}
[TestMethod]
public void ContentNaming_IncrementNameSuffixOnSave()
{
Test(() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SenseNet.IntegrationTests.Infrastructure;
using SenseNet.IntegrationTests.Platforms;
using SenseNet.IntegrationTests.TestCases;

namespace SenseNet.IntegrationTests.InMemTests
{
[TestClass]
public class InMemIncrementalNamingTests : IntegrationTest<InMemPlatform, IncrementalNamingTestCases>
{
[TestMethod]
public void IntT_InMem_ContentNaming_AllowIncrementalNaming_Allowed() { TestCase.ContentNaming_AllowIncrementalNaming_Allowed(); }
[TestMethod]
public void IntT_InMem_ContentNaming_AllowIncrementalNaming_Disallowed() { TestCase.ContentNaming_AllowIncrementalNaming_Disallowed(); }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SenseNet.IntegrationTests.Infrastructure;
using SenseNet.IntegrationTests.Platforms;
using SenseNet.IntegrationTests.TestCases;

namespace SenseNet.IntegrationTests.MsSqlTests
{
[TestClass]
public class MsSqlIncrementalNamingTests : IntegrationTest<MsSqlPlatform, IncrementalNamingTestCases>
{
[TestMethod]
public void IntT_MsSql_ContentNaming_AllowIncrementalNaming_Allowed() { TestCase.ContentNaming_AllowIncrementalNaming_Allowed(); }
[TestMethod]
public void IntT_MsSql_ContentNaming_AllowIncrementalNaming_Disallowed() { TestCase.ContentNaming_AllowIncrementalNaming_Disallowed(); }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public override void BuildServices(IConfiguration configuration, IServiceCollect
})

.AddSingleton<ITestingDataProvider, MsSqlTestingDataProvider>()
.AddSingleton<ISnTracer, SnDebugViewTracer>()
;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SenseNet.ContentRepository;
using SenseNet.ContentRepository.Schema;
using SenseNet.ContentRepository.Storage.Data;
using SenseNet.IntegrationTests.Infrastructure;
using Task = System.Threading.Tasks.Task;

namespace SenseNet.IntegrationTests.TestCases
{
public class IncrementalNamingTestCases : TestCaseBase
{
private static string ContentType_IncrementalNamingAllowedName = "ContentType_IncrementalNamingAllowed";
private static string ContentType_IncrementalNamingDisallowedName = "ContentType_IncrementalNamingDisallowed";
private static ContentType ContentType_IncrementalNamingAllowed;
private static ContentType ContentType_IncrementalNamingDisallowed;
public static void InstallContentTypes()
{
var ctdformat = @"<?xml version=""1.0"" encoding=""utf-8""?>
<ContentType name=""{0}"" parentType=""Car"" handler=""SenseNet.ContentRepository.GenericContent""
xmlns=""http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition"">
<AllowIncrementalNaming>{1}</AllowIncrementalNaming>
</ContentType>";
var ctd1 = String.Format(ctdformat, ContentType_IncrementalNamingAllowedName, "true");
var ctd2 = String.Format(ctdformat, ContentType_IncrementalNamingDisallowedName, "false");
ContentTypeInstaller.InstallContentType(CarContentType, ctd1, ctd2);
ContentType_IncrementalNamingAllowed = ContentType.GetByName(ContentType_IncrementalNamingAllowedName);
ContentType_IncrementalNamingDisallowed = ContentType.GetByName(ContentType_IncrementalNamingDisallowedName);
}

/* ================================================================================= TEST CASES */

public void ContentNaming_AllowIncrementalNaming_Allowed()
{
IntegrationTest(() =>
{
InstallContentTypes();
var testRoot = new SystemFolder(Repository.Root);
testRoot.Save();

Content content1, content2;
do
{
content1 = Content.CreateNew(ContentType_IncrementalNamingAllowedName, testRoot, null);
content2 = Content.CreateNew(ContentType_IncrementalNamingAllowedName, testRoot, null);
} while (content1.Name != content2.Name);
content1.Save();
content2.Save();
});

}
public void ContentNaming_AllowIncrementalNaming_Disallowed()
{
IntegrationTest(() =>
{
var thrown = false;
try
{
InstallContentTypes();
var testRoot = new SystemFolder(Repository.Root);
testRoot.Save();

Content content1, content2;
do
{
content1 = Content.CreateNew(ContentType_IncrementalNamingDisallowedName, testRoot, null);
content2 = Content.CreateNew(ContentType_IncrementalNamingDisallowedName, testRoot, null);
} while (content1.Name != content2.Name);
content1.Save();
content2.Save();
}
catch (NodeAlreadyExistsException)
{
thrown = true;
}
catch (AggregateException ae)
{
thrown = ae.InnerException is NodeAlreadyExistsException;
}
if (!thrown)
Assert.Fail("The expected NodeAlreadyExistsException was not thrown.");
});
}
}
}
1 change: 1 addition & 0 deletions src/Tests/WebAppTests/ServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ public void Test_Services_Integration_MsSql()
typeof(MsSqlStatisticsComponent),
typeof(MsSqlClientStoreComponent),
}},
{typeof(ISnTracer), typeof(SnDebugViewTracer)},
},
includedProvidersByType: _defaultIncludedProvidersByType,
includedProvidersByName: _defaultIncludedProvidersByName,
Expand Down

0 comments on commit 667b44b

Please sign in to comment.