Introducing Windows Azure- P31 ppsx

5 281 0
Introducing Windows Azure- P31 ppsx

Đang tải... (xem toàn văn)

Thông tin tài liệu

CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 123 } set { if ((object.ReferenceEquals(this.LastNameField, value) != true)) { this.LastNameField = value; this.RaisePropertyChanged("LastName"); } } } [System.Runtime.Serialization.DataMemberAttribute()] public string Password { get { return this.PasswordField; } set { if ((object.ReferenceEquals(this.PasswordField, value) != true)) { this.PasswordField = value; this.RaisePropertyChanged("Password"); } } } [System.Runtime.Serialization.DataMemberAttribute()] public System.DateTime TimeRegistered { get { return this.TimeRegisteredField; } set { if ((this.TimeRegisteredField.Equals(value) != true)) { this.TimeRegisteredField = value; this.RaisePropertyChanged("TimeRegistered"); } } } public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; protected void RaisePropertyChanged(string propertyName) { System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged; if ((propertyChanged != null)) { propertyChanged( this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); } } } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] [System.ServiceModel.ServiceContractAttribute( ConfigurationName="HostWCFService.IUserRegisterService")] public interface IUserRegisterService { [System.ServiceModel.OperationContractAttribute( CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 124 Action="http://tempuri.org/IUserRegisterService/AddUser", ReplyAction="http://tempuri.org/IUserRegisterService/AddUserResponse")] void AddUser(HostWCFSrviceUnitTest.HostWCFService.User user); [System.ServiceModel.OperationContractAttribute( Action="http://tempuri.org/IUserRegisterService/GetUserList", ReplyAction="http://tempuri.org/IUserRegisterService/GetUserListResponse")] HostWCFSrviceUnitTest.HostWCFService.User[] GetUserList(); } [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] public interface IUserRegisterServiceChannel : HostWCFSrviceUnitTest.HostWCFService.IUserRegisterService, System.ServiceModel.IClientChannel { } [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] public partial class UserRegisterServiceClient : System.ServiceModel.ClientBase <HostWCFSrviceUnitTest.HostWCFService.IUserRegisterService>, HostWCFSrviceUnitTest.HostWCFService.IUserRegisterService { public UserRegisterServiceClient() { } public UserRegisterServiceClient(string endpointConfigurationName) : base(endpointConfigurationName) { } public UserRegisterServiceClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public UserRegisterServiceClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress) { } public UserRegisterServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : base(binding, remoteAddress) { } public void AddUser(HostWCFSrviceUnitTest.HostWCFService.User user) { base.Channel.AddUser(user); } public HostWCFSrviceUnitTest.HostWCFService.User[] GetUserList() { return base.Channel.GetUserList(); } } } 9. Compile the solution, and we are ready to test the results. CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 125 10. Add two unit test cases and test initialization code into the HostWCFServiceUnitTest project as in Listing 4-7. Listing 4-7. Unit Test Cases for WCF Service Hosted in Azure using System; using System.Text; using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace HostWCFSrviceUnitTest { using HostWCFService WebRole; using NUnit.Framework; [TestFixture] [TestClass] public class HostWCFClientUnitTest { private HostWCFService.UserRegisterServiceClient userRegisterServiceClient = null; public HostWCFClientUnitTest() { } private TestContext testContextInstance; public TestContext TestContext { get { return testContextInstance; } set { testContextInstance = value; } } #region Additional test attributes [TestInitialize()] [SetUp] public void MyTestInitialize() { userRegisterServiceClient = new HostWCFSrviceUnitTest.HostWCFService.UserRegisterServiceClient( "WSHttpBinding IUserRegisterService" ); } CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 126 #endregion [TestMethod] [Test] public void TestRegisterUser() { HostWCFService.User user = new HostWCFService.User(); user.FirstName = "Henry"; user.LastName = "Li"; user.Password = "Hello Azure WCF host"; userRegisterServiceClient.AddUser(user); } [TestMethod] [Test] public void TestGetUserList() { TestRegisterUser(); HostWCFService.User[] users = (HostWCFService.User[]) userRegisterServiceClient.GetUserList(); Assert.IsTrue(users.Count<HostWCFService.User>() > 0 ); } } } 11. To test a single unit test case using the Visual Studio test framework, mouse over to the context of the specific test code body in Visual Studio and set a break point for debugging purposes as Figure 4-5 shows. Figure 4-5. Mouse over the test code body and right-click to bring up the context menu to run a single test case from the context in Visual Studio 12. If you want to test the entire test suite you can simply press the F5 key or select Debug ➤ Start Debugging. The program will stop at the break point, and an icon in the system tray will indicate that the WCF service has been hosted in HostWCFService WebRole, as Figure 4-6 shows. Mouse over the variable users, and the instance watch dialog windows should display the data we have just added via the WCF service. The data is stored in the memory and is the local instance of List<User> userList = new List<User>() defined in the UserRegisterService class. CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 127 Figure 4-6. Icon from system tray shows the WCF service has been hosted from HostWCFService WebRole Verify HostWCFService from the Local Development Environment Set HostWCFService as the startup project and run from Visual Studio by pressing F5. When the service host icon shows from the system tray as in Figure 4-6 and the instance is shown in the local fabric as shown in Figure 4-7, start Internet Explorer and enter http://localhost:8080/UserRegisterService in the address bar to retrieve the metadata from the service. The results are shown in Figure 4-8. Figure 4-7. The WCF service is hosted from the local development cloud and run from the local fabric . CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 123 } set { if ((object.ReferenceEquals(this.LastNameField,. interface IUserRegisterService { [System.ServiceModel.OperationContractAttribute( CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 124 Action="http://tempuri.org/IUserRegisterService/AddUser",. base.Channel.GetUserList(); } } } 9. Compile the solution, and we are ready to test the results. CHAPTER 4 ■ WINDOWS AZURE APPLICATION INTEGRATION USING WCF 125 10. Add two unit test cases and test

Ngày đăng: 05/07/2014, 01:20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan