Presentation is loading. Please wait.

Presentation is loading. Please wait.

demo public WebService(IWarehouse store) { } this.store = store;

Similar presentations


Presentation on theme: "demo public WebService(IWarehouse store) { } this.store = store;"— Presentation transcript:

1

2

3

4 demo

5 public WebService(IWarehouse store) { } this.store = store;

6 public WebService(IWarehouse store) { } this.store = store; Contract.Requires(store != null);

7 public WebService(IWarehouse store) { } Contract.Requires(store != null); Contract.Ensures(this.store != null); this.store = store;

8 [ContractInvariantMethod] void ObjectInvariant() { Contract.Invariant(this.store != null); }

9 public interface IWarehouse { … } [ContractClass(typeof(IWarehouseContract))] public interface IWarehouse { … } [ContractClassFor(typeof(IWarehouse))] public class IWarehouseContract : IWarehouse { Item IWarehouse.RemoveFromInventory(int productID) { Contract.Ensures(Contract.Result () != null); … } … }

10 public interface IWarehouse { … } [ContractClass(typeof(IWarehouseContract))] public interface IWarehouse { … } [ContractClassFor(typeof(IWarehouse))] public class IWarehouseContract : IWarehouse { Item IWarehouse.RemoveFromInventory(int productID) { Contract.Ensures(Contract.Result () != null); … } … }

11 public interface IWarehouse { … } [ContractClass(typeof(IWarehouseContract))] public interface IWarehouse { … } [ContractClassFor(typeof(IWarehouse))] public class IWarehouseContract : IWarehouse { Item IWarehouse.RemoveFromInventory(int productID) { Contract.Ensures(Contract.Result () != null); … } … }

12

13 WebService.cs WebService.dll IL from body IL from requires IL from ensures csc/vbc/… + ccrewrite public WebService(IWarehouse store) { } this.store = store; Contract.Requires(store != null); Contract.Ensures(this.store != null);

14 WebService.cs WebService.dll IL from body IL from requires csc/vbc/… + ccrewrite public WebService(IWarehouse store) { } this.store = store; Contract.Requires(store != null); Contract.Ensures(this.store != null);

15 WebService.cs WebService.dll IL from body csc/vbc/… public WebService(IWarehouse store) { } this.store = store; Contract.Requires(store != null); Contract.Ensures(this.store != null);

16 WebService.xml WebService.Contracts.dll IL from requires IL from ensures Constructs a new instance for processing orders against the specified warehouse. The warehouse this instance is to use. WebService.xml Constructs a new instance for processing orders against the specified warehouse. The warehouse this instance is to use. store != null this.store != null ccdocgen

17 [PexMethod] public void Process(WebService target, Order order) { target.Process(order); // TODO: Add assertions here }

18 [PexMethod] public void Process(WebService target, Order order) { target.Process(order); // TODO: Add assertions here }

19 [PexMethod] public void Process(WebService target, Order order) { target.Process(order); // TODO: Add assertions here }

20 [PexMethod] public void Process(WebService target, Order order) { target.Process(order); }

21 [PexMethod] public void Process(WebService target, Order order) { target.Process(order); }

22 [PexMethod] public void Process(WebService target, Order order) { target.Process(order); }

23 [PexMethod] public void Process( [PexAssumeUnderTest] WebService target, Order order) { target.Process(order); }

24 [PexMethod] public void Process( [PexAssumeUnderTest] WebService target, Order order) { target.Process(order); } public void Process(Order order) { if (order == null) return; for (int i = 0; i < order.Quantity; i++) { var item = store.RemoveFromInventory(order.ProductID); store.ShipToCustomer(order.UserName, item.ItemID); }

25 public void Process(Order order) { if (order == null) return; for (int i = 0; i < order.Quantity; i++) { var item = store.RemoveFromInventory(order.ProductID); store.ShipToCustomer(order.UserName, item.ItemID); } [PexMethod] public void Process( [PexAssumeUnderTest] WebService target, Order order) { target.Process(order); }

26 public void Process(Order order) { if (order == null) return; for (int i = 0; i < order.Quantity; i++) { var item = store.RemoveFromInventory(order.ProductID); store.ShipToCustomer(order.UserName, item.ItemID); } [PexMethod] public void Process( [PexAssumeUnderTest] WebService target, Order order) { target.Process(order); }

27 public void Process(Order order) { if (order == null) return; for (int i = 0; i < order.Quantity; i++) { var item = store.RemoveFromInventory(order.ProductID); store.ShipToCustomer(order.UserName, item.ItemID); } [PexMethod] public void Process( [PexAssumeUnderTest] WebService target, Order order) { target.Process(order); }

28 public void Process(Order order) { if (order == null) return; for (int i = 0; i < order.Quantity; i++) { var item = store.RemoveFromInventory(order.ProductID); store.ShipToCustomer(order.UserName, item.ItemID); } [PexMethod] public void Process( [PexAssumeUnderTest] WebService target, Order order) { target.Process(order); } [TestMethod] public void Process03() { var webService = new WebService((IWarehouse)null); var order = new Order((string)null, 0, 1); this.Process(webService, order); } [TestMethod] public void Process03() { var webService = new WebService((IWarehouse)null); var order = new Order((string)null, 0, 1); this.Process(webService, order); }

29 public void Process(Order order) { if (order == null) return; for (int i = 0; i < order.Quantity; i++) { var item = store.RemoveFromInventory(order.ProductID); store.ShipToCustomer(order.UserName, item.ItemID); } [PexMethod] public void Process( [PexAssumeUnderTest] WebService target, Order order) { target.Process(order); }

30 IWarehouse store; public void Process(Order order) { if (order == null) return; for (int i = 0; i < order.Quantity; i++) { var item = store.RemoveFromInventory(order.ProductID); store.ShipToCustomer(order.UserName, item.ItemID); } interface IWarehouse { … }

31

32

33

34

35 interface IWarehouse { // hand-written void ShipToCustomer(string userName, int itemID); … } class SIWarehouse : IWarehouse { // generated Action ShipToCustomerStringInt32 { get; set; } void IWarehouse.ShipToCustomer(string userName, int itemID) { return ShipToCustomerStringInt32(userName, itemID); } … }

36 interface IWarehouse { // hand-written void ShipToCustomer(string userName, int itemID); … } class SIWarehouse : IWarehouse { // generated Action ShipToCustomerStringInt32 { get; set; } void IWarehouse.ShipToCustomer(string userName, int itemID) { return ShipToCustomerStringInt32(userName, itemID); } … }

37 [PexMethod] public void ProcessOrderAndCheckQuantity(Order order) { int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (name, id) => count++ }; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

38 [PexMethod] public void ProcessOrderAndCheckQuantity(Order order) { int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (name, id) => count++ }; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

39 [PexMethod] public void ProcessOrderAndCheckQuantity(Order order) { int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (name, id) => count++ }; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

40 [PexMethod] public void ProcessOrderAndCheckQuantity(Order order) { int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (name, id) => count++ }; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); } delegate(string name, int id) { count++; } delegate(string name, int id) { count++; }

41 [PexMethod] public void ProcessOrderAndCheckQuantity(Order order) { int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (name, id) => count++ }; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); } var warehouse = new SIWarehouse(); warehouse.ShipToCustomerStringInt32 =...; var warehouse = new SIWarehouse(); warehouse.ShipToCustomerStringInt32 =...;

42 [PexMethod] public void ProcessOrderAndCheckQuantity(Order order) { int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (name,id)=> count++ }; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

43 [PexMethod] public void ProcessOrderAndCheckQuantity(Order order) { int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (name, id) => count++ }; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

44 [PexMethod] public void ProcessOrderAndCheckQuantity(Order order) { Contract.Assume(order != null); int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (name, id) => count++ }; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

45 demo

46 public void Process(Order order) { if (order == null) return; for (int i = 0; i < order.Quantity; i++) { var item = store.RemoveFromInventory(order.ProductID); if (DateTime.Now != new DateTime(2000, 1, 1)) store.ShipToCustomer(order.UserName, item.ItemID); }

47 DateTime.Now = () => new DateTime(2000, 1, 1);

48 MDateTime.NowGet = () => new DateTime(2000, 1, 1);

49

50

51

52 [PexMethod] public void ProcessOrderAndCheckQuantityMoles(Order order, DateTime now) { Contract.Assume(order != null); int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (userName, id) => count++ }; MDateTime.NowGet = () => now; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

53 [PexMethod] public void ProcessOrderAndCheckQuantityMoles(Order order, DateTime now) { Contract.Assume(order != null); int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (userName, id) => count++ }; MDateTime.NowGet = () => now; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

54 [PexMethod] public void ProcessOrderAndCheckQuantityMoles(Order order, DateTime now) { Contract.Assume(order != null); int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (userName, id) => count++ }; MDateTime.NowGet = () => now; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

55 [PexMethod] public void ProcessOrderAndCheckQuantityMoles(Order order, DateTime now) { Contract.Assume(order != null); int count = 0; var warehouse = new SIWarehouse() { ShipToCustomerStringInt32 = (userName, id) => count++ }; MDateTime.NowGet = () => now; var target = new WebService(warehouse); target.Process(order); Contract.Assert(order.Quantity == count); }

56 demo

57

58

59

60

61

62 Built by Developers for Developers….

63 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

64


Download ppt "demo public WebService(IWarehouse store) { } this.store = store;"

Similar presentations


Ads by Google