Make sure to dispose UnitOfWork in tests
This commit is contained in:
@@ -21,10 +21,11 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
public void CreateNotification()
|
||||
{
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repo = new NotificationsRepository(unitOfWork);
|
||||
|
||||
var node = new NodeDto {CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,123", SortOrder = 1, Text = "hello", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0};
|
||||
var node = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,123", SortOrder = 1, Text = "hello", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
var result = unitOfWork.Database.Insert(node);
|
||||
var entity = Mock.Of<IEntity>(e => e.Id == node.NodeId);
|
||||
var user = Mock.Of<IUser>(e => e.Id == node.UserId);
|
||||
@@ -36,92 +37,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.AreEqual(node.NodeObjectType, notification.EntityType);
|
||||
Assert.AreEqual(node.UserId, notification.UserId);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUserNotifications()
|
||||
{
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
var repo = new NotificationsRepository(unitOfWork);
|
||||
|
||||
var userDto = new UserDto { ContentStartId = -1, Email = "test" , Login = "test" , MediaStartId = -1, Password = "test" , Type = 1, UserName = "test" , UserLanguage = "en" };
|
||||
unitOfWork.Database.Insert(userDto);
|
||||
|
||||
var userNew = Mock.Of<IUser>(e => e.Id == userDto.Id);
|
||||
var userAdmin = Mock.Of<IUser>(e => e.Id == 0);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var node = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
var result = unitOfWork.Database.Insert(node);
|
||||
var entity = Mock.Of<IEntity>(e => e.Id == node.NodeId);
|
||||
var notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
var notifications = repo.GetUserNotifications(userAdmin);
|
||||
|
||||
Assert.AreEqual(5, notifications.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEntityNotifications()
|
||||
{
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
var repo = new NotificationsRepository(unitOfWork);
|
||||
|
||||
var node1 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
unitOfWork.Database.Insert(node1);
|
||||
var entity1 = Mock.Of<IEntity>(e => e.Id == node1.NodeId);
|
||||
var node2 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
unitOfWork.Database.Insert(node2);
|
||||
var entity2 = Mock.Of<IEntity>(e => e.Id == node2.NodeId);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", Type = 1, UserName = "test" + i, UserLanguage = "en" };
|
||||
unitOfWork.Database.Insert(userDto);
|
||||
var userNew = Mock.Of<IUser>(e => e.Id == userDto.Id);
|
||||
var notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
var notifications = repo.GetEntityNotifications(entity1);
|
||||
|
||||
Assert.AreEqual(5, notifications.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Delete_By_Entity()
|
||||
{
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
var repo = new NotificationsRepository(unitOfWork);
|
||||
|
||||
var node1 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
unitOfWork.Database.Insert(node1);
|
||||
var entity1 = Mock.Of<IEntity>(e => e.Id == node1.NodeId);
|
||||
var node2 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
unitOfWork.Database.Insert(node2);
|
||||
var entity2 = Mock.Of<IEntity>(e => e.Id == node2.NodeId);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", Type = 1, UserName = "test" + i, UserLanguage = "en" };
|
||||
unitOfWork.Database.Insert(userDto);
|
||||
var userNew = Mock.Of<IUser>(e => e.Id == userDto.Id);
|
||||
var notification = repo.CreateNotification(userNew, (i % 2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
var delCount = repo.DeleteNotifications(entity1);
|
||||
|
||||
Assert.AreEqual(5, delCount);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Delete_By_User()
|
||||
{
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
var repo = new NotificationsRepository(unitOfWork);
|
||||
|
||||
var userDto = new UserDto { ContentStartId = -1, Email = "test", Login = "test", MediaStartId = -1, Password = "test", Type = 1, UserName = "test", UserLanguage = "en" };
|
||||
@@ -135,7 +59,96 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
var node = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
var result = unitOfWork.Database.Insert(node);
|
||||
var entity = Mock.Of<IEntity>(e => e.Id == node.NodeId);
|
||||
var notification = repo.CreateNotification((i % 2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture));
|
||||
var notification = repo.CreateNotification((i%2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
var notifications = repo.GetUserNotifications(userAdmin);
|
||||
|
||||
Assert.AreEqual(5, notifications.Count());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEntityNotifications()
|
||||
{
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
|
||||
var repo = new NotificationsRepository(unitOfWork);
|
||||
|
||||
var node1 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
unitOfWork.Database.Insert(node1);
|
||||
var entity1 = Mock.Of<IEntity>(e => e.Id == node1.NodeId);
|
||||
var node2 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
unitOfWork.Database.Insert(node2);
|
||||
var entity2 = Mock.Of<IEntity>(e => e.Id == node2.NodeId);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", Type = 1, UserName = "test" + i, UserLanguage = "en" };
|
||||
unitOfWork.Database.Insert(userDto);
|
||||
var userNew = Mock.Of<IUser>(e => e.Id == userDto.Id);
|
||||
var notification = repo.CreateNotification(userNew, (i%2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
var notifications = repo.GetEntityNotifications(entity1);
|
||||
|
||||
Assert.AreEqual(5, notifications.Count());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Delete_By_Entity()
|
||||
{
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
|
||||
var repo = new NotificationsRepository(unitOfWork);
|
||||
|
||||
var node1 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,1", SortOrder = 1, Text = "hello1", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
unitOfWork.Database.Insert(node1);
|
||||
var entity1 = Mock.Of<IEntity>(e => e.Id == node1.NodeId);
|
||||
var node2 = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1,2", SortOrder = 1, Text = "hello2", Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
unitOfWork.Database.Insert(node2);
|
||||
var entity2 = Mock.Of<IEntity>(e => e.Id == node2.NodeId);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var userDto = new UserDto { ContentStartId = -1, Email = "test" + i, Login = "test" + i, MediaStartId = -1, Password = "test", Type = 1, UserName = "test" + i, UserLanguage = "en" };
|
||||
unitOfWork.Database.Insert(userDto);
|
||||
var userNew = Mock.Of<IUser>(e => e.Id == userDto.Id);
|
||||
var notification = repo.CreateNotification(userNew, (i%2 == 0) ? entity1 : entity2, i.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
var delCount = repo.DeleteNotifications(entity1);
|
||||
|
||||
Assert.AreEqual(5, delCount);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Delete_By_User()
|
||||
{
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
|
||||
var repo = new NotificationsRepository(unitOfWork);
|
||||
|
||||
var userDto = new UserDto { ContentStartId = -1, Email = "test", Login = "test", MediaStartId = -1, Password = "test", Type = 1, UserName = "test", UserLanguage = "en" };
|
||||
unitOfWork.Database.Insert(userDto);
|
||||
|
||||
var userNew = Mock.Of<IUser>(e => e.Id == userDto.Id);
|
||||
var userAdmin = Mock.Of<IUser>(e => e.Id == 0);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var node = new NodeDto { CreateDate = DateTime.Now, Level = 1, NodeObjectType = Guid.Parse(Constants.ObjectTypes.ContentItem), ParentId = -1, Path = "-1," + i, SortOrder = 1, Text = "hello" + i, Trashed = false, UniqueId = Guid.NewGuid(), UserId = 0 };
|
||||
var result = unitOfWork.Database.Insert(node);
|
||||
var entity = Mock.Of<IEntity>(e => e.Id == node.NodeId);
|
||||
var notification = repo.CreateNotification((i%2 == 0) ? userAdmin : userNew, entity, i.ToString(CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
var delCount = repo.DeleteNotifications(userAdmin);
|
||||
@@ -143,4 +156,5 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.AreEqual(5, delCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,8 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
// unless noted otherwise, no changes / 7.2.8
|
||||
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new PartialViewRepository(unitOfWork, _fileSystem);
|
||||
|
||||
var partialView = new PartialView("test-path-1.cshtml") { Content = "// partialView" };
|
||||
@@ -90,6 +91,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
partialView = (PartialView) repository.Get("../../packages.config"); // outside the filesystem, exists
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
|
||||
@@ -35,7 +35,8 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
|
||||
// Act
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
@@ -43,30 +44,34 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
// Assert
|
||||
Assert.That(repository, Is.Not.Null);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Add_On_ScriptRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
|
||||
// Act
|
||||
var script = new Script("test-add-script.js") {Content = "/// <reference name=\"MicrosoftAjax.js\"/>"};
|
||||
var script = new Script("test-add-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
|
||||
repository.AddOrUpdate(script);
|
||||
unitOfWork.Flush();
|
||||
|
||||
//Assert
|
||||
Assert.That(_fileSystem.FileExists("test-add-script.js"), Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Update_On_ScriptRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
|
||||
// Act
|
||||
@@ -84,13 +89,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.That(_fileSystem.FileExists("test-updated-script.js"), Is.True);
|
||||
Assert.That(scriptUpdated.Content, Is.EqualTo("/// <reference name=\"MicrosoftAjax-Updated.js\"/>"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Delete_On_ScriptRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
|
||||
// Act
|
||||
@@ -101,7 +108,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
// Assert
|
||||
|
||||
Assert.IsFalse(repository.Exists("test-script.js"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -109,7 +116,8 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
|
||||
// Act
|
||||
@@ -120,13 +128,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.That(exists.Alias, Is.EqualTo("test-script"));
|
||||
Assert.That(exists.Name, Is.EqualTo("test-script.js"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_GetAll_On_ScriptRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
|
||||
var script = new Script("test-script1.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
|
||||
@@ -146,13 +156,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.That(scripts.Any(x => x == null), Is.False);
|
||||
Assert.That(scripts.Count(), Is.EqualTo(4));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_GetAll_With_Params_On_ScriptRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
|
||||
var script = new Script("test-script1.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
|
||||
@@ -172,13 +184,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.That(scripts.Any(x => x == null), Is.False);
|
||||
Assert.That(scripts.Count(), Is.EqualTo(2));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Exists_On_ScriptRepository()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
|
||||
// Act
|
||||
@@ -187,6 +201,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
// Assert
|
||||
Assert.That(exists, Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Move_On_ScriptRepository()
|
||||
@@ -195,7 +210,8 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
|
||||
var script = new Script("test-move-script.js") { Content = content };
|
||||
@@ -219,6 +235,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.IsTrue(existsNew);
|
||||
Assert.AreEqual(content, script.Content);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PathTests()
|
||||
@@ -226,7 +243,8 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
// unless noted otherwise, no changes / 7.2.8
|
||||
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>());
|
||||
|
||||
var script = new Script("test-path-1.js") { Content = "// script" };
|
||||
@@ -284,6 +302,7 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
script = repository.Get("../packages.config"); // outside the filesystem, exists
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
|
||||
@@ -35,8 +35,8 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
// Act
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
@@ -44,14 +44,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
// Assert
|
||||
Assert.That(repository, Is.Not.Null);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Add()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
// Act
|
||||
@@ -62,14 +63,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
//Assert
|
||||
Assert.That(_fileSystem.FileExists("test-add.css"), Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Update()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
// Act
|
||||
@@ -89,14 +91,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.That(stylesheetUpdated.HasIdentity, Is.True);
|
||||
Assert.That(stylesheetUpdated.Content, Is.EqualTo("body { color:#000; }"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Update_With_Property()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
// Act
|
||||
@@ -119,14 +122,15 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
p{font-size:2em;}"));
|
||||
Assert.AreEqual(1, stylesheet.Properties.Count());
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Throws_When_Adding_Duplicate_Properties()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
// Act
|
||||
@@ -137,7 +141,7 @@ p{font-size:2em;}"));
|
||||
stylesheet.AddProperty(new StylesheetProperty("Test", "p", "font-size:2em;"));
|
||||
|
||||
Assert.Throws<DuplicateNameException>(() => stylesheet.AddProperty(new StylesheetProperty("test", "p", "font-size:2em;")));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -145,8 +149,8 @@ p{font-size:2em;}"));
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
// Act
|
||||
@@ -160,14 +164,15 @@ p{font-size:2em;}"));
|
||||
//Assert
|
||||
Assert.That(_fileSystem.FileExists("test-delete.css"), Is.False);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Get()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
// Act
|
||||
@@ -179,14 +184,15 @@ p{font-size:2em;}"));
|
||||
Assert.That(stylesheet.Content, Is.EqualTo("body {background:#EE7600; color:#FFF;}"));
|
||||
Assert.That(repository.ValidateStylesheet(stylesheet), Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_GetAll()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
var stylesheet = new Stylesheet("styles-v2.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" };
|
||||
@@ -202,14 +208,15 @@ p{font-size:2em;}"));
|
||||
Assert.That(stylesheets.Any(x => x == null), Is.False);
|
||||
Assert.That(stylesheets.Count(), Is.EqualTo(2));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_GetAll_With_Params()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
var stylesheet = new Stylesheet("styles-v2.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" };
|
||||
@@ -225,14 +232,15 @@ p{font-size:2em;}"));
|
||||
Assert.That(stylesheets.Any(x => x == null), Is.False);
|
||||
Assert.That(stylesheets.Count(), Is.EqualTo(2));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Perform_Exists()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
// Act
|
||||
@@ -241,6 +249,7 @@ p{font-size:2em;}"));
|
||||
// Assert
|
||||
Assert.That(exists, Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PathTests()
|
||||
@@ -248,7 +257,8 @@ p{font-size:2em;}"));
|
||||
// unless noted otherwise, no changes / 7.2.8
|
||||
|
||||
var provider = new FileUnitOfWorkProvider();
|
||||
var unitOfWork = provider.CreateUnitOfWork();
|
||||
using (var unitOfWork = provider.CreateUnitOfWork())
|
||||
{
|
||||
var repository = new StylesheetRepository(unitOfWork, _fileSystem);
|
||||
|
||||
var stylesheet = new Stylesheet("test-path-1.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" };
|
||||
@@ -307,6 +317,7 @@ p{font-size:2em;}"));
|
||||
stylesheet = repository.Get("../packages.config"); // outside the filesystem, exists
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
|
||||
@@ -864,8 +864,10 @@ namespace Umbraco.Tests.Services
|
||||
bool published = contentService.Publish(content, 0);
|
||||
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
var uow = provider.CreateUnitOfWork();
|
||||
using (var uow = provider.CreateUnitOfWork())
|
||||
{
|
||||
Assert.IsTrue(uow.Database.Exists<ContentXmlDto>(content.Id));
|
||||
}
|
||||
|
||||
// Act
|
||||
bool unpublished = contentService.UnPublish(content, 0);
|
||||
@@ -875,9 +877,11 @@ namespace Umbraco.Tests.Services
|
||||
Assert.That(unpublished, Is.True);
|
||||
Assert.That(content.Published, Is.False);
|
||||
|
||||
uow = provider.CreateUnitOfWork();
|
||||
using (var uow = provider.CreateUnitOfWork())
|
||||
{
|
||||
Assert.IsFalse(uow.Database.Exists<ContentXmlDto>(content.Id));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This test is ignored because the way children are handled when
|
||||
|
||||
@@ -91,10 +91,10 @@ namespace Umbraco.Tests.Services
|
||||
mediaService.Save(media);
|
||||
|
||||
var provider = new NPocoUnitOfWorkProvider(Logger);
|
||||
var uow = provider.CreateUnitOfWork();
|
||||
|
||||
using (var uow = provider.CreateUnitOfWork())
|
||||
{
|
||||
Assert.IsTrue(uow.Database.Exists<ContentXmlDto>(media.Id));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private Tuple<IMedia, IMedia, IMedia, IMedia, IMedia> CreateTrashedTestMedia()
|
||||
|
||||
Reference in New Issue
Block a user