public async void ShouldCreateAndFindAnArtitstUsingARepository()
        {
            var artistName = "ujoArtistRepo";
            var address    = "XXX" + artistName;
            var bio        = "Hi i am an artist";
            var artist     = new Artist()
            {
                Name = artistName, Address = address, Bio = bio
            };

            using (var context = new UjoContext())
            {
                var unitOfWork       = new UnitOfWork(context);
                var artistRepository = unitOfWork.RepositoryAsync <Artist>();
                artistRepository.Insert(artist);
                await unitOfWork.SaveChangesAsync();
            }

            using (var context = new UjoContext())
            {
                var unitOfWork       = new UnitOfWork(context);
                var artistRepository = unitOfWork.RepositoryAsync <Artist>();
                var artistFound      = await artistRepository.FindAsync(address);

                Assert.Equal(artist.Name, artistFound.Name);
                Assert.Equal(artist.Address, artistFound.Address);
                Assert.Equal(artist.Bio, artistFound.Bio);
            }
        }
Exemplo n.º 2
0
        private ModuleInitializer()
        {
            var testDatabase = new TestDatabase("Ujo");

            testDatabase.CreateDatabase();
            //globally inject a connection string with this name
            //this is not working using hardcoded settings
            //testDatabase.InitConnectionString("Ujo");
            //if we're using Entity Framework Code First, run all the migrations.
            var migrate =
                new System.Data.Entity.MigrateDatabaseToLatestVersion <UjoContext,
                                                                       Configuration>();
            var dbContext = new UjoContext();

            migrate.InitializeDatabase(dbContext);
        }
Exemplo n.º 3
0
        public async Task ShouldBeAbleToUpsertMusicRecordingsIncludingOtherArtists()
        {
            MappingBootstrapper.Initialise();

            var address        = "XXXX";
            var musicRecording = new MusicRecordingDTO();

            musicRecording.Address = address;
            musicRecording.Name    = "my great track";
            //musicRecording.ObjectState = ObjectState.Added;
            musicRecording.OtherArtists.Add(new CreativeWorkArtistDTO()
            {
                ContributionType = "Featured", CreativeWorkAddress = address, NonRegisteredArtistName = "JB", Role = "Tambourine"
            });

            using (var context = new UjoContext())
            {
                var unitOfWork            = new UnitOfWork(context);
                var musicRecordingService = new MusicRecordingService(unitOfWork);
                await musicRecordingService.UpsertAsync(musicRecording).ConfigureAwait(false);
            }

            using (var context = new UjoContext())
                using (var unitOfWork = new UnitOfWork(context))
                {
                    var musicRecordingService = new MusicRecordingService(unitOfWork);
                    var recordingOutput       = await musicRecordingService.FindAsync(address).ConfigureAwait(false);

                    Assert.Equal(musicRecording.Name, recordingOutput.Name);
                    Assert.Equal(musicRecording.OtherArtists.ToList()[0].NonRegisteredArtistName, recordingOutput.OtherArtists.ToList()[0].NonRegisteredArtistName);
                }


            var musicRecording2 = new MusicRecordingDTO();

            musicRecording2.Address = address;
            musicRecording2.Name    = "my great track 2";
            // musicRecording2.ObjectState = ObjectState.Added;
            musicRecording2.OtherArtists.Add(new CreativeWorkArtistDTO()
            {
                ContributionType = "Featured", CreativeWorkAddress = address, NonRegisteredArtistName = "JB2", Role = "Tambourine"
            });

            using (var context = new UjoContext())
                using (var unitOfWork = new UnitOfWork(context))
                {
                    var musicRecordingService = new MusicRecordingService(unitOfWork);
                    await musicRecordingService.UpsertAsync(musicRecording2).ConfigureAwait(false);
                }

            using (var context = new UjoContext())
                using (var unitOfWork = new UnitOfWork(context))
                {
                    var musicRecordingService = new MusicRecordingService(unitOfWork);
                    var recordingOutput       = await musicRecordingService.FindAsync(address).ConfigureAwait(false);

                    Assert.Equal(musicRecording2.Name, recordingOutput.Name);
                    Assert.Equal(1, recordingOutput.OtherArtists.Count);
                    Assert.Equal(musicRecording2.OtherArtists.ToList()[0].NonRegisteredArtistName, recordingOutput.OtherArtists.ToList()[0].NonRegisteredArtistName);
                }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            using (var db = new UjoContext())
            {
                System.Console.Write("Enter a name for a new Artist: ");
                var name = System.Console.ReadLine();

                var artist = new Artist()
                {
                    Name = name, Address = "XXX" + name
                };
                db.Artists.AddOrUpdate(artist);
                db.SaveChanges();

                var musicRecording = new MusicRecording()
                {
                    Address         = "xxxRec" + name,
                    Genre           = "Monkey Techno",
                    Name            = "Pooping head2",
                    ByArtistAddress = "XXX" + name
                };

                musicRecording.OtherArtists.Add(
                    new CreativeWorkArtist()
                {
                    ContributionType        = "Featured2",
                    Role                    = "Guitar",
                    NonRegisteredArtistName = "Simon",
                    CreativeWorkAddress     = musicRecording.Address
                });

                db.MusicRecordings.AddOrUpdate(musicRecording);
                db.CreativeWorkArtists.AddOrUpdate(musicRecording.OtherArtists.First());

                var creativeWorkArtist = new CreativeWorkArtist()
                {
                    ContributionType        = "Featured",
                    NonRegisteredArtistName = "Ujo",
                    CreativeWorkAddress     = "xxxRec" + name
                };

                db.CreativeWorkArtists.AddOrUpdate(creativeWorkArtist);
                db.SaveChanges();



                // Display all Blogs from the database
                var query = from b in db.Artists
                            orderby b.Name
                            select b;

                System.Console.WriteLine("All artists in the database:");
                foreach (var item in query)
                {
                    System.Console.WriteLine(item.Name);
                }

                System.Console.WriteLine("Press any key to exit...");
                System.Console.ReadKey();
            }
        }