public void LoadById() { //Load up Guids PieceList pieces = new PieceList(); Piece piece = new Piece(); pieces.Load(); piece = pieces.FirstOrDefault(p => p.Name == "Rock Music"); ComposerList composers = new ComposerList(); Composer composer = new Composer(); composers.Load(); composer = composers.FirstOrDefault(c => c.FirstName == "Modest"); PieceWriter pieceWriter = new PieceWriter(); PieceWriterList pieceWriters = new PieceWriterList(); pieceWriters.Load(); pieceWriter = pieceWriters.FirstOrDefault(p => p.ComposerId == composer.Id && p.PieceId == piece.Id); PieceWriter newPieceWriter = new PieceWriter { Id = pieceWriter.Id }; newPieceWriter.LoadById(); Assert.AreEqual(pieceWriter.ComposerId, newPieceWriter.ComposerId); }
public void DeleteTest() { //Load up Guids PieceList pieces = new PieceList(); Piece piece = new Piece(); pieces.Load(); piece = pieces.FirstOrDefault(p => p.Name == "Rock Music"); ComposerList composers = new ComposerList(); Composer composer = new Composer(); composers.Load(); composer = composers.FirstOrDefault(c => c.FirstName == "Modest"); PieceWriter pieceWriter = new PieceWriter(); PieceWriterList pieceWriters = new PieceWriterList(); pieceWriters.Load(); pieceWriter = pieceWriters.FirstOrDefault(p => p.ComposerId == composer.Id && p.PieceId == piece.Id); int results = pieceWriter.Delete(); Assert.IsTrue(results == 1); }
public void UpdateTest() { //Load up Guids PieceList pieces = new PieceList(); Piece piece = new Piece(); pieces.Load(); piece = pieces.FirstOrDefault(p => p.Name == "Rock Music"); ComposerList composers = new ComposerList(); Composer composer = new Composer(); composers.Load(); composer = composers.FirstOrDefault(c => c.FirstName == "Modest"); ComposerTypeList ctl = new ComposerTypeList(); ComposerType ct = new ComposerType(); ctl.Load(); ct = ctl.FirstOrDefault(c => c.Description == "Composer"); PieceWriter pieceWriter = new PieceWriter(); PieceWriterList pieceWriters = new PieceWriterList(); pieceWriters.Load(); pieceWriter = pieceWriters.FirstOrDefault(p => p.ComposerId == composer.Id && p.PieceId == piece.Id); pieceWriter.ComposerTypeId = ct.Id; int results = pieceWriter.Update(); Assert.IsTrue(results == 1); }
public void Update() { ComposerList composers = new ComposerList(); composers.Load(); Composer composer = composers.FirstOrDefault(c => c.FirstName == "SLTEST"); Composer retrievedComposer = new Composer(); if (composer != null) { retrievedComposer.Id = composer.Id; composer.FirstName = "SLTEST1"; //Act HttpClient client = InitializeClient(); //Serialize a question object that we're trying to insert string serializedComposer = JsonConvert.SerializeObject(composer); var content = new StringContent(serializedComposer); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); HttpResponseMessage response = client.PutAsync("Composer/" + composer.Id, content).Result; retrievedComposer.LoadById(); } //Assert Assert.AreEqual(composer.FirstName, retrievedComposer.FirstName); }
private void CboPiece_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cboPiece.SelectedItem != null) { Piece piece = pieces.ElementAt(cboPiece.SelectedIndex); //Change the boxes on screen based onthe selected object. txtGradeLevel.Text = piece.GradeLevel; txtName.Text = piece.Name; txtPerformanceNotes.Text = piece.PerformanceNotes; txtYearWritten.Text = piece.YearWritten > 0 ? piece.YearWritten.ToString() : String.Empty; lstGenre.SelectedItems.Clear(); foreach (Genre genre in piece.Genres) { Genre genreToAdd = genres.FirstOrDefault(g => g.Id == genre.Id); lstGenre.SelectedItems.Add(genreToAdd); } lstComposer.SelectedItems.Clear(); //Get the composerTypeId for composer Guid composerTypeGuid = composerTypes.FirstOrDefault(ct => ct.Description == "Composer").Id; foreach (PieceWriter pieceWriter in piece.PieceWriters) { //If this piecewrite is a composer, select them if (pieceWriter.ComposerTypeId == composerTypeGuid) { Composer composerToSelect = composers.FirstOrDefault(c => c.Id == pieceWriter.ComposerId); lstComposer.SelectedItems.Add(composerToSelect); } } lstArranger.SelectedItems.Clear(); //Get the composerTypeId for composer Guid arrangerTypeId = composerTypes.FirstOrDefault(ct => ct.Description == "Arranger").Id; foreach (PieceWriter pieceWriter in piece.PieceWriters) { //If this piecewrite is a composer, select them if (pieceWriter.ComposerTypeId == arrangerTypeId) { Composer arrangerToSelect = composers.FirstOrDefault(c => c.Id == pieceWriter.ComposerId); lstArranger.SelectedItems.Add(arrangerToSelect); } } btnSave.Content = "Save Piece"; } }
public void DeleteTest() { Composer composer = new Composer(); ComposerList composers = new ComposerList(); composers.Load(); composer = composers.FirstOrDefault(c => c.FirstName == "Test"); int results = composer.Delete(); Assert.IsTrue(results == 1); }
public void Insert() { //Setup ComposerList cl = new ComposerList(); Composer composer = new Composer(); cl.Load(); composer = cl.FirstOrDefault(c => c.FirstName == "Alex"); PieceList pl = new PieceList(); Piece piece = new Piece(); pl.Load(); piece = pl.FirstOrDefault(p => p.Name == "Pictures At An Exhibition"); ComposerTypeList ctl = new ComposerTypeList(); ComposerType composerType = new ComposerType(); ctl.Load(); composerType = ctl.FirstOrDefault(ct => ct.Description == "Composer"); PieceWriter pieceWriter = new PieceWriter { ComposerId = composer.Id, ComposerTypeId = composerType.Id, PieceId = piece.Id }; PieceWriterList pieceWriters = new PieceWriterList(); pieceWriters.Load(); int originalCount = pieceWriters.Count(); //Act HttpClient client = InitializeClient(); //Serialize a pieceWriter object that we're trying to insert string serializedPieceWriter = JsonConvert.SerializeObject(pieceWriter); var content = new StringContent(serializedPieceWriter); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); HttpResponseMessage response = client.PostAsync("PieceWriter", content).Result; //Assert pieceWriters.Clear(); pieceWriters.Load(); Assert.AreEqual(originalCount + 1, pieceWriters.Count); }
public void Update() { //Setup ComposerList cl = new ComposerList(); Composer composer = new Composer(); cl.Load(); composer = cl.FirstOrDefault(c => c.FirstName == "Alex"); PieceList pl = new PieceList(); Piece piece = new Piece(); pl.Load(); piece = pl.FirstOrDefault(p => p.Name == "Pictures At An Exhibition"); ComposerTypeList ctl = new ComposerTypeList(); ComposerType composerType = new ComposerType(); ComposerType arranger = new ComposerType(); ctl.Load(); composerType = ctl.FirstOrDefault(ct => ct.Description == "Composer"); arranger = ctl.FirstOrDefault(ct => ct.Description == "Arranger"); PieceWriterList pieceWriters = new PieceWriterList(); pieceWriters.Load(); PieceWriter pieceWriter = pieceWriters.FirstOrDefault(pw => pw.ComposerId == composer.Id && pw.ComposerTypeId == composerType.Id && pw.PieceId == piece.Id); PieceWriter retrievedPieceWriter = new PieceWriter(); if (pieceWriter != null) { retrievedPieceWriter.Id = pieceWriter.Id; pieceWriter.ComposerTypeId = arranger.Id; //Act HttpClient client = InitializeClient(); //Serialize a question object that we're trying to insert string serializedPieceWriter = JsonConvert.SerializeObject(pieceWriter); var content = new StringContent(serializedPieceWriter); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); HttpResponseMessage response = client.PutAsync("PieceWriter/" + pieceWriter.Id, content).Result; retrievedPieceWriter.LoadById(); } //Assert Assert.AreEqual(pieceWriter.ComposerTypeId, retrievedPieceWriter.ComposerTypeId); }
public void LoadById() { Composer composer = new Composer(); ComposerList composers = new ComposerList(); composers.Load(); composer = composers.FirstOrDefault(c => c.FirstName == "Test"); Composer newComposer = new Composer { Id = composer.Id }; newComposer.LoadById(); Assert.AreEqual(composer.FirstName, newComposer.FirstName); }
public void Delete() { //Setup ComposerList cl = new ComposerList(); Composer composer = new Composer(); cl.Load(); composer = cl.FirstOrDefault(c => c.FirstName == "Alex"); PieceList pl = new PieceList(); Piece piece = new Piece(); pl.Load(); piece = pl.FirstOrDefault(p => p.Name == "Pictures At An Exhibition"); ComposerTypeList ctl = new ComposerTypeList(); ComposerType arranger = new ComposerType(); ctl.Load(); arranger = ctl.FirstOrDefault(ct => ct.Description == "Arranger"); PieceWriterList pieceWriters = new PieceWriterList(); pieceWriters.Load(); int originalCount = pieceWriters.Count(); PieceWriter pieceWriter = pieceWriters.FirstOrDefault(pw => pw.ComposerId == composer.Id && pw.ComposerTypeId == arranger.Id && pw.PieceId == piece.Id); //Act if (pieceWriter != null) { HttpClient client = InitializeClient(); HttpResponseMessage response = client.DeleteAsync("PieceWriter/" + pieceWriter.Id).Result; } //Assert pieceWriters.Clear(); pieceWriters.Load(); Assert.AreEqual(originalCount - 1, pieceWriters.Count); }
public void Delete() { //Setup ComposerList composers = new ComposerList(); composers.Load(); int originalCount = composers.Count(); Composer composer = composers.FirstOrDefault(c => c.FirstName == "SLTEST1"); //Act if (composer != null) { HttpClient client = InitializeClient(); HttpResponseMessage response = client.DeleteAsync("Composer/" + composer.Id).Result; } //Assert composers.Clear(); composers.Load(); Assert.AreEqual(originalCount - 1, composers.Count); }
public void GetOne() { //Setup Composer composer = new Composer(); Composer retrievedComposer = new Composer(); ComposerList composers = new ComposerList(); composers.Load(); composer = composers.FirstOrDefault(c => c.FirstName == "Alex"); //Act if (composer != null) { HttpClient client = InitializeClient(); HttpResponseMessage response = client.GetAsync("Composer/" + composer.Id).Result; string result = response.Content.ReadAsStringAsync().Result; retrievedComposer = JsonConvert.DeserializeObject <Composer>(result); } //Assert Assert.IsTrue(composer.FirstName == retrievedComposer.FirstName && !string.IsNullOrEmpty(retrievedComposer.FirstName)); }