public void CheckInTest_確定需買票人數() { //arrange decimal expected = 2; //act var actual = pub.CheckIn(_customerList); //assert Assert.AreEqual(expected, actual); }
public void CheckInTest_Customer_2女1男_應收費人數為1() { //arrange ICheckInFee stubCheckInFee = MockRepository.GenerateStub <ICheckInFee>(); Pub target = new Pub(stubCheckInFee); stubCheckInFee.Stub(x => x.GetFee(Arg <Customer> .Is.Anything)).Return(100); var customers = new List <Customer> { new Customer { IsMale = true }, new Customer { IsMale = false }, new Customer { IsMale = false }, }; decimal expected = 1; //act var actual = target.CheckIn(customers); //assert Assert.AreEqual(expected, actual); }
public void Test_Friday_Charge_Customer_Count() { //arrange ICheckInFee stubCheckInFee = MockRepository.GenerateStub <ICheckInFee>(); var fakeTimeWrapper = new FakeTimeWrapper(); fakeTimeWrapper.MockTime = Convert.ToDateTime("2021/04/09"); //friday Pub target = new Pub(stubCheckInFee, fakeTimeWrapper); stubCheckInFee.Stub(x => x.GetFee(Arg <Customer> .Is.Anything)).Return(100); var customers = new List <Customer> { new Customer { IsMale = true }, new Customer { IsMale = false }, new Customer { IsMale = false }, }; decimal expected = 1; //act var actual = target.CheckIn(customers); //assert Assert.AreEqual(expected, actual); }
public void GetInComeTest() { //arrange ICheckInFee stubCheckInFee = MockRepository.GenerateStub <ICheckInFee>(); Pub target = new Pub(stubCheckInFee); stubCheckInFee.Stub(x => x.GetFee(Arg <Customer> .Is.Anything)).Return(100); var customers = new List <Customer> { new Customer { IsMale = true }, new Customer { IsMale = true }, new Customer { IsMale = false } }; var inComeBeforeCheckIn = target.GetInCome(); Assert.AreEqual(0, inComeBeforeCheckIn); decimal expectedIncome = 200; //act var chargeCustomerCount = target.CheckIn(customers); var actualIncome = target.GetInCome(); //assert Assert.AreEqual(expectedIncome, actualIncome); }
private static int DoTest() { //准备测试桩 var stubCheckInFee = new StubICheckInFee { //需要注入的方法:方法名<参数列表> GetFeeCustomer = GetFeeCustomer }; //用Stub装配Pub实例 var target = new Pub(stubCheckInFee); //准备测试数据 var customers = new List <Customer> { new Customer { Gender = Gender.Male }, new Customer { Gender = Gender.Female }, new Customer { Gender = Gender.Transgender }, }; //act var actual1 = target.CheckIn(customers); var actual = actual1; return(actual); }
public void Test_Customer_2女1男_收費標準100_Income應為100() { //arrange ICheckInFee stubCheckInFee = MockRepository.GenerateStub<ICheckInFee>(); Pub target = new Pub(stubCheckInFee); stubCheckInFee.Stub(x => x.GetFee(Arg<Customer>.Is.Anything)).Return(100); var customers = new List<Customer> { new Customer{ IsMale=true}, new Customer{ IsMale=false}, new Customer{ IsMale=false}, }; var inComeBeforeCheckIn = target.GetInCome(); Assert.AreEqual(0, inComeBeforeCheckIn); decimal expectedIncome = 100; //act var chargeCustomerCount = target.CheckIn(customers); var actualIncome = target.GetInCome(); //assert Assert.AreEqual(expectedIncome, actualIncome); }
public void CheckInTest_顧客1男2女_應回傳收費人數1人_使用NSubstitute物件() { //arrange準備受測物件、參數、預期結果 ICheckInFee CheckInFee = Substitute.For <ICheckInFee>(); Pub pub = new Pub(CheckInFee); CheckInFee.GetFee(Arg.Any <Customer>()).Returns(100); List <Customer> customers = new List <Customer> { new Customer { IsMale = true }, new Customer { IsMale = false }, new Customer { IsMale = false }, }; decimal expected = 1; //act執行受測方法 decimal actual = pub.CheckIn(customers); //assert驗證執行結果與預測結果是否一致 Assert.AreEqual(expected, actual); }
public void Test_ChargeCustomer_Count() { //arrange ICheckInFee stubCheckInFee = MockRepository.GenerateStub <ICheckInFee>(); Pub target = new Pub(stubCheckInFee); var customers = new List <Customer> { new Customer() { IsMale = true }, new Customer() { IsMale = false }, new Customer() { IsMale = false }, }; decimal expected = 1; //act var actual = target.CheckIn(customers); //assert Assert.AreEqual(expected, actual); }
public void Test_Charge_Customer_Count() { ICheckInFee stubCheckInFee = MockRepository.GenerateStub <ICheckInFee>(); Pub target = new Pub(stubCheckInFee); stubCheckInFee.Stub(x => x.GetFee(Arg <Customer> .Is.Anything)).Return(100); var customers = new List <Customer> { new Customer { IsMale = true }, new Customer { IsMale = false }, new Customer { IsMale = false } }; decimal expected = 1; var actual = target.CheckIn(customers); Assert.AreEqual(expected, actual); }
public void Test_Income_顧客1男2女_應回傳收費人數1人_模擬每一人收費為100元_預期結果門票收入總數為100_使用RhinoMocks物件() { //arrange ICheckInFee stubCheckInFee = MockRepository.GenerateStub <ICheckInFee>(); Pub target = new Pub(stubCheckInFee); stubCheckInFee.Stub(x => x.GetFee(Arg <Customer> .Is.Anything)).Return(100); var customers = new List <Customer> { new Customer { IsMale = true }, new Customer { IsMale = false }, new Customer { IsMale = false }, }; var inComeBeforeCheckIn = target.GetInCome(); Assert.AreEqual(0, inComeBeforeCheckIn); decimal expectedIncome = 100; //act var chargeCustomerCount = target.CheckIn(customers); var actualIncome = target.GetInCome(); //assert Assert.AreEqual(expectedIncome, actualIncome); }
public void CheckInTest_顧客1男2女_應回傳收費人數1人_使用RhinoMocks物件() { //arrange準備受測物件、參數、預期結果 ICheckInFee stubCheckInFee = MockRepository.GenerateStub <ICheckInFee>(); Pub target = new Pub(stubCheckInFee); stubCheckInFee.Stub(x => x.GetFee(Arg <Customer> .Is.Anything)).Return(100); var customers = new List <Customer> { new Customer { IsMale = true }, new Customer { IsMale = false }, new Customer { IsMale = false }, }; decimal expected = 1; //act執行受測方法 var actual = target.CheckIn(customers); //assert驗證執行結果與預測結果是否一致 Assert.AreEqual(expected, actual); }
public void Test_Income_顧客1男2女_應回傳收費人數1人_模擬每一人收費為100元_預期結果門票收入總數為100_使用NSubstitute物件() { //arrange準備受測物件、參數、預期結果 ICheckInFee CheckInFee = Substitute.For <ICheckInFee>(); Pub pub = new Pub(CheckInFee); CheckInFee.GetFee(Arg.Any <Customer>()).Returns(100); List <Customer> customers = new List <Customer> { new Customer { IsMale = false }, new Customer { IsMale = true }, new Customer { IsMale = false }, }; var inComeBeforeCheckIn = pub.GetInCome(); Assert.AreEqual(0, inComeBeforeCheckIn); decimal expectedIncome = 100; //act執行受測方法 decimal chargeCustomerCount = pub.CheckIn(customers); decimal actualIncome = pub.GetInCome(); //assert驗證執行結果與預測結果是否一致 Assert.AreEqual(expectedIncome, actualIncome); }
public void CheckInTest_Mock確認程式被執行次數() { //arrange ICheckInFee stubCheckInFree = Substitute.For <ICheckInFee>(); stubCheckInFree.GetFree(Arg.Any <Customer>()).Returns(100); Pub pub = new Pub(stubCheckInFree); var customers = new List <Customer> { new Customer { IsMale = true }, new Customer { IsMale = true }, new Customer { IsMale = false }, }; var inComeBeforeCheckIn = pub.GetInCome; Assert.AreEqual(0, inComeBeforeCheckIn); decimal expectedIncome = 200; //act var actual = pub.CheckIn(customers); var actualIncome = pub.GetInCome; //assert Assert.AreEqual(expectedIncome, actualIncome); }
public void CheckInTest_2男1女_與ICheckInFee互動2次() { //arrange mock var customers = new List <Customer>(); //2男1女 var customer1 = new Customer { IsMale = true, Seq = 1 }; var customer2 = new Customer { IsMale = false, Seq = 2 }; var customer3 = new Customer { IsMale = true, Seq = 3 }; customers.Add(customer1); customers.Add(customer2); customers.Add(customer3); MockRepository mock = new MockRepository(); ICheckInFee stubCheckInFee = mock.StrictMock <ICheckInFee>(); using (mock.Record()) { //期望呼叫ICheckInFee的GetFee()次數為2次 //且第一次的參數為customer1, 第二次的參數為customer3 stubCheckInFee.GetFee(customer1); LastCall .Return((decimal)100); stubCheckInFee.GetFee(customer3); LastCall .Return((decimal)200); ////若不需要檢查傳入參數,只需要確認呼叫次數為2次,可以這樣寫 //stubCheckInFee.GetFee(customer1); //LastCall // .IgnoreArguments().Return((decimal)200) // .Repeat.Times(2); } using (mock.Playback()) { var target = new Pub(stubCheckInFee); var count = target.CheckIn(customers); } }
public void ChargeCustomerCountTest() { using (ShimsContext.Create()) { System.Fakes.ShimDateTime.TodayGet = () => new DateTime(2017, 8, 18); Console.WriteLine("test is begine..."); //准备测试桩 var stubCheckInFee = new StubICheckInFee { //需要注入的方法:方法名<参数列表> GetFeeCustomer = customer => 100m }; //用Stub装配Pub实例 var target = new Pub(stubCheckInFee); //准备测试数据 var customers = new List <Customer> { new Customer { Gender = Gender.Male }, new Customer { Gender = Gender.Female }, new Customer { Gender = Gender.Transgender }, }; //act var actual1 = target.CheckIn(customers); var actual = actual1; decimal expected = 1; //assert Assert.AreEqual(expected, actual); } }
public void Test_CheckIn_Charge_Only_Male() { //arrange mock var customers = new List <Customer>(); //2男1女 var customer1 = new Customer() { IsMale = true }; var customer2 = new Customer() { IsMale = true }; var customer3 = new Customer() { IsMale = false }; customers.Add(customer1); customers.Add(customer2); customers.Add(customer3); MockRepository mock = new MockRepository(); ICheckInFee stubCheckInFee = mock.StrictMock <ICheckInFee>(); using (mock.Record()) { //期望呼叫ICheckInFee的GetFee()次數為2次 stubCheckInFee.GetFee(customer1); LastCall .IgnoreArguments() .Return((decimal)100) .Repeat.Times(2); } using (mock.Playback()) { var target = new Pub(stubCheckInFee); var count = target.CheckIn(customers); } }
public void Test_Friday_Charge_Customer_Count() { using (ShimsContext.Create()) { System.Fakes.ShimDateTime.TodayGet = () => { //2012/10/19為Friday return(new DateTime(2012, 10, 19)); }; //arrange ICheckInFee stubCheckInFee = MockRepository.GenerateStub <ICheckInFee>(); Pub target = new Pub(stubCheckInFee); stubCheckInFee.Stub(x => x.GetFee(Arg <Customer> .Is.Anything)).Return(100); var cusomers = new List <Customer> { new Customer() { IsMale = true }, new Customer() { IsMale = false }, new Customer() { IsMale = false }, }; decimal expected = 1; //act var actual = target.CheckIn(cusomers); //assert Assert.AreEqual(expected, actual); } }
public void CheckInTest_Customer_2女1男_應收費人數為1() { //arrange ICheckInFee stubCheckInFee = MockRepository.GenerateStub<ICheckInFee>(); Pub target = new Pub(stubCheckInFee); stubCheckInFee.Stub(x => x.GetFee(Arg<Customer>.Is.Anything)).Return(100); var customers = new List<Customer> { new Customer{ IsMale=true}, new Customer{ IsMale=false}, new Customer{ IsMale=false}, }; decimal expected = 1; //act var actual = target.CheckIn(customers); //assert Assert.AreEqual(expected, actual); }
public void Test_Income() { //arrange ICheckInFee stubCheckInFee = MockRepository.GenerateStub <ICheckInFee>(); var fakeTimeWrapper = new FakeTimeWrapper(); fakeTimeWrapper.MockTime = Convert.ToDateTime("2021/04/09"); Pub target = new Pub(stubCheckInFee, fakeTimeWrapper); stubCheckInFee.Stub(x => x.GetFee(Arg <Customer> .Is.Anything)).Return(100); var customers = new List <Customer> { new Customer { IsMale = true }, new Customer { IsMale = false }, new Customer { IsMale = false }, }; var inComeBeforeCheckIn = target.GetInCome(); Assert.AreEqual(0, inComeBeforeCheckIn); decimal expectedIncome = 100; //act var chargeCustomerCount = target.CheckIn(customers); var actualIncome = target.GetInCome(); //assert Assert.AreEqual(expectedIncome, actualIncome); }
public void CheckInTest_2男1女_與ICheckInFee互動2次() { //arrange mock var customers = new List<Customer>(); //2男1女 var customer1 = new Customer { IsMale = true, Seq = 1 }; var customer2 = new Customer { IsMale = false, Seq = 2 }; var customer3 = new Customer { IsMale = true, Seq = 3 }; customers.Add(customer1); customers.Add(customer2); customers.Add(customer3); MockRepository mock = new MockRepository(); ICheckInFee stubCheckInFee = mock.StrictMock<ICheckInFee>(); using (mock.Record()) { //期望呼叫ICheckInFee的GetFee()次數為2次 //且第一次的參數為customer1, 第二次的參數為customer3 stubCheckInFee.GetFee(customer1); LastCall .Return((decimal)100); stubCheckInFee.GetFee(customer3); LastCall .Return((decimal)200); ////若不需要檢查傳入參數,只需要確認呼叫次數為2次,可以這樣寫 //stubCheckInFee.GetFee(customer1); //LastCall // .IgnoreArguments().Return((decimal)200) // .Repeat.Times(2); } using (mock.Playback()) { var target = new Pub(stubCheckInFee); var count = target.CheckIn(customers); } }