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 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 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 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 LoadTest()
        {
            PieceWriterList pieceWriters = new PieceWriterList();

            pieceWriters.Load();
            Assert.AreEqual(4, pieceWriters.Count);
        }
示例#6
0
        // GET: api/PieceWriter
        public IEnumerable <PieceWriter> Get()
        {
            PieceWriterList pwl = new PieceWriterList();

            pwl.Load();
            return(pwl);
        }
        public void GetOne()
        {
            //Setup
            PieceWriter     pieceWriter          = new PieceWriter();
            PieceWriter     retrievedPieceWriter = new PieceWriter();
            PieceWriterList pieceWriters         = new PieceWriterList();
            Piece           pictures             = new Piece();
            PieceList       pl = new PieceList();

            pl.Load();
            pictures = pl.FirstOrDefault(p => p.Name == "Pictures At An Exhibition");

            pieceWriters.Load();

            pieceWriter = pieceWriters.FirstOrDefault(pw => pw.PieceId == pictures.Id);

            //Act
            if (pieceWriter != null)
            {
                HttpClient          client   = InitializeClient();
                HttpResponseMessage response = client.GetAsync("PieceWriter/" + pieceWriter.Id).Result;

                string result = response.Content.ReadAsStringAsync().Result;

                retrievedPieceWriter = JsonConvert.DeserializeObject <PieceWriter>(result);
            }

            //Assert
            Assert.IsTrue(pieceWriter.ComposerId == retrievedPieceWriter.ComposerId && retrievedPieceWriter.ComposerId != Guid.Empty);
        }
        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 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);
        }