Created
April 8, 2013 07:38
-
-
Save hatelove/5334943 to your computer and use it in GitHub Desktop.
LINQ training session 3 - Generic homework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace LinqSession3_GenericSample | |
{ | |
public class PkeyAttribute : Attribute | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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