예제 #1
0
        public void AddProfileTest()
        {
            ProfileServiceClient client = new ProfileServiceClient();

            Profile profile = new Profile
            {
                Username = "******",
                Password = "******",
                Name = "Bruce",
                Surname = "Wayne",
                Gender = Gender.Male,
                DateOfBirth = DateTime.Parse("31/12/1970"),
                Description = "Batman's profile",
                Email = "*****@*****.**",
                Address = new Address { Street = "Bat Cave", City = "Gotham", PostalCode = "67890" }
            };

            string profileID = client.AddProfile(profile);

            Profile profileFromService = client.GetProfileByID(profileID);

            Assert.AreEqual<string>("batman", profileFromService.Username);
            Assert.AreEqual<string>("Bruce", profileFromService.Name);
            Assert.AreEqual<string>("Wayne", profileFromService.Surname);
            Assert.AreEqual<string>("*****@*****.**", profileFromService.Email);
            Assert.AreEqual<DateTime?>(DateTime.Parse("31/12/1970"), profileFromService.DateOfBirth);
            Assert.AreEqual<string>("Bat Cave", profileFromService.Address.Street);
            Assert.AreEqual<string>("Gotham", profileFromService.Address.City);
            Assert.AreEqual<string>("67890", profileFromService.Address.PostalCode);

            client.DeleteProfile(profileID);

            List<Profile> profiles = client.GetAllProfiles();

            Assert.AreEqual<int>(0, profiles.Count);
        }
예제 #2
0
        static void Main(string[] args)
        {
            ProfileServiceClient client = new ProfileServiceClient("WSHttpBinding_ProfileService");

            // AddProfile
            Profile newProfile = new Profile()
            {
                Username = "******",
                Password = "******",
                Name = "Guillermo",
                Surname = "Schlereth Lamas",
                Email = "*****@*****.**",
                DateOfBirth = DateTime.Parse("12/06/1972"),
                Description = "Hola soy Guillermo",
                Gender = Gender.Male,
                Address = new Address() { Street = "Federico Mompou, 3", City = "Torremolinos", PostalCode = "29620" }
            };

            Guid guilleID = client.AddProfile(newProfile);

            newProfile = new Profile()
            {
                Username = "******",
                Password = "******",
                Name = "Lidia",
                Surname = "Lluch Fuentes",
                Email = "*****@*****.**",
                DateOfBirth = DateTime.Parse("21/07/1973"),
                Description = "Hola soy Lidia",
                Gender = Gender.Female,
                Address = new Address() { Street = "Federico Mompou, 3", City = "Torremolinos", PostalCode = "29620" }
            };

            Guid lidiaID = client.AddProfile(newProfile);

            newProfile = new Profile()
            {
                Username = "******",
                Password = "******",
                Name = "Liam",
                Surname = "Schlereth Lluch",
                Email = "*****@*****.**",
                DateOfBirth = DateTime.Parse("25/03/2008"),
                Description = "Hola soy Liam",
                Gender = Gender.Male,
                Address = new Address() { Street = "Federico Mompou, 3", City = "Torremolinos", PostalCode = "29620" }
            };

            Guid liamID = client.AddProfile(newProfile);

            // CreateProfile
            Guid sergioID = client.CreateProfile("sergio", "admin123", "*****@*****.**", "Sergio", "Schlereth Lamas");
            Guid mariaID = client.CreateProfile("mariluz", "admin123", "*****@*****.**", "Mariluz", "Schlereth Lamas");
            Guid pericoID = client.CreateProfile("perico", "admin123", "*****@*****.**", "Pedro", "Delgado");

            // GetAllProfiles
            List<Profile> allProfiles = client.GetAllProfiles();
            WriteProfiles(allProfiles, "All profiles -->");

            // GetProfileByID and GetProfileByCredentials
            Profile liamProfile = client.GetProfileByID(liamID);
            Profile sergioProfile = client.GetProfileByID(sergioID);
            Profile lidiaProfile = client.GetProfileByCredentials("lidia", "admin123");

            List<Profile> selectProfiles = new List<Profile>();
            selectProfiles.Add(liamProfile);
            selectProfiles.Add(sergioProfile);
            selectProfiles.Add(lidiaProfile);
            WriteProfiles(selectProfiles, "Liam, Sergio and Lidia profiles -->");

            // ModifyProfile
            sergioProfile.Description = "Hola soy Sergio ...";
            sergioProfile.Email = "*****@*****.**";
            sergioProfile.DateOfBirth = DateTime.Parse("25/06/1986");
            sergioProfile.Gender = Gender.Male;
            sergioProfile.Address = new Address
            {
                Street = "Avda. Bellamina, 3",
                City = "Torremolinos",
                PostalCode = "29620"
            };

            client.ModifyProfile(sergioProfile);
            WriteProfiles(new List<Profile>() { client.GetProfileByID(sergioID) }, "Sergio profile modified -->");

            // DeleteProfile
            client.DeleteProfile(pericoID);
            WriteProfiles(client.GetAllProfiles(), "Perico profile deleted -->");

            // SearchProfiles
            ProfileFilter filter = new ProfileFilter()
            {
                Street = "Mompou"
            };

            List<Profile> searchResult = client.SearchProfiles(filter);
            WriteProfiles(searchResult, "Profiles living in Mompou street -->");

            // AddContact
            client.AddContact(guilleID, lidiaID);
            client.AddContact(guilleID, liamID);

            // AddContacts
            client.AddContacts(guilleID, new List<Guid>() { sergioID, mariaID });

            // GetContacts
            WriteProfiles(client.GetContacts(guilleID), "Guille contacts -->");

            // RemoveContact
            client.RemoveContact(guilleID, sergioID);
            WriteProfiles(client.GetContacts(guilleID), "Sergio removed from guille contacts -->");

            // RemoveAllContacts
            client.RemoveAllContacts(guilleID);
            WriteProfiles(client.GetContacts(guilleID), "Guille contacts removed -->");

            // Delete Profiles
            client.DeleteProfile(guilleID);
            client.DeleteProfile(lidiaID);
            client.DeleteProfile(sergioID);
            client.DeleteProfile(mariaID);
            client.DeleteProfile(liamID);

            WriteProfiles(client.GetAllProfiles(), "All contacts deleted -->");

            Console.ReadLine();
        }