示例#1
0
        public void MockWhatsYourId()
        {
            string val = "59bb09f7-df66-45d0-9bcc-79c2d4d2ced1";
            string actualRetVal;

            // mock wcf interface
            Mock <IPaymentService> wcfMock = new Mock <IPaymentService>();

            // setup for wcf service WhatsYourId method
            wcfMock.Setup <string>(s => s.WhatsYourId()).Returns(val);

            // create object to register with IoC
            IPaymentService wcfMockObject = wcfMock.Object;

            // register instance
            UnityHelper.IoC = new UnityContainer();
            UnityHelper.IoC.RegisterInstance <IPaymentService>(wcfMockObject);

            // create ServiceAgent object using parameterized constructor (for unit test)
            PaymentServiceAgent serviceAgent = new PaymentServiceAgent(true);

            // method call to be tested
            actualRetVal = serviceAgent.GetID();

            // verify if the expected method called during test or not
            wcfMock.Verify(s => s.WhatsYourId(), Times.Exactly(1));

            Assert.AreEqual("59bb09f7-df66-45d0-9bcc-79c2d4d2ced1", actualRetVal, "Not same.");
        }
示例#2
0
        public override Product Create(string description)
        {
            Target client = new ShippingAgent("Shipping");

            client.Link = "URL to Shipping Service";
            Target paymentClient = new PaymentServiceAgent("Payment");

            paymentClient.Link = "URL to Payment Services";

            Product physicalProduct = new PhysicalProduct(description);

            physicalProduct.Outputs = new List <Output>();
            physicalProduct.Outputs.Add(new PackingSlip("Original Packing Slip", physicalProduct, client));
            physicalProduct.Outputs.Add(new PackingSlip("Commission Payment", physicalProduct, paymentClient));

            return(physicalProduct);
        }
        public override Product Create(string description)
        {
            Target shippingClient = new ShippingAgent("Shipping");

            shippingClient.Link = "URL to Shipping Service";
            Target royaltyClient = new RoyaltyDepartmentClient("Royalty Department");

            royaltyClient.Link = "URL to Royalty Department Service";
            Target paymentClient = new PaymentServiceAgent("Payment");

            paymentClient.Link = "URL to Payment Services";

            Product book = new Book(description);

            book.Outputs = new List <Output>();
            book.Outputs.Add(new PackingSlip("Original Packing Slip", book, shippingClient));
            book.Outputs.Add(new PackingSlip("Duplicate Packing Slip", book, royaltyClient));
            book.Outputs.Add(new PackingSlip("Commission Payment", book, paymentClient));

            return(book);
        }