Esempio n. 1
0
        public async Task ReturnCorrectArtist()
        {
            //Arrange
            var options = Utils.GetOptions(nameof(ReturnCorrectArtist));

            using (var arrangeContext = new AppDbContext(options))
            {
                await arrangeContext.Artists.AddAsync(new Artist
                {
                    Name         = "Name",
                    DeezerId     = "DeezerId",
                    Picture      = "PictureUrl",
                    TrackListURL = "URL",
                });

                await arrangeContext.SaveChangesAsync();
            }

            using (var actContext = new AppDbContext(options))
            {
                var expectedArtist = Utils.Mapper.Map <ArtistDTO>(await actContext.Artists.FirstAsync());
                var sut            = new ArtistService(actContext, Utils.Mapper);

                //Act
                var actualArtist = await sut.GetArtistAsync(expectedArtist.Id);

                //Assert
                Assert.AreEqual(expectedArtist.Id, actualArtist.Id);
                Assert.AreEqual(expectedArtist.Name, actualArtist.Name);
                Assert.AreEqual(expectedArtist.Picture, actualArtist.Picture);
                Assert.AreEqual(expectedArtist.TrackListURL, actualArtist.TrackListURL);
            }
        }
Esempio n. 2
0
 public ArtistsController(
     RedisService redis,
     DbService db,
     ArtistService artistService
     ) : base(redis, db, artistService)
 {
 }
Esempio n. 3
0
 public ArtistApiController(ArtistQueries queries, ArtistService service, IAggregatedEntryImageUrlFactory thumbPersister, ObjectCache cache)
 {
     _queries        = queries;
     _service        = service;
     _thumbPersister = thumbPersister;
     _cache          = cache;
 }
Esempio n. 4
0
        public IHttpActionResult Get(int id)
        {
            var headers = Request.Headers;

            if (!headers.Contains("token"))
            {
                return(Ok(new { errorCode = "66", message = "unauthorized" }));
            }
            if (headers.Contains("token"))
            {
                var token = headers.GetValues("token").First();
                var jwt   = new JwtToken();
                if (!jwt.VerifyToken(token))
                {
                    return(Ok(new { errorCode = "66", message = "unauthorized" }));
                }
            }
            var service = new ArtistService();
            var artist  = service.GetArtist(id);

            if (artist == null)
            {
                return(NotFound());
            }
            return(Ok(artist));
        }
Esempio n. 5
0
        void LoadLayout()
        {
            Image_album.Source         = new BitmapImage(new Uri(albumRoot.album.picUrl));
            TextBlock_albumName.Text   = albumRoot.album.name;
            Button_ar.Content          = ArtistService.GetArNames_ArtistsItem(albumRoot.album.artists);
            TextBlock_comentCount.Text = albumRoot.album.info.commentCount.ToString();
            TextBlock_des.Text         = albumRoot.album.description == null ? "" : albumRoot.album.description;
            TextBlock_songsCount.Text  = albumRoot.songs.Count.ToString();

            //判断是否为喜欢歌曲
            if (MainPage.favoriteSongsRoot != null)
            {
                foreach (var temp in albumRoot.songs)
                {
                    if (MainPage.favoriteSongsRoot.ids.Find(p => p.Equals(temp.Id)) != 0)
                    {
                        temp.isFavorite = true;
                    }
                }
            }
            ListBox_musicDetail.ItemsSource = albumRoot.songs;
            //TextBlock_subCount.Text = playListDetailRoot.playlist.subscribedCount.ToString();
            //TextBlock_comentCount.Text = playListDetailRoot.playlist.commentCount.ToString();
            //TextBlock_songsCount.Text = musicDetailRootSource.songs.Count.ToString();
            //ListBox_musicDetail.ItemsSource = musicDetailRootSource.songs;
        }
Esempio n. 6
0
        private ArtistService CreateArtistService()
        {
            var userId        = Guid.Parse(User.Identity.GetUserId());
            var artistService = new ArtistService(userId);

            return(artistService);
        }
Esempio n. 7
0
        public IHttpActionResult Get()
        {
            var headers = Request.Headers;

            if (!headers.Contains("token"))
            {
                return(Ok(new { errorCode = "66", message = "unauthorized" }));
            }
            if (headers.Contains("token"))
            {
                var token = headers.GetValues("token").First();
                var jwt   = new JwtToken();
                if (!jwt.VerifyToken(token))
                {
                    return(Ok(new { errorCode = "66", message = "unauthorized" }));
                }
            }
            var service = new ArtistService();
            var rnd     = new Random();
            var artists = service.GetAllArtists().OrderBy(item => rnd.Next()).ToList();

            if (artists.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(artists));
        }
Esempio n. 8
0
        public void RemoveArtistTest()
        {
            ArtistService service     = new ArtistService(_artistRepository);
            bool          returnValue = service.RemoveArtist(999);

            Assert.IsTrue(returnValue);
        }
Esempio n. 9
0
 public UserController(
     UserService service,
     UserQueries data,
     ArtistService artistService,
     ArtistQueries artistQueries,
     OtherService otherService,
     IRepository repository,
     UserMessageQueries messageQueries,
     IPRuleManager ipRuleManager,
     VdbConfigManager config,
     MarkdownParser markdownParser,
     ActivityEntryQueries activityEntryQueries,
     LoginManager loginManager)
 {
     Service = service;
     Data    = data;
     _activityEntryQueries = activityEntryQueries;
     _artistQueries        = artistQueries;
     _artistService        = artistService;
     _repository           = repository;
     _otherService         = otherService;
     _messageQueries       = messageQueries;
     _ipRuleManager        = ipRuleManager;
     _config         = config;
     _markdownParser = markdownParser;
     _loginManager   = loginManager;
 }
Esempio n. 10
0
        public void GetArtistTest()
        {
            var service  = new ArtistService(_dataProvider);
            var response = service.GetSimilarArtists("mogwai");

            Assert.IsNotNull(response);
        }
Esempio n. 11
0
        public void GetArtistProfileTest()
        {
            var service  = new ArtistService(_dataProvider);
            var response = service.GetArtistProfile("AR6XZ861187FB4CECD");

            Assert.IsNotNull(response);
        }
Esempio n. 12
0
        public ActionResult Edit(int id, ArtistEdit model)
        {
            var db = new ShopService();

            ViewBag.ShopID = new SelectList(db.GetShops().ToList(), "ShopID", "ShopName", model.ShopID);
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ArtistID != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }
            var service = new ArtistService();

            if (service.UpdateArtist(model))
            {
                TempData["SaveResult"] = "The Artist was updated.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "This Artist could not be updated.");
            return(View(model));
        }
Esempio n. 13
0
        public async void Delete_Errors()
        {
            var mock          = new ServiceMockFacade <IArtistRepository>();
            var model         = new ApiArtistServerRequestModel();
            var validatorMock = new Mock <IApiArtistServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new ArtistService(mock.LoggerMock.Object,
                                            mock.MediatorMock.Object,
                                            mock.RepositoryMock.Object,
                                            validatorMock.Object,
                                            mock.DALMapperMockFactory.DALArtistMapperMock,
                                            mock.DALMapperMockFactory.DALBankAccountMapperMock,
                                            mock.DALMapperMockFactory.DALEmailMapperMock,
                                            mock.DALMapperMockFactory.DALTransactionMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ArtistDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
Esempio n. 14
0
        public void TestCreateArtistCount()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("createArtistsReturnCount").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new ArtistService(dbContext);

            var artist = new Artist
            {
                Name   = "joni",
                Genre  = "metal",
                UserId = "jshsdjhdajdh"
            };

            for (int i = 1; i < 5; i++)
            {
                service.Create(artist.Name, artist.Genre, artist.UserId);

                dbContext.SaveChanges();
            }

            dbContext.SaveChanges();

            int result = dbContext.Artists.CountAsync().Result;

            Assert.AreEqual(5, result);
        }
Esempio n. 15
0
 public SearchController(OtherService services, ArtistService artistService, AlbumService albumService, SongService songService)
 {
     this.services = services;
     this.artistService = artistService;
     this.albumService = albumService;
     this.songService = songService;
 }
Esempio n. 16
0
        private async Task DoWork()
        {
            DocumentClientFactory clientFactory = new DocumentClientFactory();
            MusicService          musicService  = new MusicService(clientFactory);
            await musicService.InitializeStorage();

            UserService userService = new UserService(clientFactory);

            var user1 = userService.CreateNew();

            user1.Id        = new Guid("0e54b6da-caef-492f-bc95-b0669a8957d5").ToString();
            user1.UserName  = "******";
            user1.FirstName = "Jack";
            user1.LastName  = "Blackie";

            await userService.AddOrUpdate(user1);

            var user2 = userService.CreateNew();

            user2.Id        = new Guid("d13c91fd-f8df-4470-ae30-bb6ab5797438").ToString();
            user2.UserName  = "******";
            user2.FirstName = "Frank";
            user2.LastName  = "Conrad";

            await userService.AddOrUpdate(user2);

            var users = await userService.GetByUsername("*****@*****.**");

            foreach (var user in users)
            {
                Console.Write("\t Read {0}", user);
            }
            Console.ReadKey();

            user1.FirstName = "Jackie";
            await userService.Update(user1);

            users = await userService.GetByUsername("*****@*****.**");

            foreach (var user in users)
            {
                Console.Write("\t Read {0}", user);
            }
            Console.ReadKey();

            await userService.Delete(user2);

            ArtistService artistService = new ArtistService(clientFactory);

            var artist = artistService.CreateNew(user1);

            artist.Id   = "02ab6b39-4d53-45f4-8922-d118d8e27ad2";
            artist.Name = "Muse";

            await artistService.AddOrUpdate(artist);

            artist = await artistService.GetById(artist.Id);

            Console.Write("\t Read {0}", artist);
        }
Esempio n. 17
0
        public IHttpActionResult Get(int id)
        {
            ArtistService artistService = CreateArtistService();
            var           artist        = artistService.GetArtistById(id);

            return(Ok(artist));
        }
        // GET: Artist
        public ActionResult Index()
        {
            var service = new ArtistService();
            var model   = service.GetArtists();

            return(View(model));
        }
Esempio n. 19
0
        public IHttpActionResult Put([FromBody] ArtistModel artistModel)
        {
            var headers = Request.Headers;

            if (!headers.Contains("token"))
            {
                return(Ok(new { errorCode = "66", message = "unauthorized" }));
            }
            if (headers.Contains("token"))
            {
                var token = headers.GetValues("token").First();
                var jwt   = new JwtToken();
                if (!jwt.VerifyTokenAndRole(token, (int)RolesEnum.ARTIST))
                {
                    return(Ok(new { errorCode = "66", message = "unauthorized" }));
                }
            }
            var service = new ArtistService();

            try
            {
                var artist = service.UpdateArtist(artistModel);
                return(Ok(artist));
            }
            catch (NotFoundException ex)
            {
                return(NotFound());
            }
            catch (InvalidModelException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public ActionResult Details(int id)
        {
            var service = new ArtistService();
            var model   = service.GetArtistById(id);

            return(View(model));
        }
Esempio n. 21
0
        public IHttpActionResult GetSearchResults(string artistName)
        {
            var headers = Request.Headers;

            if (!headers.Contains("token"))
            {
                return(Ok(new { errorCode = "66", message = "unauthorized" }));
            }
            if (headers.Contains("token"))
            {
                var token = headers.GetValues("token").First();
                var jwt   = new JwtToken();
                if (!jwt.VerifyToken(token))
                {
                    return(Ok(new { errorCode = "66", message = "unauthorized" }));
                }
            }
            var service = new ArtistService();
            var artists = service.SearchForArtist(artistName);

            if (artists.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(artists));
        }
Esempio n. 22
0
        public IHttpActionResult GetAll()
        {
            ArtistService artistService = CreateArtistService();
            var           artists       = artistService.GetArtists();

            return(Ok(artists));
        }
Esempio n. 23
0
        /// <summary>
        /// This method is called by the Login control after a login attempt.
        /// </summary>
        /// <param name="loginResponse"></param>
        private async void LoginComplete(LoginResponse loginResponse)
        {
            // If the loginResponse object exists
            if (NullHelper.Exists(loginResponse))
            {
                // if the login was successful
                if (loginResponse.Success)
                {
                    // Erase any messages
                    this.Message = "";

                    // Set the artist
                    this.Artist = loginResponse.Artist;

                    // if we do not have a Gallerymanager
                    if (!HasGalleryManager)
                    {
                        // Create a new instance of a 'GalleryManager' object.
                        this.GalleryManager = new GalleryManager(this);
                    }

                    // Set the Artist
                    this.GalleryManager.Artist = this.Artist;

                    // Load the Artists in case this is a new artist
                    this.GalleryManager.Artists = await ArtistService.GetArtistList();

                    // Call Refresh
                    Refresh();
                }
            }
        }
        public async Task UpdateArtistAsyncShouldReturnFalseIfIdIsInvalidOrDbIsEmpty()
        {
            var artist = new Artist
            {
                FullName  = "artist1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            await dbContext.Artists.AddAsync(artist);

            await dbContext.SaveChangesAsync();

            var input = new UpdateArtistInputModel
            {
                Id        = "invalid",
                FullName  = "artist2",
                Biography = "biography2",
                BirthDate = DateTime.Parse("24 July 2019"),
                PhotoLink = "photo2",
            };

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = await artistService.UpdateArtistAsync(input);

            Assert.False(actualResult);
        }
        public async Task UpdateArtistAsyncShouldSwitchPhotoLinkToDefaultImgaeIfPreviousIsRemoved(string photoLink)
        {
            var artist = new Artist
            {
                FullName  = "artist1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            await dbContext.Artists.AddAsync(artist);

            await dbContext.SaveChangesAsync();

            var input = new UpdateArtistInputModel
            {
                Id        = dbContext.Artists.First().Id,
                FullName  = "artist2",
                Biography = "biography2",
                BirthDate = DateTime.Parse("24 July 2019"),
                PhotoLink = photoLink,
            };

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = await artistService.UpdateArtistAsync(input);

            Assert.True(actualResult);
            Assert.True(dbContext.Artists.Count() == 1);
            Assert.True(dbContext.Artists.First().FullName == "artist2");
            Assert.True(dbContext.Artists.First().Biography == "biography2");
            Assert.True(dbContext.Artists.First().BirthDate == DateTime.Parse("24 July 2019"));
            Assert.True(dbContext.Artists.First().PhotoLink == GlobalConstants.noArtistImage);
        }
        public async Task CreateArtistAsyncShouldReturnFalseIfArtistWithSameNameBiographyAndBDateAlreadyExists()
        {
            var input = new CreateArtistInputModel
            {
                FullName  = "artist1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };

            await dbContext.Artists.AddAsync(new Artist
            {
                FullName  = "artist1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            });

            await dbContext.SaveChangesAsync();

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = await artistService.CreateArtistAsync(input);

            Assert.False(actualResult);
            Assert.True(dbContext.Artists.Count() == 1);
        }
        public async Task UpdateArtistAsyncShouldUpdateArtistProperlyIfValidDataIsEntered()
        {
            var artist = new Artist
            {
                FullName  = "artist1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            await dbContext.Artists.AddAsync(artist);

            await dbContext.SaveChangesAsync();

            var input = new UpdateArtistInputModel
            {
                Id        = dbContext.Artists.First().Id,
                FullName  = "artist2",
                Biography = "biography2",
                BirthDate = DateTime.Parse("24 July 2019"),
                PhotoLink = "photo2",
            };

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = await artistService.UpdateArtistAsync(input);

            Assert.True(actualResult);
            Assert.True(dbContext.Artists.Count() == 1);
            Assert.True(dbContext.Artists.First().FullName == "artist2");
            Assert.True(dbContext.Artists.First().Biography == "biography2");
            Assert.True(dbContext.Artists.First().BirthDate == DateTime.Parse("24 July 2019"));
            Assert.True(dbContext.Artists.First().PhotoLink == "photo2");
        }
        public void OrderArtistsShouldReturnInputIfOrderByIsInvalid()
        {
            var input = new List <ArtistAllViewModel>()
            {
                new ArtistAllViewModel
                {
                    FullName       = "name1",
                    Biography      = "biography1",
                    BirthDate      = DateTime.Parse("25 July 2018"),
                    PhotoLink      = "photo1",
                    CareerProjects = 1,
                },
                new ArtistAllViewModel
                {
                    FullName       = "name1",
                    Biography      = "biography1",
                    BirthDate      = DateTime.Parse("25 July 2019"),
                    PhotoLink      = "photo1",
                    CareerProjects = 2,
                },
            };

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = artistService.OrderArtists(input, "something invalid");

            Assert.Equal(input.First(), actualResult.First());
            Assert.Equal(input.Last(), actualResult.Last());
        }
        public void OrderArtistsShouldReturnArtistsOrderedByMostPopular()
        {
            var input = new List <ArtistAllViewModel>()
            {
                new ArtistAllViewModel
                {
                    FullName       = "name1",
                    Biography      = "biography1",
                    BirthDate      = DateTime.Parse("25 July 2018"),
                    PhotoLink      = "photo1",
                    CareerProjects = 1,
                },
                new ArtistAllViewModel
                {
                    FullName       = "name1",
                    Biography      = "biography1",
                    BirthDate      = DateTime.Parse("25 July 2019"),
                    PhotoLink      = "photo1",
                    CareerProjects = 2,
                },
            };

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = artistService.OrderArtists(input, GlobalConstants.artistsOrderByMostPopular);

            Assert.Equal(input.First(), actualResult.Last());
            Assert.Equal(input.Last(), actualResult.First());
        }
Esempio n. 30
0
        public void ReturnCorrectSongObjects()
        {
            // Arrange
            const string artistName = "Name";

            var repository = new Mock <IEfContextWrapper <Artist> >();
            var context    = new Mock <ISaveContext>();

            var sut = new ArtistService(repository.Object, context.Object);

            var artistCollection = new List <Artist>()
            {
                new Artist()
                {
                    Name = artistName
                }
            };

            repository.Setup(x => x.All).Returns(() => artistCollection.AsQueryable());

            // Act
            var result = sut.GetArtists().ToList();

            // Assert
            Assert.AreEqual(artistCollection[0].Name, result[0].Name);
        }
Esempio n. 31
0
        public void Should_Delete_Music()
        {
            //ARRANGE
            var albums = AlbumStub.Albums;
            var artist = ArtistStub.Artist;
            var music  = MusicStub.Music;

            using (var context = _sqlLifeFake.GetDbContext())
            {
                AlbumService  albumService  = new AlbumService(context);
                ArtistService artistService = new ArtistService(context);
                MusicService  musicService  = new MusicService(context);

                //ACT
                var insertArtist = artistService.InsertArtistAsync(artist);
                albums[0].ArtistId = insertArtist.Result.Id;

                var albumInsert = albumService.InsertAlbumAsync(albums[0]);
                music.AlbumId = albumInsert.Result.Id;

                music.MusicArtists = new List <MusicArtist>();
                MusicArtist musicArtist = new MusicArtist
                {
                    ArtistId = insertArtist.Result.Id
                };

                music.MusicArtists.Add(musicArtist);

                var deleteMusic = musicService.InsertMusicAsync(music);
                var result      = musicService.DeleteMusicAsync(deleteMusic.Result.Id);

                //ASSERT
                result.Result.Should().BeFalse();
            }
        }
Esempio n. 32
0
 public ArtistApiController(ArtistQueries queries, ArtistService service, IEntryThumbPersister thumbPersister)
 {
     this.queries = queries;
     this.service = service;
     this.thumbPersister = thumbPersister;
 }
Esempio n. 33
0
 public ArtistController(ArtistService service, ArtistQueries queries)
 {
     this.service = service;
     this.queries = queries;
 }