잊지 않겠습니다.

사용법은 Ruby, Python, C#, VB.NET이 거의 유사한 방법을 나타낸다.

ttern

Matching Criterion

Example

+

앞의 글자에 연달아서, 뒤에 글자가 붙어서 따라 오는경우

to+ 는 too, tooo 처럼
to뒤에 어떤것이 오는경우

*

바로 앞의 글자가 없거나, 또는 바로앞글자가 있고 뒤에 글자가 따라올때

to* 는 t, to, too 처럼 바로앞의 글자생략까지 포함

?

바로 앞의 글자가 없거나 있는경우

te?n 는 ten or tn 임. 
teen은 포함 안됨

{n}

n의수(입력된 숫자)만큼 정확하게 앞글자를 반복한다.

te{2}n 은 teen이다.  ten 이나 teeen 은 포함안됨

{n,}

n의수(입력된 숫자) 이하 만큼 반복 해준다

te{1,}n 은 ten 이나 teen 이다.  tn은 포함안됨.

{n,m}

 n 과 m 사이의수(입력한 두수의 차이)만큼 앞 글자를 반복

te{1,2}n 은 ten 이나 teen 이다

\

슬래쉬 듸에 오는 (+, *, 와 ?처럼) 특수한 의미를 가진 문자가 오면 그대로 처리하라는 의미

A\+B 과 A+B는 동일한의미.
  + 가 특수한 의미를 가진 문자이므로 슬래쉬를 써준것

\d \D

(\d)는 숫자 (\D)는 숫자가 아닌 글자를 말함. 전자는[0-9],  후자는[^0-9] 일치 함

\d\d 는 55 로, \D\D 는 xx로 
예를 들수 있음

\w \W

(\w)는 문자를(밑줄이나 괄호등 까지  포함),  (\W)은 문자가 아닌글을 말함. 
이는 [a-zA-Z0-9_]. 과 [^a-zA-Z0-9_]. 과 일치함

A_19 은  \w\w\w\w 이고
($). 는 \W\W\W  이다

\n \r \t \v \f 

순서대로, 다음줄로 넘어가기, 그줄의 첫번째로 돌아가기, 가로 탭, 세로 탭,  피드


\s \S

(\s)는 빈공간을 (\S)는 빈공간이 아닌 글자로 채워진 공간을 말함

\w\s\w\s\w 는 A B C 처럼 문자 네개 공백두개

. (dot)

. (마침표)는 한글자인 문자를 대표하는 기호.  문자 가운데 \n는 인식못함

a.c 의 예는 abc.
abcc 는 안됨

|

논리기호 OR의 의미.

"in|en" matches enquiry.

[. . . ]

괄호 안에 있는 문자 중에 있는 하나의 문자(알파벳, 점은 문자를 의미함)

[aeiou] 는 u(또는 각각 a, e, i, o 모두가능). [\d\D]는 하나의 숫자나 숫자가 아닌글

[^. . .]

괄호 안에 없는 하나의 문자(알파벳)

[^aeiou] matches x.



정규식 그룹명 이용법
string txt ="Monday Hi:88 Lo:56 Tuesday Hi:91 Lo:61";

string rgPatt = @"( ?<day>[a-zA-Z]+)\s*(?<temps>Hi:\d+\s*Lo:\d+)";
// 그룹명은 위에서 처럼  ?<그룹명>  으로 명명 해주고
MatchCollection mc = Regex.Matches(txt, rgPatt); 
// 스트링값과 정규식을 mc 그룹으로 묶어준후에 
foreach(Match m in mc) 
// mc그룹안의 그룹 하나 하나를 m으로 명명해주고
{
   Console.WriteLine("{0} {1}",
m.Groups["day"],m.Groups["temps"]);
//m의 그룹을 위에서 지정해준 이름으로 불러옴. m.Groups["그룹명"]
}
//출력하면   Monday Hi:88 Lo:56
//               Tuesday Hi:91 Lo:61

Example
Regex regex = new Regex(@"(?<name>CN)=(?<property>(\w)*(\d))", RegexOptions.Singleline);
string mailStoreString =
    "CN=BusinessMailstore5,CN=First Storage Group,CN=InformationStore,CN=EXBE03,CN=Servers,_
CN=First Administrative Group,CN=Administrative Groups,CN=TMEX,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=tmex,DC=co,DC=kr";
            
MatchCollection matchCollections = regex.Matches(mailStoreString);
foreach(Match m in matchCollections)
{
    Console.WriteLine(m.Groups["property"]);
}

 

Custom Log 데이터 분류

string examString = "Error : Name : 대리점가입자, PhoneNumber : 01041471048 / Open";
Regex regx = new Regex(@"(\w|\s|\:|\,)*(PhoneNumber\s\:\s)(?<phonenumber>\d{11})(\s\/\s\w+)");


Log4net 에서의 데이터 분류 하기 

string examString = "22:43:53 [26] INFO  com.hostway.lib.Syncmail [(null)] - Send SMS Message : To 01071933972";
Regex regx = new Regex(
       @"(?<eventdate>\d\d:\d\d:\d\d)(\w|\s|\[|\]|\(|\)|\.)*-\s(?<message>(\w|\s|\d|\:|)*)"
             );

Assert.IsTrue(regx.IsMatch(examString));
MatchCollection matches = regx.Matches(examString);
Assert.AreEqual(1, matches.Count);
Assert.AreEqual("22:43:53", matches[0].Groups["eventdate"].Value);
Console.WriteLine(matches[0].Groups["eventdate"].Value);
Console.WriteLine(matches[0].Groups["message"].Value);
Posted by Y2K
,

NUnit Guide

.NET Framework 2009. 1. 7. 11:11

:NUnit에서 각각의 test를 만들고, 그 Test에서 각각의 Assert문을 만드는 Class library

Constraint

Constraint-base Assert Model을 위한 Class

expect value와 actual value의 비교를 통해 true, false를 결정하고, message를 출력한다.

Assert

Attribute

TestFixtureAttribute

Test Class 선언 Attribute

  • TestFixtureSetUp : Test Class의 모든 Test가 실행되기 전에 수행되는 Test
  • TestAttribute : 각각의 Test
  • TestFixtureTearDown : Test Class의 모든 Test가 실행된 후에 수행되는 Test
  • SetUpAttribute : Test Attribute가 선언된 Test가 각각 실행되기 전에 수행되는 Test
  • TearDownAttribute : Test Attribute가 선언된 Test가 모두 종결될 때 수행되는 Test
SetUpFixtureAttribute
  • 선언된 Namespace에서 한번만 사용될 수 있는 Attribute
  • 모든 TestFixture가 실행되기 전, 모든 TestFixture가 종결될때 단 한번만 수행된다.
CategoryAttribute
  • Test의 종류를 모을 수 있는 Attribute
  • 각각의 Test에서 Category를 이용해서 NUnit.Console 또는 GUI Unit에서 Test의 종류를 모아서 사용 가능하다.
ExceptedExceptionAttribute
  • Exception 무시 처리
ExplicitAttribute
  • 특별하게 GUI또는 Console에서 지정되지 않는 경우에는 수행되지 않는 테스트를 지정한다.
IgnoreAttribute
  • 수행되지 않을 테스트를 지정한다. 이 경우에는 테스트는 Yellow Bar로 나타나게 된다.
  • 임시 테스트로 주로 사용하게 되며, 테스트에 대한 Issue를 적어놓도록 한다.
Description
  • 테스트 또는 Assembly에 대한 설정을 적어놓는 Attribute
[assembly: Description("Assembly description here")]

namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture, Description("Fixture description here")]
  public class SomeTests
  {
    [Test, Description("Test description here")]
    public void OneTest()
    { /* ... */ }
  }
}
Property
  • Test가 수행되는 동안에 Property의 값을 지정해 주는 Attribute
namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture, Property("Location",723)]
  public class MathTests
  {
    [Test, Property("Severity", "Critical")]
public void AdditionTest()
    { /* ... */ }
  }
}
IncludeExcludeAttribute (abstract)
  • Include, Exclude를 이용, Test의 수행 환경을 결정한다.
PlatformAttribute
  • Test가 수행될 환경 결정
namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  public class SuccessTests
  {
    [Test]
    [Platform(Exclude="Win98,WinME")]
    public void SomeTest()
    { /* ... */ }
}
Win Win32 Win32S Win32Windows Win32NT WinCE Win95 Win98 WinMe NT3 NT4 NT5 Win2K WinXP Win2003Server Unix Linux Net Net-1.0 Net-1.1 Net-2.0 NetCF SSCLI Rotor Mono
CultureAttribue
  • 테스트가 수행될 언어 환경 설정
namespace NUnit.Tests
{
  using System;
  using NUnit.Framework;

  [TestFixture]
  [Culture("fr-FR")]
  public class FrenchCultureTests
  {
    // ...
  }
}
Posted by Y2K
,
  • 신속한 데이터의 개발
  • Database, XML, Data Array에서 같은 Query를 사용해서 사용 가능

1. metadata의 생성

 [Table(Name = "Customers")] : Table에 Mapping이 되는 것을 나타내는 Attribute
 [Column(IsPrimayKey = true)]
 [Column(Storage=_City)] : Column Mapping을 나타내는 Attribute

[Table(Name = "Customers")]
 public class Customer
 {
     [Column(IsPrimaryKey = true)]
     public string CustomerID;    
     private string _City;

     [Column(Storage = "_City")]
     public string City
     {
         get { return this._City; } 
         set { this._City = value;}
     }
 }

2. DataContext 선언

    : MetaData가 정해져 있는 데이터와의 연결을 선언 (DB Connection과 동일) 

    DataContext db = new DataContext(@"Data Source =(local, Inital Catalog= Northwind... ")
    db.Log = Console.Out;
    Table<Customer> customers = db.GetTable<Customer>();
    var cust = from c in customers 
                    where c.City = "Seoul" SELECT C;

3. Programming...

  

IDE의 이용

  1. LINQ Class 의 추가
  2. DB를 선택, DB Table의 추가
  3. Namespace에 Database에 관한 LINQ Class의 자동 생성
  4. Hall, Dall과 비슷한 소스가 모두 자동으로 생성된다.
    Northwind db = new Northwind();
    var cust = from c in db.Customer 
                    where c.City = "Seoul" SELECT C;
Posted by Y2K
,