Example #1
0
        public static WorkEntity Create(AzureTable table, MusicRecordingDTO work)
        {
            var workEntity = new WorkEntity(table);

            workEntity.Initialise(work);
            return(workEntity);
        }
        public WorkEntity MapFromWorkModel(WorkEntity workEntity, MusicRecordingDTO work)
        {
            workEntity.Address             = work.Address ?? "";
            workEntity.Name                = work.Name ?? "";
            workEntity.Creator             = work.Creator ?? "";
            workEntity.DateCreated         = work.DateCreated ?? "";
            workEntity.DateModified        = work.DateModified ?? "";
            workEntity.Image               = work.Image ?? "";
            workEntity.Audio               = work.Audio ?? "";
            workEntity.Genre               = work.Genre ?? "";
            workEntity.Keywords            = work.Keywords ?? "";
            workEntity.ByArtistAddress     = work.ByArtistAddress ?? "";
            workEntity.ByArtistName        = work.ArtistName ?? "";
            workEntity.FeaturedArtists     = JsonConvert.SerializeObject(work.GetFeaturedArtists().ToArray());
            workEntity.ContributingArtists = JsonConvert.SerializeObject(work.GetContributingArtists().ToArray());
            workEntity.PerformingArtists   = JsonConvert.SerializeObject(work.GetPerformingArtists().ToArray());
            workEntity.Label               = work.Label ?? "";
            workEntity.Description         = work.Description ?? "";
            workEntity.Publisher           = work.Publisher ?? "";
            workEntity.HasPartOf           = work.HasPart ?? false;
            workEntity.IsPartOf            = work.IsPartOf ?? false;
            workEntity.IsFamilyFriendly    = work.IsFamilyFriendly ?? "";
            workEntity.License             = work.License ?? "";
            workEntity.IswcCode            = work.IswcCode ?? "";

            return(workEntity);
        }
Example #3
0
        public void ShouldBeAbleToMapDTOToModel()
        {
            MappingBootstrapper.Initialise();
            Mapper.AssertConfigurationIsValid();

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

            musicRecording.Address = address;
            musicRecording.Name    = "my great track";
            var musicRecordingModel = new MusicRecording();

            Mapper.Map(musicRecording, musicRecordingModel);
            Assert.Equal(musicRecordingModel.Address, address);
        }
        public async Task <MusicRecordingDTO> GetMusicRecordingAsync()
        {
            var musicRecording = new MusicRecordingDTO();

            musicRecording.Address = Contract.Address;
            musicRecording.Audio   = await GetWorkAttributeAsyncCall(WorkSchema.audio);

            musicRecording.Image = await GetWorkAttributeAsyncCall(WorkSchema.image);

            musicRecording.DateCreated = await GetWorkAttributeAsyncCall(WorkSchema.dateCreated);

            musicRecording.DateModified = await GetWorkAttributeAsyncCall(WorkSchema.dateModified);

            var byArtist = await GetWorkAttributeAsyncCall(WorkSchema.byArtist);

            if (IsAddress(byArtist))
            {
                musicRecording.ByArtistAddress = byArtist;
            }
            else
            {
                musicRecording.ArtistName = byArtist;
            }

            musicRecording.Creator = await GetWorkAttributeAsyncCall(WorkSchema.creator);

            musicRecording.Name = await GetWorkAttributeAsyncCall(WorkSchema.name);

            musicRecording.Genre = await GetWorkAttributeAsyncCall(WorkSchema.genre);

            musicRecording.Keywords = await GetWorkAttributeAsyncCall(WorkSchema.keywords);

            musicRecording.Label = await GetWorkAttributeAsyncCall(WorkSchema.label);

            musicRecording.Publisher = await GetWorkAttributeAsyncCall(WorkSchema.publisher);

            musicRecording.HasPart  = TryParseToBolean(await GetWorkAttributeAsyncCall(WorkSchema.hasPartOf), false);
            musicRecording.IsPartOf = TryParseToBolean(await GetWorkAttributeAsyncCall(WorkSchema.isPartOf), false);
            musicRecording.License  = await GetWorkAttributeAsyncCall(WorkSchema.license);

            musicRecording.IswcCode = await GetWorkAttributeAsyncCall(WorkSchema.iswcCode);

            musicRecording.IsrcCode = await GetWorkAttributeAsyncCall(WorkSchema.isrcCode);

            musicRecording.OtherArtists = await GetAllOtherArtists();

            return(musicRecording);
        }
Example #5
0
        public void ShouldBeAbleToMapOtherArtitsDTOToModel()
        {
            MappingBootstrapper.Initialise();
            Mapper.AssertConfigurationIsValid();

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

            musicRecording.Address = address;
            musicRecording.OtherArtists.Add(new CreativeWorkArtistDTO()
            {
                ArtistAddres = otherArtitsAddress
            });
            var musicRecordingModel = new MusicRecording();

            Mapper.Map(musicRecording, musicRecordingModel);
            Assert.Equal(musicRecordingModel.Address, address);
            Assert.Equal(musicRecordingModel.OtherArtists.First().ArtistAddres, otherArtitsAddress);
        }
Example #6
0
 public void Initialise(MusicRecordingDTO work)
 {
     new WorkModelToWorkEntityMapper().MapFromWorkModel(this, work);
 }
Example #7
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);
                }
        }