Skip to content

Instantly share code, notes, and snippets.

@hatelove
Created April 8, 2013 07:38
Show Gist options
  • Save hatelove/5334943 to your computer and use it in GitHub Desktop.
Save hatelove/5334943 to your computer and use it in GitHub Desktop.
LINQ training session 3 - Generic homework
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LinqSession3_GenericSample;
using System.Text;
namespace UnitTestLinqSession3
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void Test_Person()
{
var target = new EntityHelper();
var entity = new Person { Id = 91, Age = 18, Name = "Joey" };
target.LogPkey<Person>(entity);
var resultMessage = target.GetMessage();
var sb = new StringBuilder();
sb.AppendLine(string.Format("Pkey name:{0}, value:{1}", "Id", "91"));
var expected = sb.ToString();
Assert.AreEqual(expected, resultMessage);
}
[TestMethod]
public void Test_Order()
{
var target = new EntityHelper();
var entity = new Order { Id = 1, Price = 100 };
target.LogPkey<Order>(entity);
var resultMessage = target.GetMessage();
Assert.AreEqual(string.Empty, resultMessage);
}
}
public class Person
{
[Pkey]
public int Id { get; set; }
public int Age { get; set; }
public string Name { get; set; }
}
public class Order
{
public int Id { get; set; }
public int Price { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqSession3_GenericSample
{
public class PkeyAttribute : Attribute
{
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqSession3_GenericSample
{
public class EntityHelper
{
private StringBuilder _message = new StringBuilder();
// Todo: adding function : LogPkey()
public string GetMessage()
{
return this._message.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment