Skip to content

Instantly share code, notes, and snippets.

@hatelove
Created October 15, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatelove/6e2b910c8bc9f47e1253 to your computer and use it in GitHub Desktop.
Save hatelove/6e2b910c8bc9f47e1253 to your computer and use it in GitHub Desktop.
Alive+NUnit+EF+localDB
using System;
using System.Collections.Generic;
using System.Linq;
//using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnit.Framework;
namespace AliveWithSpecflowEf
{
[TestFixture]
public class UnitTest1
{
[Test]
public void TestMethod1()
{
//var condition =
var target = new OrderService();
var condition = new OrderQueryCondition
{
CustomerId = "ERNSH",
OrderDateStart = new DateTime(1997, 1, 1),
OrderDateEnd = new DateTime(1997, 1, 31)
};
var result = target.Query(condition);
Assert.AreEqual(3, result.Count);
}
}
internal class OrderService
{
public OrderService()
{
}
private NorthwindEntities dbContext;
internal List<Order> Query(OrderQueryCondition condition)
{
using (dbContext = new NorthwindEntities())
{
var orders = dbContext.Orders.Where(x => x.CustomerID == condition.CustomerId);
if (condition.OrderDateStart != null)
{
orders = orders.Where(x => x.OrderDate >= condition.OrderDateStart);
}
if (condition.OrderDateEnd != null)
{
orders = orders.Where(x => x.OrderDate <= condition.OrderDateEnd);
}
var result = orders.ToList();
return result;
}
}
}
internal class OrderQueryCondition
{
public string CustomerId { get; set; }
public DateTime? OrderDateStart { get; set; }
public DateTime? OrderDateEnd { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment