コード例 #1
0
        public void TaskSuccessTest()
        {
            var addArtistTask   = new AddArtist(DbContext, new FormattingService());
            var testArtist      = TestsModel.Artist;
            var addArtistResult = addArtistTask.DoTask(testArtist);

            Assert.IsTrue(addArtistResult.Success);
            Assert.IsNull(addArtistResult.Exception);
            Assert.IsNotNull(addArtistResult.Data);

            var artistId = addArtistResult.Data;

            Assert.IsNotNull(artistId);
            Assert.IsTrue(artistId > 0);

            var paymentService = new ListServices(DbContext).DoTask(null).Data.SingleOrDefault(s => s.Name.ToLower() == "payment");

            Assert.IsNotNull(paymentService);

            var allPlatforms  = new ListPlatforms(DbContext).DoTask(null).Data.ToList();
            var linkPlatforms = new List <Platform>();

            foreach (var platform in allPlatforms)
            {
                linkPlatforms.AddRange(from service in platform.Services where service.Id != paymentService.Id select platform);
            }

            var linkPlatform = linkPlatforms[new Random().Next(0, linkPlatforms.Count)];

            var artistLink = new ArtistLink
            {
                Platform = linkPlatform,
                Artist   = testArtist,
                Url      = "http://www." + DateTime.Now.Ticks + ".com"
            };

            var task   = new AddArtistLink(DbContext);
            var result = task.DoTask(artistLink);

            Assert.IsTrue(result.Success);
            Assert.IsNull(result.Exception);
            Assert.IsNotNull(result.Data);

            var getArtistLinkTask   = new GetArtistLink(DbContext);
            var getArtistLinkResult = getArtistLinkTask.DoTask(artistLink.Id);

            Assert.IsTrue(getArtistLinkResult.Success);
            Assert.IsNull(getArtistLinkResult.Exception);
            Assert.IsNotNull(getArtistLinkResult.Data);

            Assert.AreEqual(artistLink.PlatformId, getArtistLinkResult.Data.PlatformId);
            Assert.AreEqual(artistLink.ArtistId, getArtistLinkResult.Data.ArtistId);
            Assert.AreEqual(artistLink.Url, getArtistLinkResult.Data.Url);

            var removeArtistTask   = new RemoveArtist(DbContext);
            var removeArtistResult = removeArtistTask.DoTask(testArtist);

            Assert.IsTrue(removeArtistResult.Success);
            Assert.IsNull(removeArtistResult.Exception);
        }
コード例 #2
0
        public IActionResult UpdateArtistLink(int artistId, int artistLinkId, ArtistLink artistLink)
        {
            try
            {
                if (!ClientKeyIsValid())
                {
                    return(Unauthorized());
                }

                if (!UserIsAuthenticatedAndAuthorized(MethodBase.GetCurrentMethod()))
                {
                    return(Unauthorized());
                }

                if (!UserIsAuthorizedForArtist(artistId))
                {
                    return(Unauthorized());
                }

                var invalidArtistPathResult = InvalidArtistPathResult(artistId);
                if (invalidArtistPathResult != null)
                {
                    return(invalidArtistPathResult);
                }

                var getArtistLinkResult = _getArtistLinkTask.DoTask(artistLinkId);

                if (getArtistLinkResult.HasException)
                {
                    return(Error(getArtistLinkResult.Exception));
                }

                if (getArtistLinkResult.HasNoData)
                {
                    return(NotFound());
                }

                if (getArtistLinkResult.Data.ArtistId != artistId)
                {
                    return(BadRequest());
                }

                artistLink.ArtistId = artistId;
                artistLink.Id       = artistLinkId;
                var taskResults = _updateArtistLinkTask.DoTask(artistLink);

                return(taskResults.Success ?
                       Ok() :
                       Error(taskResults.Exception));
            }
            catch (Exception e)
            {
                return(Error(e));
            }
        }
コード例 #3
0
        public TaskResult <bool> DoTask(ArtistLink artistLink)
        {
            try
            {
                var toRemove = _dbContext.ArtistLinks.SingleOrDefault(al => al.Id == artistLink.Id);
                if (toRemove == null)
                {
                    return(new TaskResult <bool>(false));
                }

                _dbContext.ArtistLinks.Remove(toRemove);
                _dbContext.SaveChanges();

                return(new TaskResult <bool>(true));
            }
            catch (Exception e)
            {
                return(new TaskResult <bool>(new TaskException(e)));
            }
        }
コード例 #4
0
        public TaskResult <int?> DoTask(ArtistLink artistLink)
        {
            try
            {
                var artistId   = artistLink.Artist?.Id ?? artistLink.ArtistId;
                var platformId = artistLink.Platform?.Id ?? artistLink.PlatformId;

                artistLink.Artist     = null;
                artistLink.ArtistId   = artistId;
                artistLink.Platform   = null;
                artistLink.PlatformId = platformId;

                _dbContext.ArtistLinks.Add(artistLink);
                _dbContext.SaveChanges();

                return(new TaskResult <int?>(artistLink.Id));
            }
            catch (Exception e)
            {
                return(new TaskResult <int?>(new TaskException(e)));
            }
        }
コード例 #5
0
        public TaskResult <Nothing> DoTask(ArtistLink update)
        {
            try
            {
                var artistLink = _dbContext.ArtistLinks.SingleOrDefault(al => al.Id == update.Id);

                if (artistLink == null)
                {
                    throw new TaskException(SystemMessage("ARTIST_ACCOUNT_NOT_FOUND"));
                }

                artistLink.PlatformId = update.Platform?.Id ?? update.PlatformId;
                artistLink.Platform   = _dbContext.Platforms.Single(p => p.Id == artistLink.PlatformId);
                artistLink.Url        = update.Url;
                _dbContext.SaveChanges();

                return(new TaskResult <Nothing>(true));
            }
            catch (Exception e)
            {
                return(new TaskResult <Nothing>(new TaskException(e)));
            }
        }
コード例 #6
0
        public IActionResult AddArtistLink(int artistId, ArtistLink artistLink)
        {
            try
            {
                if (!ClientKeyIsValid())
                {
                    return(Unauthorized());
                }

                if (!UserIsAuthenticatedAndAuthorized(MethodBase.GetCurrentMethod()))
                {
                    return(Unauthorized());
                }

                if (!UserIsAuthorizedForArtist(artistId))
                {
                    return(Unauthorized());
                }

                var invalidArtistPathResult = InvalidArtistPathResult(artistId);
                if (invalidArtistPathResult != null)
                {
                    return(invalidArtistPathResult);
                }

                artistLink.ArtistId = artistId;
                var taskResults = _addArtistLinkTask.DoTask(artistLink);

                return(taskResults.Success ?
                       Json(taskResults) :
                       Error(taskResults.Exception));
            }
            catch (Exception e)
            {
                return(Error(e));
            }
        }