Esempio n. 1
0
        public void ConstructorTest()
        {
            var boolNullable = new ArtistTable();

            Assert.AreEqual("artists", TableFactory <Artist> .GetTable <ArtistTable>().TableName);
            Assert.IsNotNull(boolNullable);
        }
Esempio n. 2
0
        public ArtistModel LookupArtistByName(string artistName, bool createIfNotFound = true)
        {
            ArtistTable artistTable = DatabaseManager.Current.LookupArtist(artistName);

            if (artistTable == null)
            {
                if (createIfNotFound)
                {
                    ArtistTable newArtist = new ArtistTable(artistName);
                    DatabaseManager.Current.AddArtist(newArtist);

                    ArtistModel artistModel = new ArtistModel(newArtist);
                    artistLookupDictionary.Add(artistModel.ArtistId, artistModel);

                    return(artistModel);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(LookupArtistById(artistTable.ArtistId));
            }
        }
Esempio n. 3
0
        public void GetCreateSqlTest()
        {
            var table    = new ArtistTable();
            var expected = $"CREATE TABLE {TableFactory<Artist>.GetTable<ArtistTable>().TableName} ({ArtistTable.IdColumnName} INTEGER NOT NULL PRIMARY KEY, {ArtistTable.NameColumnName} TEXT UNIQUE NOT NULL COLLATE NOCASE) WITHOUT ROWID;";

            Assert.AreEqual(expected, table.GetCreateSql());
        }
Esempio n. 4
0
        public void GetDeleteSqlTest()
        {
            var id    = HelperObjectFactory.GetRandomInt(0, 100);
            var value = new IdentifyingInfo
            {
                Id = id
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();
            var expected   = $"DELETE FROM {TableFactory<Artist>.GetTable<ArtistTable>().TableName} WHERE {ArtistTable.IdColumnName} = @{ArtistTable.IdColumnName};";

            Assert.AreEqual(expected, table.GetDeleteSql(value, ref parameters));
            Assert.AreEqual(1, parameters.Count);
            parameters.Clear();

            value = new IdentifyingInfo
            {
                Name = StringExtensions.GetRandomStringAsync(25).Result
            };

            expected = $"DELETE FROM {TableFactory<Artist>.GetTable<ArtistTable>().TableName} WHERE {ArtistTable.NameColumnName} = @{ArtistTable.NameColumnName};";

            Assert.AreEqual(expected, table.GetDeleteSql(value, ref parameters));
            Assert.AreEqual(1, parameters.Count);
        }
Esempio n. 5
0
        public void GetUpdateSqlTest()
        {
            var id         = HelperObjectFactory.GetRandomInt(0, 100);
            var value      = new Artist(id, StringExtensions.GetRandomStringAsync(23).Result);
            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();
            var expected   = $"UPDATE {TableFactory<Artist>.GetTable<ArtistTable>().TableName} SET {ArtistTable.NameColumnName} = @{ArtistTable.NameColumnName} WHERE {ArtistTable.IdColumnName} = @{ArtistTable.IdColumnName};";

            Assert.AreEqual(expected, table.GetUpdateSql(value, ref parameters));
            Assert.AreEqual(2, parameters.Count);
        }
Esempio n. 6
0
        public void GetInsertSqlTest()
        {
            var id         = HelperObjectFactory.GetRandomInt(0, 100);
            var value      = new Artist(id, StringExtensions.GetRandomStringAsync(23).Result);
            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();
            var expected   = $"INSERT OR IGNORE INTO {TableFactory<Artist>.GetTable<ArtistTable>().TableName} ({ArtistTable.IdColumnName}, {AlbumTable.NameColumnName}) VALUES(@{ArtistTable.IdColumnName}, @{ArtistTable.NameColumnName});";

            Assert.AreEqual(expected, table.GetInsertSql(value, ref parameters));
            Assert.AreEqual(2, parameters.Count);
        }
Esempio n. 7
0
        public void GetDeleteAlbumsByArtistSqlExceptionTest()
        {
            var value = new IdentifyingInfo
            {
                Id = null
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();

            Assert.That(() => table.GetDeleteAlbumsByArtistSql(value, ref parameters), Throws.ArgumentException);
        }
Esempio n. 8
0
        public ArtistModel SearchArtistByName(string artistName)
        {
            ArtistTable artistTable = DatabaseManager.Current.LookupArtist(artistName);

            if (artistTable == null)
            {
                return(null);
            }
            else
            {
                return(LookupArtistById(artistTable.ArtistId));
            }
        }
Esempio n. 9
0
        public void GetIdFromNameExceptionTest()
        {
            var id    = HelperObjectFactory.GetRandomInt(0, 100);
            var value = new IdentifyingInfo
            {
                Id = id
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();

            Assert.That(() => table.GetIdFromNameSql(value, ref parameters), Throws.ArgumentException);
        }
Esempio n. 10
0
        public static TrackInfo TrackInfoFromRowId(int rowId)
        {
            try
            {
                PlayQueueEntryTable playQueueEntry = DatabaseManager.Current.LookupPlayQueueEntryById(rowId);

                if (playQueueEntry != null)
                {
                    SongTable songTable = DatabaseManager.Current.LookupSongById(playQueueEntry.SongId);

                    if (songTable != null)
                    {
                        AlbumTable  albumTable  = DatabaseManager.Current.LookupAlbumById(songTable.AlbumId);
                        ArtistTable artistTable = DatabaseManager.Current.LookupArtistById(songTable.ArtistId);

                        if (albumTable != null && artistTable != null)
                        {
                            ArtistTable albumArtistTable = DatabaseManager.Current.LookupArtistById(albumTable.ArtistId);

                            if (albumArtistTable != null)
                            {
                                return(new TrackInfo(songTable.Name, artistTable.Name, albumTable.Name, albumArtistTable.Name, songTable.Source, albumTable.AlbumArt, rowId, playQueueEntry.NextId, playQueueEntry.PrevId, playQueueEntry.SongId));
                            }
                            else
                            {
                                Logger.Current.Log(new CallerInfo(), LogLevel.Warning, "Couldn't play row {0}, no artistEntry {1} matches!", rowId, albumTable.ArtistId);
                            }
                        }
                        else
                        {
                            Logger.Current.Log(new CallerInfo(), LogLevel.Warning, "Couldn't play row {0}, no albumEntry {1} or artistEntry {2} matches ({3} {4})!", rowId, songTable.AlbumId, songTable.ArtistId, albumTable != null, artistTable != null);
                        }
                    }
                    else
                    {
                        Logger.Current.Log(new CallerInfo(), LogLevel.Warning, "Couldn't play row {0}, no songEntry for {1} matches!", rowId, playQueueEntry.SongId);
                    }
                }
                else
                {
                    Logger.Current.Log(new CallerInfo(), LogLevel.Warning, "Couldn't play row {0}, no playQueueEntry matches!", rowId);
                }
            }
            catch (SQLiteException ex)
            {
                Logger.Current.Log(new CallerInfo(), LogLevel.Error, "Couldn't play row {0}, got an exception {1}!", rowId, ex.Message);
            }

            return(null);
        }
Esempio n. 11
0
        public void GetIdFromNameTest()
        {
            var value = new IdentifyingInfo
            {
                Name = StringExtensions.GetRandomStringAsync(25).Result
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();
            var expected   = $"SELECT {ArtistTable.IdColumnName} FROM {table.TableName} WHERE {ArtistTable.NameColumnName} = @{ArtistTable.NameColumnName};";

            Assert.AreEqual(expected, table.GetIdFromNameSql(value, ref parameters));
            Assert.AreEqual(1, parameters.Count);
        }
Esempio n. 12
0
        public void GetDeleteAlbumsByArtistSqlTest()
        {
            var id    = HelperObjectFactory.GetRandomInt(0, 100);
            var value = new IdentifyingInfo
            {
                Id = id
            };

            var parameters = new List <SQLiteParameter>();
            var table      = new ArtistTable();
            var expected   = $"DELETE FROM {TableFactory<Album>.GetTable<AlbumTable>().TableName} WHERE {AlbumTable.ArtistIdColumnName} = @{AlbumTable.ArtistIdColumnName};";

            Assert.AreEqual(expected, table.GetDeleteAlbumsByArtistSql(value, ref parameters));
            Assert.AreEqual(1, parameters.Count);
        }
Esempio n. 13
0
        public async Task InitializeDatabaseNonUniqueIdsExceptionTest()
        {
            using (var container = Substitute.For <UnityContainer>())
            {
                using (var cursor = Substitute.For <ICursor>())
                {
                    cursor.GetInt(0).Returns(1);

                    var artistTable = new ArtistTable();
                    var albumTable  = new AlbumTable();
                    var genreTable  = new GenreTable();

                    var artistParameters = new List <SQLiteParameter>();
                    var albumParameters  = new List <SQLiteParameter>();
                    var genreParameters  = new List <SQLiteParameter>();

                    var artistSql = artistTable.GetInsertSql(new Artist(0, "Michael Jackson"), ref artistParameters);
                    var genreSql  = genreTable.GetInsertSql(new Genre(0, "Pop"), ref genreParameters);
                    var albumSql  = albumTable.GetInsertSql(new Album(0, 0, 0, "Thriller", 1982), ref albumParameters);

                    var dataAccess = Substitute.For <IDataAccess>();
                    dataAccess.OpenOrCreateDatabaseAsync().Returns(DatabaseState.New);
                    dataAccess.ExecuteQueryWithParametersAsync(Arg.Any <string>(), Arg.Any <List <SQLiteParameter> >()).Returns(cursor);

                    dataAccess.ExecuteSqlWithParametersAsync(artistSql, Arg.Any <List <SQLiteParameter> >()).Returns(1);
                    dataAccess.ExecuteSqlWithParametersAsync(genreSql, Arg.Any <List <SQLiteParameter> >()).Returns(0);
                    dataAccess.ExecuteSqlWithParametersAsync(albumSql, Arg.Any <List <SQLiteParameter> >()).Returns(1);

                    container.RegisterInstance(Resources.DataAccessObjectName, dataAccess, new ContainerControlledLifetimeManager());

                    container.RegisterType <AlbumController>(new InjectionFactory(s => new AlbumController(dataAccess)));
                    container.RegisterType <ArtistController>(new InjectionFactory(s => new ArtistController(dataAccess)));
                    container.RegisterType <GenreController>(new InjectionFactory(s => new GenreController(dataAccess)));
                    container.RegisterType <StatisticsController>(new InjectionFactory(s => new StatisticsController(dataAccess)));

                    try
                    {
                        await DatabaseHelpers.InitializeDatabase(container);
                    }
                    catch (Exception ex)
                    {
                        Assert.IsInstanceOf <SQLiteException>(ex);
                        Assert.AreEqual($"unknown error\r\n{Resources.ErrorAddingItemMessage}", ex.Message);
                    }
                }
            }
        }
Esempio n. 14
0
        protected void btnSignUp_Click(object sender, EventArgs e)
        {
            Boolean emailExists = false;

            // Check if an Email already exists in the database
            // If yes display an alert message and refresh the page
            DataContextDataContext dbEmail = new DataContextDataContext();
            var getSellerEmail             = from p in dbEmail.ArtistTables
                                             select p;

            // Same Email Cannot Add Register
            foreach (var getExistsEmail in getSellerEmail)
            {
                if (getExistsEmail.authorEmail == selEmail.Text)
                {
                    emailExists = true;
                }
            }

            if (emailExists == true)
            {
                Response.Write("<script>alert('The Email has already been taken and registered with this website')</script>");
            }


            if (emailExists == false)
            {
                db = new DataContextDataContext();

                ArtistTable newArtistTable = new ArtistTable();
                newArtistTable.authorUsername = selUsername.Text;
                newArtistTable.authorPswd     = selPswd.Text;
                newArtistTable.authorEmail    = selEmail.Text;
                newArtistTable.authorName     = selName.Text;
                newArtistTable.authorGender   = selGender.Text;
                newArtistTable.contact        = selPhoneNum.Text;
                DateTime myDateTime = DateTime.ParseExact(Request.Form["date"], "yyyy-MM-dd", null);
                newArtistTable.authorDOB = myDateTime;
                newArtistTable.address   = selHouseAddress.Text;

                db.ArtistTables.InsertOnSubmit(newArtistTable);
                db.SubmitChanges();

                Response.Write("<script>alert('You've successfully registered an account!')</script>");
                Response.Redirect("~/SellerLogin.aspx");
            }
        }
Esempio n. 15
0
        public void showData()
        {
            using (DataContextDataContext objDataContext = new DataContextDataContext())
            {
                // Get single seller record to display
                ArtistTable objSeller = objDataContext.ArtistTables.Single(sel => sel.authorEmail == Session["seller"]);

                //Fields which will be display customer details
                selName.Text     = objSeller.authorName;
                selPhoneNum.Text = objSeller.contact;
                selEmail.Text    = objSeller.authorEmail;
                selGender.Text   = objSeller.authorGender;

                DateTime sdate = (DateTime)objSeller.authorDOB;
                selDOB.Text          = sdate.ToString("dd-MM-yyyy");
                selHouseAddress.Text = objSeller.address;
            };
        }
Esempio n. 16
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //SqlDataSource1.Update();

            using (DataContextDataContext objDataContext = new DataContextDataContext())
            {
                // Get single customer record
                ArtistTable objSeller = objDataContext.ArtistTables.Single(sel => sel.authorEmail == Session["seller"]);

                //Field which allow customer to update their profile
                objSeller.authorName   = selName.Text;
                objSeller.contact      = selPhoneNum.Text;
                objSeller.authorEmail  = selEmail.Text;
                objSeller.authorGender = selGender.Text;
                objSeller.authorDOB    = DateTime.ParseExact(selDOB.Text, "dd-MM-yyyy", null);
                objSeller.address      = selHouseAddress.Text;

                // executes the commands to implement the changes to the database
                objDataContext.SubmitChanges();
            }
        }
Esempio n. 17
0
        public ArtistModel LookupArtistById(int artistId)
        {
            if (artistLookupDictionary.ContainsKey(artistId))
            {
                return(artistLookupDictionary[artistId]);
            }
            else
            {
                ArtistTable artistTable = DatabaseManager.Current.LookupArtistById(artistId);

                if (artistTable == null)
                {
                    return(null);
                }
                else
                {
                    ArtistModel artistModel = new ArtistModel(artistTable);
                    artistLookupDictionary.Add(artistModel.ArtistId, artistModel);

                    return(artistModel);
                }
            }
        }
Esempio n. 18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["seller"] == null)
            {
                signUpBtnMain.Visible = true;
                loginBtnMain.Visible  = true;

                logoutBtnMain.Visible = false;
                lblWelcomeMsg.Visible = false;
                lblLoginTime.Visible  = false;
                lblLoginDate.Visible  = false;
            }
            else
            {
                signUpBtnMain.Visible = false;
                loginBtnMain.Visible  = false;

                logoutBtnMain.Visible = true;
                lblWelcomeMsg.Visible = true;
                lblLoginTime.Visible  = true;
                lblLoginDate.Visible  = true;
            }

            if (!IsPostBack)
            {
                if (Session["seller"] != null)
                {
                    DataContextDataContext objDataContext = new DataContextDataContext();
                    ArtistTable            objSeller      = objDataContext.ArtistTables.Single(sel => sel.authorEmail == Session["seller"]);
                    string selName = objSeller.authorName;

                    lblWelcomeMsg.Text = "Welcome back, " + selName + "!";
                    lblLoginTime.Text  = "Time Now : " + DateTime.Now.ToShortTimeString();
                    lblLoginDate.Text  = "Date Access : " + DateTime.Now.ToShortDateString();
                }
            }
        }