Skip to content

Commit

Permalink
Split the jumbo test class into small test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Turnerj committed Dec 9, 2020
1 parent 7296007 commit fb0cce4
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace MongoFramework.Tests.Infrastructure.Linq.Translation
{
[TestClass]
public class ExpressionTranslationTests : QueryTestBase
public class ExpressionTranslationTests_Conditional : QueryTestBase
{
[TestMethod]
public void TranslateConditional_Equals()
Expand Down Expand Up @@ -239,81 +239,5 @@ public void TranslateConditional_ExternalConstants()
};
Assert.AreEqual(expected, result);
}

[TestMethod]
public void TranslateInstantiation_Anonymous()
{
var expression = GetTransform(e => new
{
e.Id,
MyNumber = e.SingleNumber
});
var result = ExpressionTranslation.TranslateInstantiation(expression);
var expected = new BsonDocument
{
{ "Id", "Id" },
{ "MyNumber", "SingleNumber" }
};
Assert.AreEqual(expected, result);
}

[TestMethod]
public void TranslateInstantiation_RealType()
{
var expression = GetTransform(e => new QueryTestModel
{
Id = e.Id,
SingleNumber = e.SingleNumber
});
var result = ExpressionTranslation.TranslateInstantiation(expression);
var expected = new BsonDocument
{
{ "Id", "Id" },
{ "SingleNumber", "SingleNumber" }
};
Assert.AreEqual(expected, result);
}

[TestMethod, ExpectedException(typeof(ArgumentException))]
public void TranslateInstantiation_InvalidExpression()
{
var expression = GetTransform(e => e.SingleNumber);
ExpressionTranslation.TranslateInstantiation(expression);
}

[TestMethod]
public void TranslateMember_SingleLevelMember()
{
var expression = GetTransform(e => e.SingleString);
var result = ExpressionTranslation.TranslateMember(expression);
var expected = new BsonString("SingleString");
Assert.AreEqual(expected, result);
}

[TestMethod]
public void TranslateMember_MultiLevelMember()
{
var expression = GetTransform(e => e.SingleModel.SingleNumber);
var result = ExpressionTranslation.TranslateMember(expression);
var expected = new BsonString("SingleModel.SingleNumber");
Assert.AreEqual(expected, result);
}

[TestMethod]
public void TranslateMember_MemberWithArrayIndex_AtStart()
{
var expression = GetTransform(e => e.ArrayOfModels[3].SingleNumber);
var result = ExpressionTranslation.TranslateMember(expression);
var expected = new BsonString("ArrayOfModels.3.SingleNumber");
Assert.AreEqual(expected, result);
}
[TestMethod]
public void TranslateMember_MemberWithArrayIndex_AtEnd()
{
var expression = GetTransform(e => e.SingleModel.ArrayOfModels[2]);
var result = ExpressionTranslation.TranslateMember(expression);
var expected = new BsonString("SingleModel.ArrayOfModels.2");
Assert.AreEqual(expected, result);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MongoDB.Bson;
using MongoFramework.Infrastructure.Linq.Translation;

namespace MongoFramework.Tests.Infrastructure.Linq.Translation
{
[TestClass]
public class ExpressionTranslationTests_Instantiation : QueryTestBase
{
[TestMethod]
public void TranslateInstantiation_Anonymous()
{
var expression = GetTransform(e => new
{
e.Id,
MyNumber = e.SingleNumber
});
var result = ExpressionTranslation.TranslateInstantiation(expression);
var expected = new BsonDocument
{
{ "Id", "Id" },
{ "MyNumber", "SingleNumber" }
};
Assert.AreEqual(expected, result);
}

[TestMethod]
public void TranslateInstantiation_RealType()
{
var expression = GetTransform(e => new QueryTestModel
{
Id = e.Id,
SingleNumber = e.SingleNumber
});
var result = ExpressionTranslation.TranslateInstantiation(expression);
var expected = new BsonDocument
{
{ "Id", "Id" },
{ "SingleNumber", "SingleNumber" }
};
Assert.AreEqual(expected, result);
}

[TestMethod, ExpectedException(typeof(ArgumentException))]
public void TranslateInstantiation_InvalidExpression()
{
var expression = GetTransform(e => e.SingleNumber);
ExpressionTranslation.TranslateInstantiation(expression);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MongoDB.Bson;
using MongoFramework.Infrastructure.Linq.Translation;

namespace MongoFramework.Tests.Infrastructure.Linq.Translation
{
[TestClass]
public class ExpressionTranslationTests_Member : QueryTestBase
{
[TestMethod]
public void TranslateMember_SingleLevelMember()
{
var expression = GetTransform(e => e.SingleString);
var result = ExpressionTranslation.TranslateMember(expression);
var expected = new BsonString("SingleString");
Assert.AreEqual(expected, result);
}

[TestMethod]
public void TranslateMember_MultiLevelMember()
{
var expression = GetTransform(e => e.SingleModel.SingleNumber);
var result = ExpressionTranslation.TranslateMember(expression);
var expected = new BsonString("SingleModel.SingleNumber");
Assert.AreEqual(expected, result);
}

[TestMethod]
public void TranslateMember_MemberWithArrayIndex_AtStart()
{
var expression = GetTransform(e => e.ArrayOfModels[3].SingleNumber);
var result = ExpressionTranslation.TranslateMember(expression);
var expected = new BsonString("ArrayOfModels.3.SingleNumber");
Assert.AreEqual(expected, result);
}
[TestMethod]
public void TranslateMember_MemberWithArrayIndex_AtEnd()
{
var expression = GetTransform(e => e.SingleModel.ArrayOfModels[2]);
var result = ExpressionTranslation.TranslateMember(expression);
var expected = new BsonString("SingleModel.ArrayOfModels.2");
Assert.AreEqual(expected, result);
}
}
}

0 comments on commit fb0cce4

Please sign in to comment.