示例#1
0
文件: TestSuite2.cs 项目: ltj/rentit
        public void GetAlbumInfoTest4()
        {
            RentItClient target = new RentItClient();
            int id = 70;

            AlbumInfo actual = target.GetAlbumInfo(id);
        }
示例#2
0
文件: TestSuite1.cs 项目: ltj/rentit
 public void GetAllCustomerDataExceptionTestTwo()
 {
     RentItClient target = new RentItClient();
     AccountCredentials credentials = new AccountCredentials
     {
         UserName = "******",
         HashedPassword = "******"
     };
     target.GetAllCustomerData(credentials);
 }
示例#3
0
文件: TestSuite2.cs 项目: ltj/rentit
        public void GetAlbumInfoTest2()
        {
            RentItClient target = new RentItClient();

            // The album indentified by id 78 has only 2 songs.
            int id = 78;
            AlbumInfo actual = target.GetAlbumInfo(id);

            Assert.AreEqual(2, actual.Songs.Length);
        }
示例#4
0
文件: TestSuite1.cs 项目: ltj/rentit
 public void GetAllCustomerDataExceptionTestOne()
 {
     RentItClient target = new RentItClient();
     AccountCredentials credentials = new AccountCredentials
     {
         UserName = "******",
         HashedPassword = "******"
     };
     target.GetAllCustomerData(credentials);
 }
示例#5
0
文件: TestSuite1.cs 项目: ltj/rentit
 public void GetAllPublisherDataExceptionTestOne()
 {
     RentItClient target = new RentItClient();
     AccountCredentials credentials = new AccountCredentials
     {
         UserName = "******",
         HashedPassword = "******"
     };
     target.GetAllPublisherData(credentials);
 }
示例#6
0
文件: TestSuite3.cs 项目: ltj/rentit
 public void CreateNewUserTest2()
 {
     RentItClient target = new RentItClient();
     Account newAccount = new Account {
         UserName = "******",
         FullName = "Test Testesen",
         Email = "*****@*****.**",
         HashedPassword = "******"
     };
     target.CreateNewUser(newAccount);
 }
示例#7
0
文件: TestSuite2.cs 项目: ltj/rentit
        public void GetAlbumInfoTest1()
        {
            RentItClient target = new RentItClient();

            // Get the album indentified by the media id 78.
            int id = 78;
            AlbumInfo actual = target.GetAlbumInfo(id);

            Assert.AreNotEqual(null, actual);
            Assert.AreEqual("The Cure", actual.AlbumArtist);
            Assert.AreEqual("The Greatest Hits", actual.Title);
        }
示例#8
0
文件: TestSuite1.cs 项目: ltj/rentit
 public void GetAllCustomerDataTest()
 {
     RentItClient target = new RentItClient();
     AccountCredentials credentials = new AccountCredentials
     {
         UserName = "******",
         HashedPassword = "******"
     };
     UserAccount actual = target.GetAllCustomerData(credentials);
     Assert.AreEqual("user21", actual.UserName);
     Assert.AreEqual("*****@*****.**", actual.Email);
     Assert.AreEqual("user21", actual.FullName);
     Assert.AreEqual("a1881c06eec96db9901c7bbfe41c42a3f08e9cb4", actual.HashedPassword);
     Assert.AreEqual(0, actual.Credits);
 }
示例#9
0
文件: TestSuite3.cs 项目: ltj/rentit
 public void CreateNewUserTest()
 {
     RentItClient target = new RentItClient();
     Account newAccount = new Account {
         UserName = "******",
         FullName = "Unit Testesen1",
         Email = "*****@*****.**",
         HashedPassword = "******"
     };
     bool expected = true;
     bool actual;
     actual = target.CreateNewUser(newAccount);
     Assert.AreEqual(expected, actual);
     CleanupCreateUser(newAccount.UserName);
 }
示例#10
0
        public SearchResultsControl()
        {
            InitializeComponent();
            rentIt = new RentItClient();

            criteria = new MediaCriteria {
                SearchText = "",
                Genre = "",
                Type = MediaType.Any,
                Limit = -1,
                Offset = 0,
                Order = MediaOrder.AlphabeticalAsc
            };

            TypeFilter.SelectedIndex = 0;
        }
示例#11
0
文件: TestSuite4.cs 项目: ltj/rentit
        public void AddCreditsTest()
        {
            RentItClient target = new RentItClient();
            AccountCredentials credentials = new AccountCredentials {
                UserName = "******",
                HashedPassword = "******"
            };
            int oldCredits = target.GetAllCustomerData(credentials).Credits;

            uint addAmount = 100;
            bool expected = true;
            bool actual = target.AddCredits(credentials, addAmount);
            Assert.AreEqual(expected, actual);

            int newCredits = target.GetAllCustomerData(credentials).Credits;
            Assert.AreEqual(oldCredits + addAmount, newCredits);
        }
示例#12
0
文件: MainForm.cs 项目: ltj/rentit
        public MainForm()
        {
            InitializeComponent();

            var binding = new BasicHttpBinding();
            var address = new EndpointAddress("http://rentit.itu.dk/rentit01/RentItService.svc");
            rentItProxy = new RentItClient(binding, address);

            // Call a method on the web service to check for connectivity.
            // A potential EndpointNotFoundException is caught in Program.cs.
            rentItProxy.GetAllGenres(MediaType.Book);

            TopBar.RentItProxy = rentItProxy;
            TopBar.Credentials = credentials;
            TopBar.ContentChangeEvent += ChangeContent;
            TopBar.CredentialsChangeEvent += ChangeCredentials;
            TopBar.CreditsChangeEvent += ChangeCredits;

            Content = new MainScreen { RentItProxy = rentItProxy };
        }
示例#13
0
文件: TestSuite4.cs 项目: ltj/rentit
        public void DeleteMediaTest1()
        {
            RentItClient target = new RentItClient();
            int mediaId = 3; // Kraftwerk - The Robots
            AccountCredentials credentials = new AccountCredentials {
                UserName = "******",
                HashedPassword = "******"
            };
            bool expected = true;
            bool actual = target.DeleteMedia(mediaId, credentials);
            Assert.AreEqual(expected, actual);

            var db = new RentItTestDatabase.RentItDatabaseDataContext();

            // clean up
            var deletedMedia = (from m in db.Medias
                                where m.id == mediaId
                                select m).Single();
            deletedMedia.active = true;
            db.SubmitChanges();
        }
示例#14
0
文件: TestSuite4.cs 项目: ltj/rentit
        public void DeleteMediaTest2()
        {
            RentItClient target = new RentItClient();
            int mediaId = 2; // "House of Leaves"
            AccountCredentials credentials = new AccountCredentials {
                UserName = "******",
                HashedPassword = "******"
            };

            target.DeleteMedia(mediaId, credentials); // InvalidCredentialsException
        }
示例#15
0
文件: TestSuite4.cs 项目: ltj/rentit
        public void UpdateMediaMetadataTest()
        {
            RentItClient target = new RentItClient();
            AccountCredentials credentials = new AccountCredentials {
                UserName = "******",
                HashedPassword = "******"
            };

            int mediaId = 10; // Kraftwerk - "The Man-Machine" album
            AlbumInfo newAlbumData = target.GetAlbumInfo(mediaId);
            string albumArtist = newAlbumData.AlbumArtist;
            newAlbumData.AlbumArtist = newAlbumData.AlbumArtist == "Kraftwerk" ? "Craftwork" : "Kraftwerk";
            bool actual = target.UpdateMediaMetadata(newAlbumData, credentials);
            string updatedAlbumArtist = target.GetAlbumInfo(mediaId).AlbumArtist;
            Assert.IsTrue(actual);
            Assert.IsTrue(albumArtist == "Kraftwerk"? "Craftwork" == updatedAlbumArtist : "Kraftwerk" == updatedAlbumArtist);

            mediaId = 1; // "The Room"
            MovieInfo newMovieData = target.GetMovieInfo(mediaId);
            string director = newMovieData.Director;
            newMovieData.Director = newMovieData.Director == "Tommy Wiseau" ? "Timmy Wiseau" : "Tommy Wiseau";
            actual = target.UpdateMediaMetadata(newMovieData, credentials);
            string updatedDirector = target.GetMovieInfo(mediaId).Director;
            Assert.IsTrue(actual);
            Assert.IsTrue(director == "Tommy Wiseau" ? "Timmy Wiseau" == updatedDirector : "Tommy Wiseau" == updatedDirector);

            mediaId = 2; // "House of Leaves"
            BookInfo newBookData = target.GetBookInfo(mediaId);
            string author = newBookData.Author;
            newBookData.Author = newBookData.Author == "Mark Z. Danielewsky" ? "Mak Z. Danielewsky" : "Mark Z. Danielewsky";
            actual = target.UpdateMediaMetadata(newBookData, credentials);
            string updatedAuthor = target.GetBookInfo(mediaId).Author;
            Assert.IsTrue(actual);
            Assert.IsTrue(author == "Mark Z. Danielewsky" ? "Mak Z. Danielewsky" == updatedAuthor : "Mark Z. Danielewsky" == updatedAuthor);
        }
示例#16
0
文件: TestSuite4.cs 项目: ltj/rentit
        public void UpdateAccountInfoTest1()
        {
            RentItClient target = new RentItClient();
            AccountCredentials credentials = new AccountCredentials {
                UserName = "******",
                HashedPassword = "******"
            };
            Account account = target.GetAllCustomerData(credentials);
            string oldEmail = account.Email;
            account.Email += "+";

            bool expected = true;
            bool actual = target.UpdateAccountInfo(credentials, account);
            Assert.AreEqual(expected, actual);

            string newEmail = target.GetAllCustomerData(credentials).Email;
            Assert.AreEqual(oldEmail + "+", newEmail);
        }
示例#17
0
文件: TestSuite4.cs 项目: ltj/rentit
        public void GetAllGenresTest()
        {
            RentItClient target = new RentItClient();
            MediaType mediaType = MediaType.Any;
            string[] expected = new string[0]; // empty list
            string[] actual = target.GetAllGenres(mediaType); // List<string> actual = target.GetAllGenres(mediaType);
            Assert.AreNotEqual(expected.Length, actual.Length); // list should not be empty

            mediaType = MediaType.Book;
            actual = target.GetAllGenres(mediaType);
            Assert.AreNotEqual(expected.Length, actual.Length); // list should not be empty

            mediaType = MediaType.Movie;
            actual = target.GetAllGenres(mediaType);
            Assert.AreNotEqual(expected.Length, actual.Length); // list should not be empty

            mediaType = MediaType.Album;
            actual = target.GetAllGenres(mediaType);
            Assert.AreNotEqual(expected.Length, actual.Length); // list should not be empty

            mediaType = MediaType.Song;
            actual = target.GetAllGenres(mediaType);
            Assert.AreNotEqual(expected.Length, actual.Length); // list should not be empty
        }
示例#18
0
文件: TestSuite1.cs 项目: ltj/rentit
        public void GetAllPublisherDataTest()
        {
            RentItClient target = new RentItClient();
            AccountCredentials credentials = new AccountCredentials
            {
                UserName = "******",
                HashedPassword = "******"
            };

            PublisherAccount actual = target.GetAllPublisherData(credentials);

            Assert.AreEqual("publishCorp", actual.UserName);
            Assert.AreEqual("*****@*****.**", actual.Email);
            Assert.AreEqual("Publish Corp. Publishing Division", actual.FullName);
            Assert.AreEqual("7110EDA4D09E062AA5E4A390B0A572AC0D2C0220", actual.HashedPassword);
            Assert.AreEqual("Publish Corp. International", actual.PublisherName);
        }
示例#19
0
文件: TestSuite1.cs 项目: ltj/rentit
        public void GetAlsoRentedItemsTest()
        {
            RentItClient target = new RentItClient();
            const int Id = 1;

            MediaItems actual = target.GetAlsoRentedItems(Id);

            Assert.IsTrue(actual.Books.ToList().Exists(x => x.Id == 2 && x.Title == "House of Leaves"));
            Assert.IsTrue(actual.Albums.ToList().Exists(x => x.Id == 10 && x.Title == "The Man-Machine"));
            Assert.IsTrue(actual.Songs.Count() == 0);
        }
示例#20
0
文件: TestSuite2.cs 项目: ltj/rentit
        public void GetBookInfoTest1()
        {
            RentItClient target = new RentItClient();

            int id = 81;
            BookInfo actual = target.GetBookInfo(id);

            Assert.AreEqual("Power Commands for Visual Studio", actual.Title);
        }
示例#21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int mediaId = int.Parse(Request.QueryString["mediaId"]);
            string mediaExtension = Request.QueryString["extension"];
            string userName = Request.QueryString["userName"];
            string password = Request.QueryString["password"];

            Debug.WriteLine("Query string accepted.");

            // Check if the user name is a publisher account.
            var db = new RentItDatabase.RentItDatabaseDataContext();
            if (!db.Publisher_accounts.Exists(acc => acc.user_name.Equals(userName)))
            {
                Response.StatusCode = 400;
                Response.StatusDescription = "The specified account is not authorized to upload media.";
                Response.End();
            }

            // Check if the metadata of the movie has been uploaded.
            if (!db.Medias.Exists(media => media.id == mediaId))
            {
                Response.StatusCode = 400;
                Response.StatusDescription =
                    "Metadata for the specified media has not been uploaded."
                    + "This is needed before it is possible to upload the data.";
                Response.End();
            }

            var client = new RentItClient();
            try
            {
                client.ValidateCredentials(
                    new AccountCredentials() { UserName = userName, HashedPassword = password });
            }
            catch (Exception)
            {
                Response.StatusCode = 400;
                Response.StatusDescription = "Incorrect credentials";
                Response.End();
            }

            // Get the uploaded file.
            HttpPostedFile uploadedFile = Request.Files.Get(0);
            var memoryStream = new MemoryStream();
            byte[] binary;

            try
            {
                uploadedFile.InputStream.CopyTo(memoryStream);
                binary = memoryStream.ToArray();
            }
            catch (Exception)
            {
                Response.StatusCode = 400;
                Response.StatusDescription = "Media upload failed. Please try again.";
                Response.End();
                return;
            }

            RentItDatabase.Media mediaInfo = (from m in db.Medias
                                              where m.id == mediaId
                                              select m).Single();

            // Create a new Media_file entry in the database and upload the file to
            // the database.
            RentItDatabase.Media_file mediaFile = new Media_file
                {
                    name = mediaInfo.title,
                    extension = mediaExtension,
                    data = binary
                };
            db.Media_files.InsertOnSubmit(mediaFile);
            db.SubmitChanges();

            // Connect the Media_file tuple to the Media tuple.
            mediaInfo.Media_file = mediaFile;
            db.SubmitChanges();
        }
示例#22
0
        private static RentItClient GetServiceClient()
        {
            if (RentItProxy != null)
            {
                return RentItProxy;
            }

            var binding = new BasicHttpBinding();
            var address = new EndpointAddress("http://rentit.itu.dk/rentit01/RentItService.svc");
            return RentItProxy = new RentItClient(binding, address);
        }
示例#23
0
文件: TestSuite1.cs 项目: ltj/rentit
        public void SubmitReviewExceptionTest()
        {
            RentItClient target = new RentItClient();
            MediaReview review = new MediaReview
            {
                MediaId = 64,
                Rating = Rating.Three,
                ReviewText = "Bucket.",
                Timestamp = DateTime.Now,
                UserName = "******"
            };

            AccountCredentials credentials = new AccountCredentials
            {
                UserName = "******",
                HashedPassword = "******"
            };
            target.SubmitReview(review, credentials);
            target.SubmitReview(review, credentials);
        }
示例#24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Stream inputStream = Request.InputStream;

            int mediaId = int.Parse(Request.QueryString["mediaId"]);
            // string mediaExtension = Request.QueryString["extension"];
            string userName = Request.QueryString["userName"];
            string password = Request.QueryString["password"];

            // Check if the user name is a publisher account.
            var db = new RentItDatabase.RentItDatabaseDataContext();
            if (!db.Publisher_accounts.Exists(acc => acc.user_name.Equals(userName)))
            {
                Response.StatusCode = 400;
                Response.StatusDescription = "The specified account is not authorized to upload media.";
            }

            // Check if the metadata of the movie has been uploaded.
            if (!db.Medias.Exists(media => media.id == mediaId))
            {
                Response.StatusCode = 400;
                Response.StatusDescription =
                    "Metadata for the specified media has not been uploaded."
                    + "This is needed before it is possible to upload the data.";
                Response.End();
            }

            var client = new RentItClient();
            try
            {
                client.ValidateCredentials(
                    new AccountCredentials() { UserName = userName, HashedPassword = password });
            }
            catch (Exception)
            {
                Response.StatusCode = 400;
                Response.StatusDescription = "Incorrect credentials";
                Response.End();
            }

            var memoryStream = new MemoryStream();
            byte[] thumbnail;

            try
            {
                inputStream.CopyTo(memoryStream);
                thumbnail = memoryStream.ToArray();
            }
            catch (Exception)
            {
                Response.StatusCode = 400;
                Response.StatusDescription = "Thumbnail upload failed. Please try again.";
                Response.End();
                return;
            }

            RentItDatabase.Media mediaInfo = (from m in db.Medias
                                              where m.id == mediaId
                                              select m).First();
            mediaInfo.thumbnail = thumbnail;
            db.SubmitChanges();
        }
示例#25
0
文件: TestSuite3.cs 项目: ltj/rentit
        public void TestMethod1()
        {
            RentItClient client = new RentItClient();

            Account acc = client.ValidateCredentials(new AccountCredentials() { UserName = "******", HashedPassword = "******" });

            Assert.AreNotEqual(null, acc);
        }
示例#26
0
文件: TestSuite4.cs 项目: ltj/rentit
 public void DeleteMediaTest3()
 {
     RentItClient target = new RentItClient();
     int mediaId = 90000; // non-existant
     AccountCredentials credentials = new AccountCredentials {
         UserName = "******",
         HashedPassword = "******"
     };
     target.DeleteMedia(mediaId, credentials); // InvalidCredentialsException
 }
示例#27
0
文件: TestSuite1.cs 项目: ltj/rentit
 public void GetAlsoRentedItemsExceptionTest()
 {
     RentItClient target = new RentItClient();
     target.GetAlsoRentedItems(-3);
 }
示例#28
0
文件: TestSuite1.cs 项目: ltj/rentit
        public void SubmitReviewTest()
        {
            RentItClient target = new RentItClient();
            const string User = "******";
            const int MediaId = 79;
            MediaReview review = new MediaReview
            {
                MediaId = MediaId,
                Rating = Rating.Three,
                ReviewText = "Bucketboy, yes.",
                Timestamp = DateTime.Now,
                UserName = User
            };

            AccountCredentials credentials = new AccountCredentials
            {
                UserName = User,
                HashedPassword = "******"
            };
            bool actual = target.SubmitReview(review, credentials);
            Assert.IsTrue(actual);
            this.SubmitReviewCleanup(User, MediaId);
        }
示例#29
0
文件: TestSuite3.cs 项目: ltj/rentit
        public void DeleteAccountTest()
        {
            var db = new RentItTestDatabase.RentItDatabaseDataContext();
            RentItClient target = new RentItClient();

            Account delAccount = new Account {
                UserName = "******",
                FullName = "Unit Testesen1",
                Email = "*****@*****.**",
                HashedPassword = "******"
            };
            target.CreateNewUser(delAccount);

            AccountCredentials credentials = new AccountCredentials {
                UserName = "******",
                HashedPassword = "******"
            };
            bool expected = true;
            bool actual;
            actual = target.DeleteAccount(credentials);
            Assert.AreEqual(expected, actual);

            CleanupCreateUser(credentials.UserName);
        }
示例#30
0
文件: TestSuite1.cs 项目: ltj/rentit
 public void GetAllPublisherDataExceptionTestTwo()
 {
     RentItClient target = new RentItClient();
     AccountCredentials credentials = new AccountCredentials
     {
         UserName = "******",
         HashedPassword = "******"
     };
     target.GetAllPublisherData(credentials);
 }