Skip to content

Commit

Permalink
#3 Moving Core Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Gerbenis committed Oct 1, 2015
1 parent 78c61d2 commit e6284d3
Show file tree
Hide file tree
Showing 16 changed files with 221 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// new TestModel {Name = "Test2"},
// }.AsQueryable();

// [Test]
// [Fact]
// public void Should_Call_Fetch_Successfully()
// {
// using (var fakeProvider = new ContextScopeProviderHelper())
Expand All @@ -32,13 +32,13 @@

// var result = originalQuery.Fetch(s => s.Parent);

// Assert.IsNotNull(result);
// Assert.NotNull(result);
// Assert.Equal(result.Count(), 1);
// Assert.IsTrue(result.Any(r => r.Name == "Fetch_Result"));
// Assert.True(result.Any(r => r.Name == "Fetch_Result"));
// }
// }

// [Test]
// [Fact]
// public void Should_Call_FetchMany_Successfully()
// {
// using (var fakeProvider = new ContextScopeProviderHelper())
Expand All @@ -48,13 +48,13 @@

// var result = originalQuery.FetchMany(s => s.Children);

// Assert.IsNotNull(result);
// Assert.NotNull(result);
// Assert.Equal(result.Count(), 1);
// Assert.IsTrue(result.Any(r => r.Name == "FetchMany_Result"));
// Assert.True(result.Any(r => r.Name == "FetchMany_Result"));
// }
// }

// [Test]
// [Fact]
// public void Should_Call_ThenFetch_Successfully()
// {
// using (var fakeProvider = new ContextScopeProviderHelper())
Expand All @@ -64,13 +64,13 @@

// var result = originalQuery.Fetch(s => s.Parent).ThenFetch(s => s.Parent);

// Assert.IsNotNull(result);
// Assert.NotNull(result);
// Assert.Equal(result.Count(), 1);
// Assert.IsTrue(result.Any(r => r.Name == "ThenFetch_Result"));
// Assert.True(result.Any(r => r.Name == "ThenFetch_Result"));
// }
// }

// [Test]
// [Fact]
// public void Should_Call_ThenFetchMany_Successfully()
// {
// using (var fakeProvider = new ContextScopeProviderHelper())
Expand All @@ -80,9 +80,9 @@

// var result = originalQuery.FetchMany(s => s.Children).ThenFetchMany(s => s.Children);

// Assert.IsNotNull(result);
// Assert.NotNull(result);
// Assert.Equal(result.Count(), 1);
// Assert.IsTrue(result.Any(r => r.Name == "ThenFetchMany_Result"));
// Assert.True(result.Any(r => r.Name == "ThenFetchMany_Result"));
// }
// }

Expand All @@ -103,9 +103,9 @@
// .Setup(p => p.ThenFetch(It.IsAny<FetchRequestTest<TestModel, TestModel>>(), It.IsAny<Expression<Func<TestModel, TestModel>>>()))
// .Returns<FetchRequestTest<TestModel, TestModel>, Expression<Func<TestModel, TestModel>>>((query, expression) =>
// {
// Assert.IsNotNull(query);
// Assert.NotNull(query);
// Assert.Equal(query.Count(), 1);
// Assert.IsTrue(query.Any(r => r.Name == "Fetch_Result"));
// Assert.True(query.Any(r => r.Name == "Fetch_Result"));

// var result = new List<TestModel> {new TestModel {Name = "ThenFetch_Result"}}.AsQueryable();
// return new FetchRequestTest<TestModel, TestModel>(result);
Expand All @@ -125,9 +125,9 @@
// .Setup(p => p.ThenFetchMany(It.IsAny<FetchRequestTest<TestModel, TestModel>>(), It.IsAny<Expression<Func<TestModel, IEnumerable<TestModel>>>>()))
// .Returns<FetchRequestTest<TestModel, TestModel>, Expression<Func<TestModel, IEnumerable<TestModel>>>>((query, expression) =>
// {
// Assert.IsNotNull(query);
// Assert.NotNull(query);
// Assert.Equal(query.Count(), 1);
// Assert.IsTrue(query.Any(r => r.Name == "FetchMany_Result"));
// Assert.True(query.Any(r => r.Name == "FetchMany_Result"));

// var result = new List<TestModel> {new TestModel {Name = "ThenFetchMany_Result"}}.AsQueryable();
// return new FetchRequestTest<TestModel, TestModel>(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void ShouldLoad_Assembly_GetLoadableTypes()
// var testBaseType = typeof(TestBase);
// var types = loader.GetLoadableTypes(assembly, testBaseType);

// Assert.IsNotNull(types);
// Assert.NotNull(types);
// Assert.Greater(types.Count(), 1);
// Assert.IsTrue(types.Contains(GetType()));
// Assert.IsTrue(types.All(testBaseType.IsAssignableFrom));
// Assert.True(types.Contains(GetType()));
// Assert.True(types.All(testBaseType.IsAssignableFrom));
//}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,52 @@
using System.IO;
using System.Linq;
using BetterModules.Core.Environment.FileSystem;
using NUnit.Framework;
using Microsoft.Framework.Logging;
using Xunit;

namespace BetterModules.Core.Tests.Environment.FileSystem
{
[TestFixture]
public class DefaultWorkingDirectoryTests : TestBase
public class DefaultWorkingDirectoryTests
{
private string OriginalFileName
{
get
{
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "TestModules", "test.dll");
}
}

private string RuntimeFileName
{
get
{
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test.dll");
}
}
private string OriginalFileName => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "TestModules", "test.dll");

private string ModuleFileName
{
get
{
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "Modules", "test.dll");
}
}
private string RuntimeFileName => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test.dll");

private string ModuleFileName => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "Modules", "test.dll");

[Test]
[Fact]
public void ShouldReturn_Correct_WorkingDirectoryPath()
{
var service = new DefaultWorkingDirectory();
var service = new DefaultWorkingDirectory(new LoggerFactory());
var path = service.GetWorkingDirectoryPath();

Assert.IsNotNull(path);
Assert.IsTrue(path.Contains(AppDomain.CurrentDomain.BaseDirectory));
Assert.NotNull(path);
Assert.True(path.Contains(AppDomain.CurrentDomain.BaseDirectory));
}

[Test]
[Fact]
public void ShouldReturn_AvailableModules()
{
PrepareTestDll();

var service = new DefaultWorkingDirectory();
var service = new DefaultWorkingDirectory(new LoggerFactory());
var modules = service.GetAvailableModules();

Assert.IsNotNull(modules);
Assert.AreEqual(modules.Count(), 1);
Assert.AreEqual(modules.First().Name, "test.dll");
Assert.NotNull(modules);
Assert.Equal(modules.Count(), 1);
Assert.Equal(modules.First().Name, "test.dll");

RemoveTestDll();
}

[Test]
[Fact]
public void ShouldCopy_ModulesToRuntimeDirectory_Successfully()
{
PrepareTestDll();

var service = new DefaultWorkingDirectory();
var service = new DefaultWorkingDirectory(new LoggerFactory());
service.RecopyModulesToRuntimeFolder(new FileInfo(ModuleFileName));
Assert.IsTrue(File.Exists(RuntimeFileName));
Assert.True(File.Exists(RuntimeFileName));

RemoveTestDll();
}
Expand Down
21 changes: 10 additions & 11 deletions vNext/test/BetterModules.Core.Tests/Events/CoreEventsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@
using BetterModules.Events;
using Moq;
using NHibernate;
using NUnit.Framework;
using Xunit;

namespace BetterModules.Core.Tests.Events
{
[TestFixture]
public class CoreEventsTests : TestBase
public class CoreEventsTests
{
private int firedDelete;
private int firedSave;
private IEntity entity;
private ISession session;

[Test]
[Fact]
public void Should_FireDeleteEvents_Correctly()
{
firedDelete = 0;
entity = new Mock<IEntity>().Object;

CoreEvents.Instance.EntityDeleting += Instance_EntityDeleting;

Assert.AreEqual(firedDelete, 0);
Assert.Equal(firedDelete, 0);
CoreEvents.Instance.OnEntityDelete(entity);
Assert.AreEqual(firedDelete, 1);
Assert.Equal(firedDelete, 1);
CoreEvents.Instance.OnEntityDelete(entity);
Assert.AreEqual(firedDelete, 2);
Assert.Equal(firedDelete, 2);

CoreEvents.Instance.EntityDeleting -= Instance_EntityDeleting;
}

[Test]
[Fact]
public void Should_FireSaveEvents_Correctly()
{
firedSave = 0;
Expand All @@ -40,11 +39,11 @@ public void Should_FireSaveEvents_Correctly()

CoreEvents.Instance.EntitySaving += Instance_EntitySaving;

Assert.AreEqual(firedSave, 0);
Assert.Equal(firedSave, 0);
CoreEvents.Instance.OnEntitySaving(entity, session);
Assert.AreEqual(firedSave, 1);
Assert.Equal(firedSave, 1);
CoreEvents.Instance.OnEntitySaving(entity, session);
Assert.AreEqual(firedSave, 2);
Assert.Equal(firedSave, 2);

CoreEvents.Instance.EntitySaving -= Instance_EntitySaving;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@
using BetterModules.Events;
using Moq;
using NHibernate;
using NUnit.Framework;
using Xunit;

namespace BetterModules.Core.Tests.Events
{
[TestFixture]
public class EntitySavingEventArgsTests : TestBase
public class EntitySavingEventArgsTests
{
[Test]
[Fact]
public void Should_Assign_Correct_Session_Arg()
{
var session = new Mock<ISession>().Object;
var entity = new Mock<IEntity>().Object;

var args = new EntitySavingEventArgs(entity, session);

Assert.AreEqual(args.Session, session);
Assert.AreEqual(args.Entity, entity);
Assert.Equal(args.Session, session);
Assert.Equal(args.Entity, entity);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using BetterModules.Events;
using NUnit.Framework;
using Xunit;

namespace BetterModules.Core.Tests.Events
{
[TestFixture]
public class SingleItemEventArgsTests : TestBase
public class SingleItemEventArgsTests
{
[Test]
[Fact]
public void Should_Assign_Correct_Single_Event_Arg()
{
var args = new SingleItemEventArgs<int>(13);

Assert.AreEqual(args.Item, 13);
Assert.Equal(args.Item, 13);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
using System;
using BetterModules.Core.Exceptions.DataTier;
using BetterModules.Sample.Module.Models;
using NUnit.Framework;
using Xunit;

namespace BetterModules.Core.Tests.Exceptions.DataTier
{
[TestFixture]
public class ConcurrentDataExceptionTests
{
private const string Message = "TestExcMessage";

[Test]
[Fact]
public void Should_Create_Exception_With_Message()
{
var exception = new ConcurrentDataException(Message);

Assert.AreEqual(exception.Message, Message);
Assert.IsNull(exception.InnerException);
Assert.IsNull(exception.StaleEntity);
Assert.Equal(exception.Message, Message);
Assert.Null(exception.InnerException);
Assert.Null(exception.StaleEntity);
}

[Test]
[Fact]
public void Should_Create_Exception_With_Message_And_InnerException()
{
var innerException = new Exception(Message);
var exception = new ConcurrentDataException(Message, innerException);

Assert.AreEqual(exception.Message, Message);
Assert.AreEqual(exception.InnerException, innerException);
Assert.IsNull(exception.StaleEntity);
Assert.Equal(exception.Message, Message);
Assert.Equal(exception.InnerException, innerException);
Assert.Null(exception.StaleEntity);
}

[Test]
[Fact]
public void Should_Create_Exception_With_Stale_Entity()
{
var guid = Guid.NewGuid();
var entity = new TestItemModel { Id = guid };
var exception = new ConcurrentDataException(entity);

Assert.IsNotNull(exception.Message);
Assert.IsTrue(exception.Message.Contains(guid.ToString()));
Assert.IsTrue(exception.Message.Contains("TestItemModel"));
Assert.AreEqual(exception.StaleEntity, entity);
Assert.IsNull(exception.InnerException);
Assert.NotNull(exception.Message);
Assert.True(exception.Message.Contains(guid.ToString()));
Assert.True(exception.Message.Contains("TestItemModel"));
Assert.Equal(exception.StaleEntity, entity);
Assert.Null(exception.InnerException);
}
}
}
Loading

0 comments on commit e6284d3

Please sign in to comment.